Skip to content

Commit

Permalink
Merge pull request #70 from Gongjakso/feat/apply
Browse files Browse the repository at this point in the history
fix : endDate->finishDate로 수정 및 오타 수정
  • Loading branch information
sycuuui authored Feb 17, 2024
2 parents d67ef39 + f2dfb6f commit ad57e91
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
public record ApplyRes(
String title,
LocalDateTime startDate,
LocalDateTime endDate,
LocalDateTime finishDate,
Long max_person,
int current_person,
Boolean postType
) {
public static ApplyRes of(Post post, int current_person){
return new ApplyRes(post.getTitle(),post.getStartDate(),post.getEndDate(),post.getMaxPerson(),current_person,post.isPostType());
return new ApplyRes(post.getTitle(),post.getStartDate(),post.getFinishDate(),post.getMaxPerson(),current_person,post.isPostType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public record ParticipationList(
CategoryType recruit_part,
String leaderName,
LocalDateTime startDate,
LocalDateTime endDate,
LocalDateTime finishDate,
PostStatus postStatus,
Boolean postType
) {
public static ParticipationList of(Post post,CategoryType recruit_part) {
return new ParticipationList(post.getTitle(), recruit_part,post.getMember().getName(),post.getStartDate(),post.getEndDate(),post.getStatus(), post.isPostType());
return new ParticipationList(post.getTitle(), recruit_part,post.getMember().getName(),post.getStartDate(),post.getFinishDate(),post.getStatus(), post.isPostType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import java.time.LocalDateTime;

public record PeriodReq(
LocalDateTime endDate
LocalDateTime finishDate
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void save(Member member, Long post_id, ApplyReq req){
//재지원 판단
if(!applyRepository.existsApplyByMemberAndPost(member, post)){
//지원 기간인지 판단
if(post.getEndDate().isBefore(LocalDateTime.now())){
if(post.getFinishDate().isBefore(LocalDateTime.now())){
throw new ApplicationException(ErrorCode.NOT_APPLY_EXCEPTION);
}else {
Apply apply = req.toEntity(member, post);
Expand Down Expand Up @@ -174,7 +174,7 @@ public void updatePostPeriod(Long post_id, PeriodReq req) {
}else {
//공고 상태가 모집 중인지 판단
if(post.getStatus()==RECRUITING){
post.setEndDate(req.endDate());
post.setFinishDate(req.finishDate());
}else {
throw new ApplicationException(ErrorCode.NOT_RECRUITING_EXCEPION);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
package com.gongjakso.server.domain.post.controller;

import com.gongjakso.server.domain.apply.dto.ApplyReq;
import com.gongjakso.server.domain.post.dto.CalenderRes;
import com.gongjakso.server.domain.post.dto.ScrapPost;
import com.gongjakso.server.domain.post.repository.PostScrapRepository;
import com.gongjakso.server.domain.post.service.CalenderService;
import com.gongjakso.server.domain.post.dto.CalendarRes;
import com.gongjakso.server.domain.post.service.CalendarService;
import com.gongjakso.server.global.common.ApplicationResponse;
import com.gongjakso.server.global.security.PrincipalDetails;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/calender")
@RequestMapping("/api/v1/calendar")
@RequiredArgsConstructor
@Tag(name = "Calender", description = "캘린더 관련 API")
public class CalenderController {
private final CalenderService calenderService;
@Tag(name = "Calendar", description = "캘린더 관련 API")
public class CalendarController {
private final CalendarService calendarService;
@Operation(summary = "캘린더 정보 API", description = "자신이 스크랩한 공고 정보 요청")
@GetMapping("")
public ApplicationResponse<CalenderRes> addApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestParam(name = "year", defaultValue = "2024") int year, @RequestParam(name = "month", defaultValue = "11") int month){
return ApplicationResponse.ok(calenderService.findScrapPost(principalDetails.getMember(),year,month));
public ApplicationResponse<CalendarRes> addApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestParam(name = "year", defaultValue = "2024") int year, @RequestParam(name = "month", defaultValue = "11") int month){
return ApplicationResponse.ok(calendarService.findScrapPost(principalDetails.getMember(),year,month));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.gongjakso.server.domain.post.dto;

import java.util.List;

public record CalendarRes(
List<ScrapPost> scrapPosts
) {
public static CalendarRes of(List<ScrapPost> scrapPosts){
return new CalendarRes(scrapPosts);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.gongjakso.server.domain.post.service;

import com.gongjakso.server.domain.apply.dto.ApplyList;
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.dto.CalenderRes;
import com.gongjakso.server.domain.post.dto.CalendarRes;
import com.gongjakso.server.domain.post.dto.ScrapPost;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.entity.PostScrap;
Expand All @@ -15,23 +14,22 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
@RequiredArgsConstructor
public class CalenderService {
public class CalendarService {
private final PostScrapRepository postScrapRepository;
private final PostRepository postRepository;
public CalenderRes findScrapPost(Member member,int year,int month){
public CalendarRes findScrapPost(Member member, int year, int month){
List<PostScrap> postScraps = postScrapRepository.findByMemberAndScrapStatus(member,true);
List<Long> postIdList = postScraps.stream().map(postScrap -> postScrap.getPost().getPostId()).toList();
List<Post> posts = postRepository.findAllByEndDateBetweenAndPostIdIn(getFirstDayOfMonth(year,month),getLastDayOfMonth(year,month), postIdList);
List<ScrapPost> scrapPosts = posts.stream().map(ScrapPost::of)
.collect(Collectors.toList());
return CalenderRes.of(scrapPosts);
return CalendarRes.of(scrapPosts);
}
public static LocalDateTime getFirstDayOfMonth(int year, int month) {
LocalDate firstDayOfMonth = LocalDate.of(year, month, 1);
Expand Down

0 comments on commit ad57e91

Please sign in to comment.