diff --git a/src/main/java/org/sophy/sophy/controller/BooktalkController.java b/src/main/java/org/sophy/sophy/controller/BooktalkController.java index 494e84f..aa24db4 100644 --- a/src/main/java/org/sophy/sophy/controller/BooktalkController.java +++ b/src/main/java/org/sophy/sophy/controller/BooktalkController.java @@ -5,10 +5,7 @@ import org.sophy.sophy.controller.dto.BooktalkUpdateDto; import org.sophy.sophy.controller.dto.request.BooktalkRequestDto; import org.sophy.sophy.controller.dto.request.CityRequestDto; -import org.sophy.sophy.controller.dto.response.BooktalkCreateResponseDto; -import org.sophy.sophy.controller.dto.response.BooktalkDeleteResponseDto; -import org.sophy.sophy.controller.dto.response.BooktalkDetailResponseDto; -import org.sophy.sophy.controller.dto.response.BooktalkResponseDto; +import org.sophy.sophy.controller.dto.response.*; import org.sophy.sophy.exception.SuccessStatus; import org.sophy.sophy.service.BooktalkService; import org.springframework.http.HttpStatus; @@ -42,12 +39,20 @@ public ApiResponseDto deleteBooktalk(@PathVariable("b } @GetMapping("/{booktalkId}/detail") + @ResponseStatus(HttpStatus.OK) public ApiResponseDto getBooktalkDetail(@PathVariable("booktalkId") Long booktalkId) { return ApiResponseDto.success(SuccessStatus.GET_BOOKTALK_DETAIL_SUCCESS, booktalkService.getBooktalkDetail(booktalkId)); } @GetMapping("/search") + @ResponseStatus(HttpStatus.OK) public ApiResponseDto> getPlacesByCity(@Valid @RequestBody CityRequestDto cityRequestDto) { return ApiResponseDto.success(SuccessStatus.GET_BOOKTALKS_BY_CITY_SUCCESS, booktalkService.getBooktalksByCity(cityRequestDto)); } + + @GetMapping("/deadline-upcoming") + @ResponseStatus(HttpStatus.OK) + public ApiResponseDto> getBooktalkDeadlineUpcoming() { + return ApiResponseDto.success(SuccessStatus.GET_BOOKTALKS_DEADLINE_UPCOMING_SUCCESS, booktalkService.getBooktalkDeadlineUpcoming()); + } } diff --git a/src/main/java/org/sophy/sophy/controller/dto/response/BooktalkDeadlineUpcomingDto.java b/src/main/java/org/sophy/sophy/controller/dto/response/BooktalkDeadlineUpcomingDto.java new file mode 100644 index 0000000..92ae512 --- /dev/null +++ b/src/main/java/org/sophy/sophy/controller/dto/response/BooktalkDeadlineUpcomingDto.java @@ -0,0 +1,30 @@ +package org.sophy.sophy.controller.dto.response; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.sophy.sophy.domain.Booktalk; + +import java.time.LocalDateTime; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class BooktalkDeadlineUpcomingDto { + private Long booktalkId; + private String title; + private LocalDateTime startDate; + private LocalDateTime endDate; + private String PlaceName; + private String PlaceAddress; + + public static BooktalkDeadlineUpcomingDto of(Booktalk booktalk) { + return new BooktalkDeadlineUpcomingDto( + booktalk.getId(), + booktalk.getTitle(), + booktalk.getStartDate(), + booktalk.getEndDate(), + booktalk.getPlace().getName(), + booktalk.getPlace().getAddress() + ); + } +} diff --git a/src/main/java/org/sophy/sophy/exception/SuccessStatus.java b/src/main/java/org/sophy/sophy/exception/SuccessStatus.java index dc7f047..748507a 100644 --- a/src/main/java/org/sophy/sophy/exception/SuccessStatus.java +++ b/src/main/java/org/sophy/sophy/exception/SuccessStatus.java @@ -23,6 +23,7 @@ public enum SuccessStatus { DELETE_BOOKTALK_SUCCESS(HttpStatus.OK, "북토크를 성공적으로 삭제했습니다."), GET_BOOKTALK_DETAIL_SUCCESS(HttpStatus.OK, "북토크 상세정보를 성공적으로 불러왔습니다."), GET_BOOKTALKS_BY_CITY_SUCCESS(HttpStatus.OK, "지역으로 북토크 리스트를 성공적으로 불러왔습니다"), + GET_BOOKTALKS_DEADLINE_UPCOMING_SUCCESS(HttpStatus.OK, "마감임박 소피 북토크 리스트를 성공적으로 불러왔습니다."), GET_MY_BOOKTALKS_SUCCESS(HttpStatus.OK, "예정된 북토크 리스트를 성공적으로 불러왔습니다"), GET_AUTHOR_BOOKTALKS_SUCCESS(HttpStatus.OK, "작가 북토크 리스트를 성공적으로 불러왔습니다"), TEST_SUCCESS(HttpStatus.OK, "Test :: OK"), diff --git a/src/main/java/org/sophy/sophy/service/BooktalkService.java b/src/main/java/org/sophy/sophy/service/BooktalkService.java index cfda16e..30fd4d9 100644 --- a/src/main/java/org/sophy/sophy/service/BooktalkService.java +++ b/src/main/java/org/sophy/sophy/service/BooktalkService.java @@ -4,10 +4,7 @@ import org.sophy.sophy.controller.dto.BooktalkUpdateDto; import org.sophy.sophy.controller.dto.request.BooktalkRequestDto; import org.sophy.sophy.controller.dto.request.CityRequestDto; -import org.sophy.sophy.controller.dto.response.BooktalkCreateResponseDto; -import org.sophy.sophy.controller.dto.response.BooktalkDeleteResponseDto; -import org.sophy.sophy.controller.dto.response.BooktalkDetailResponseDto; -import org.sophy.sophy.controller.dto.response.BooktalkResponseDto; +import org.sophy.sophy.controller.dto.response.*; import org.sophy.sophy.domain.*; import org.sophy.sophy.exception.ErrorStatus; import org.sophy.sophy.exception.model.ForbiddenException; @@ -63,6 +60,26 @@ public BooktalkDetailResponseDto getBooktalkDetail(Long booktalkId) { return BooktalkDetailResponseDto.of(booktalk); } + public List getBooktalkDeadlineUpcoming() { + List placeList = placeRepository.findAll(); + + List booktalkList = new ArrayList<>(); + placeList.forEach(place -> { + place.getBooktalkList().forEach(booktalk -> { + // 모집중인 북토크만 추가 + if (booktalk.getBooktalkStatus() == BooktalkStatus.RECRUITING) { + booktalkList.add(BooktalkDeadlineUpcomingDto.of(booktalk)); + } + } + ); + }); + + // 마감 임박순으로 정렬 + booktalkList.sort(Comparator.comparing(BooktalkDeadlineUpcomingDto::getEndDate)); + + return booktalkList; + } + private Member getMemberById(Long memberId) { return memberRepository.findById(memberId) .orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION, ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));