Skip to content

Commit

Permalink
Merge pull request #100 from SOPT-SOPHY/feat/#96-add-isapply
Browse files Browse the repository at this point in the history
Feat/#96 add isapply
  • Loading branch information
onpyeong committed Oct 13, 2023
2 parents c710302 + 3df7dd5 commit 713952b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public class BooktalkController {
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "북토크 상세 조회")
public ApiResponseDto<BooktalkDetailResponseDto> getBooktalkDetail(
@Parameter(hidden = true) @AuthenticationPrincipal User user,
@Parameter(example = "1") @PathVariable("booktalkId") Long booktalkId) {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALK_DETAIL_SUCCESS,
booktalkService.getBooktalkDetail(booktalkId));
booktalkService.getBooktalkDetail(user.getUsername(), booktalkId));
}

@GetMapping("/search")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Getter;
import org.sophy.sophy.domain.Booktalk;
import org.sophy.sophy.domain.enumerate.BookCategory;
import org.sophy.sophy.domain.enumerate.BooktalkStatus;
import org.sophy.sophy.domain.enumerate.PreliminaryInfo;

@Getter
Expand All @@ -16,7 +17,7 @@ public class BooktalkDetailResponseDto {
private String title;
private String Author;
private BookCategory bookCategory;
private String book; //TODO 추후 연결
private String book;
private LocalDateTime startDate;
private LocalDateTime endDate;
private Integer participant;
Expand All @@ -25,8 +26,10 @@ public class BooktalkDetailResponseDto {
private String description;
private String PlaceName;
private String PlaceAddress;
private Boolean isApply;
private BooktalkStatus booktalkStatus;

public static BooktalkDetailResponseDto of(Booktalk booktalk) {
public static BooktalkDetailResponseDto of(Booktalk booktalk, Boolean isApply) {
return new BooktalkDetailResponseDto(
booktalk.getBooktalkImageUrl(),
booktalk.getTitle(),
Expand All @@ -40,7 +43,9 @@ public static BooktalkDetailResponseDto of(Booktalk booktalk) {
booktalk.getPreliminaryInfo(),
booktalk.getDescription(),
booktalk.getPlace().getName(),
booktalk.getPlace().getAddress()
booktalk.getPlace().getAddress(),
isApply,
booktalk.getBooktalkStatus()
);
}
}
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/exception/ErrorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public enum ErrorStatus {
*/

FORBIDDEN_USER_EXCEPTION(HttpStatus.FORBIDDEN, "접근 권한이 없습니다."),
BOOKTALK_RECRUITING_CLOSED_EXCEPTION(HttpStatus.FORBIDDEN, "모집 마감된 북토크입니다."),
/**
* 404 NOT FOUND
*/
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ public BooktalkDeleteResponseDto deleteBooktalk(
}

// 북토크 상세 조회
public BooktalkDetailResponseDto getBooktalkDetail(Long booktalkId) {
public BooktalkDetailResponseDto getBooktalkDetail(String email, Long booktalkId) {
Member member = memberRepository.getMemberByEmail(email);
Booktalk booktalk = booktalkRepository.getBooktalkById(booktalkId);
return BooktalkDetailResponseDto.of(booktalk);
Boolean isApply = member.getUserBookTalkList()
.stream().anyMatch(memberBooktalk -> memberBooktalk.getBooktalk().equals(booktalk));
return BooktalkDetailResponseDto.of(booktalk, isApply);
}

// 북토크 참여 신청
Expand All @@ -101,6 +104,10 @@ public void postBooktalkParticipation(
Member member = memberRepository.getMemberByEmail(email); //참가 신청 유저
Booktalk booktalk = booktalkRepository.getBooktalkById(
booktalkParticipationRequestDto.getBooktalkId()); //참가하고자 하는 북토크
if (!booktalk.getBooktalkStatus().equals(BooktalkStatus.RECRUITING)) {
throw new ForbiddenException(ErrorStatus.BOOKTALK_RECRUITING_CLOSED_EXCEPTION,
ErrorStatus.BOOKTALK_RECRUITING_CLOSED_EXCEPTION.getMessage());
}
//북토크 현재 인원이 최대인원을 넘지 않았는지 체크하는 메서드
if (booktalk.getMaximum() <= booktalk.getParticipantNum()) {
throw new OverMaxParticipationException(ErrorStatus.OVER_MAX_PARTICIPATION_EXCEPTION,
Expand All @@ -116,6 +123,9 @@ public void postBooktalkParticipation(
// 복합키?
memberBooktalkRepository.save(
booktalkParticipationRequestDto.toMemberBooktalk(booktalk, member));
if (booktalk.getMaximum().equals(booktalk.getParticipantNum())) { //인원이 다 찬 경우 마감
booktalk.setBooktalkStatus(BooktalkStatus.RECRUITING_CLOSED);
}
}

// 마감임박 북토크 조회
Expand Down

0 comments on commit 713952b

Please sign in to comment.