Skip to content

Commit

Permalink
�feat: GET 마감임박 소피 모아보기 조회 (#46)
Browse files Browse the repository at this point in the history
* add: BooktalkCreateRequestDto, ResponseDto 추가

* feat: POST 북토크 생성 구현

* add: BooktalkUpdateDto 추가

* modify: Booktalk에 patchBooktalk추가

* feat: PATCH 북토크 수정하기 구현

* fix: 북토크 생성 시 member와 place 연결

* add: BooktalkDeleteResponseDto 추가

* modify: Author와 Booktalk에 deleteBooktalk 추가

* feat: DELETE 북토크 삭제 구현

* feat: GET 북토크 상세조회 구현

* feat: GET 마감임박 북토크 모아보기 조회 구현
  • Loading branch information
onpyeong committed Jul 13, 2023
1 parent 7e7376b commit 6c332f7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/main/java/org/sophy/sophy/controller/BooktalkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,12 +39,20 @@ public ApiResponseDto<BooktalkDeleteResponseDto> deleteBooktalk(@PathVariable("b
}

@GetMapping("/{booktalkId}/detail")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<BooktalkDetailResponseDto> getBooktalkDetail(@PathVariable("booktalkId") Long booktalkId) {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALK_DETAIL_SUCCESS, booktalkService.getBooktalkDetail(booktalkId));
}

@GetMapping("/search")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<List<BooktalkResponseDto>> 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<List<BooktalkDeadlineUpcomingDto>> getBooktalkDeadlineUpcoming() {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALKS_DEADLINE_UPCOMING_SUCCESS, booktalkService.getBooktalkDeadlineUpcoming());
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/exception/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +60,26 @@ public BooktalkDetailResponseDto getBooktalkDetail(Long booktalkId) {
return BooktalkDetailResponseDto.of(booktalk);
}

public List<BooktalkDeadlineUpcomingDto> getBooktalkDeadlineUpcoming() {
List<Place> placeList = placeRepository.findAll();

List<BooktalkDeadlineUpcomingDto> 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()));
Expand Down

0 comments on commit 6c332f7

Please sign in to comment.