Skip to content

Commit

Permalink
Merge pull request #83 from Cafegory/feature-82
Browse files Browse the repository at this point in the history
[BUILD SUCCESS] 카공에 오픈채팅방url 추가 및 카공 모집글 생성, 카공 모집글 수정에 오픈채팅방 url 넣을 수 있도록 변경, 카공모집글 조회에 참여한 상태 추가
  • Loading branch information
donghyun0304 authored Apr 25, 2024
2 parents fb89e03 + 8d7a722 commit 7e3df36
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 37 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/example/demo/controller/StudyOnceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import java.time.LocalDateTime;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -56,7 +58,14 @@ public class StudyOnceController {
private final StudyOnceCommentQueryService studyOnceCommentQueryService;

@GetMapping("/{studyOnceId:[0-9]+}")
public ResponseEntity<StudyOnceSearchResponse> search(@PathVariable Long studyOnceId) {
public ResponseEntity<StudyOnceSearchResponse> search(@PathVariable Long studyOnceId,
@RequestHeader(value = "Authorization", required = false) String authorization) {
if (StringUtils.hasText(authorization)) {
long memberId = cafegoryTokenManager.getIdentityId(authorization);
StudyOnceSearchResponse response = studyOnceService.searchStudyOnceWithMemberParticipation(studyOnceId,
memberId);
return new ResponseEntity<>(response, HttpStatus.OK);
}
StudyOnceSearchResponse response = studyOnceService.searchByStudyId(studyOnceId);
return ResponseEntity.ok(response);
}
Expand All @@ -69,7 +78,8 @@ public ResponseEntity<PagedResponse<StudyOnceSearchListResponse>> searchList(
}

@PostMapping("")
public ResponseEntity<StudyOnceCreateResponse> create(@RequestBody StudyOnceCreateRequest studyOnceCreateRequest,
public ResponseEntity<StudyOnceCreateResponse> create(
@RequestBody @Validated StudyOnceCreateRequest studyOnceCreateRequest,
@RequestHeader("Authorization") String authorization) {
long memberId = cafegoryTokenManager.getIdentityId(authorization);
StudyOnceCreateResponse response = studyOnceService.createStudy(memberId, studyOnceCreateRequest);
Expand All @@ -78,7 +88,7 @@ public ResponseEntity<StudyOnceCreateResponse> create(@RequestBody StudyOnceCrea

@PatchMapping("/{studyOnceId:[0-9]+}")
public ResponseEntity<StudyOnceInfoResponse> update(@PathVariable Long studyOnceId,
@RequestBody StudyOnceUpdateRequest request,
@RequestBody @Validated StudyOnceUpdateRequest request,
@RequestHeader("Authorization") String authorization) {
long leaderId = cafegoryTokenManager.getIdentityId(authorization);
if (studyOnceService.doesOnlyStudyLeaderExist(studyOnceId)) {
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/com/example/demo/domain/study/StudyOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class StudyOnce {
private int nowMemberCount;
private boolean isEnd;
private boolean ableToTalk;
private String openChatUrl;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "leader_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Member leader;
Expand All @@ -66,11 +67,12 @@ public class StudyOnce {

@Builder
private StudyOnce(Long id, String name, Cafe cafe, LocalDateTime startDateTime, LocalDateTime endDateTime,
int maxMemberCount, int nowMemberCount, boolean isEnd, boolean ableToTalk, Member leader) {
int maxMemberCount, int nowMemberCount, boolean isEnd, boolean ableToTalk, String openChatUrl, Member leader) {
validateStartDateTime(startDateTime);
validateStudyOnceTime(startDateTime, endDateTime);
validateMaxMemberCount(maxMemberCount);
this.id = id;
validateEmptyOrWhiteSpace(name, STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE);
this.name = name;
this.cafe = cafe;
this.startDateTime = startDateTime;
Expand All @@ -80,6 +82,8 @@ private StudyOnce(Long id, String name, Cafe cafe, LocalDateTime startDateTime,
this.nowMemberCount = nowMemberCount;
this.isEnd = isEnd;
this.ableToTalk = ableToTalk;
validateEmptyOrWhiteSpace(openChatUrl, STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE);
this.openChatUrl = openChatUrl;
this.leader = leader;
validateConflictJoin(leader);
studyMembers = new ArrayList<>();
Expand Down Expand Up @@ -181,9 +185,7 @@ public boolean canJoin(LocalDateTime baseDateTime) {
}

public void changeName(String name) {
if (StringUtils.isEmptyOrWhitespace(name)) {
throw new CafegoryException(STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE);
}
validateEmptyOrWhiteSpace(name, STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE);
this.name = name;
}

Expand All @@ -208,4 +210,19 @@ public boolean doesOnlyLeaderExist() {
return this.studyMembers.size() == 1 && this.studyMembers.get(0).isLeader(this.leader);
}

public void changeOpenChatUrl(String openChatUrl) {
validateEmptyOrWhiteSpace(openChatUrl, STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE);
this.openChatUrl = openChatUrl;
}

private void validateEmptyOrWhiteSpace(String target, ExceptionType exceptionType) {
if (StringUtils.isEmptyOrWhitespace(target)) {
throw new CafegoryException(exceptionType);
}
}

public boolean isAttendance(Member member) {
return studyMembers.stream()
.anyMatch(s -> s.getId().getMemberId().equals(member.getId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.LocalDateTime;

import javax.validation.constraints.NotBlank;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -11,10 +13,13 @@
@NoArgsConstructor
public class StudyOnceCreateRequest {
private long cafeId;
@NotBlank
private String name;
private LocalDateTime startDateTime;
private LocalDateTime endDateTime;
private int maxMemberCount;
private boolean canTalk;
@NotBlank
private String openChatUrl;
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class StudyOnceCreateResponse {
private boolean canTalk;
private boolean canJoin;
private boolean isEnd;
private String openChatUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class StudyOnceInfoResponse {
private boolean canTalk;
private boolean canJoin;
private boolean isEnd;
private String openChatUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public class StudyOnceSearchResponse {
private boolean canTalk;
private boolean canJoin;
private boolean isEnd;
private String openChatUrl;
private boolean isAttendance;
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public class StudyOnceUpdateRequest {
private int maxMemberCount;
@Nullable
private boolean canTalk;
@Nullable
private String openChatUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum ExceptionType {
STUDY_ONCE_PARENT_COMMENT_MODIFICATION_BLOCKED(FORBIDDEN, "답변이 존재하는 질문은 수정 할 수 없습니다."),
STUDY_ONCE_PARENT_COMMENT_REMOVAL_BLOCKED(FORBIDDEN, "답변이 존재하는 질문은 삭제 할 수 없습니다."),
STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE(BAD_REQUEST, "스터디 이름은 null, 빈 값, 혹은 공백만으로 이루어질 수 없습니다."),
STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE(BAD_REQUEST, "스터디의 오픈채팅방 URL은 null, 빈 값, 혹은 공백만으로 이루어질 수 없습니다."),
MEMBER_NOT_FOUND(NOT_FOUND, "없는 회원입니다."),
REVIEW_NOT_FOUND(NOT_FOUND, "없는 리뷰입니다."),
REVIEW_OVER_CONTENT_SIZE(BAD_REQUEST, "리뷰 글자수가 최대 글자수 이하여야 합니다."),
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/example/demo/mapper/StudyOnceMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public StudyOnce toNewEntity(StudyOnceCreateRequest studyOnceCreateRequest, Cafe
.nowMemberCount(0)
.isEnd(false)
.ableToTalk(studyOnceCreateRequest.isCanTalk())
.openChatUrl(studyOnceCreateRequest.getOpenChatUrl())
.cafe(cafe)
.leader(leader)
.build();
Expand All @@ -63,10 +64,11 @@ public StudyOnceInfoResponse toStudyOnceInfoResponse(StudyOnce saved, boolean ca
.canTalk(saved.isAbleToTalk())
.canJoin(canJoin)
.isEnd(saved.isEnd())
.openChatUrl(saved.getOpenChatUrl())
.build();
}

public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolean canJoin) {
public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolean canJoin, boolean isAttendance) {
return StudyOnceSearchResponse.builder()
.cafeId(saved.getCafe().getId())
.creatorId(saved.getLeader().getId())
Expand All @@ -80,6 +82,8 @@ public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolea
.canTalk(saved.isAbleToTalk())
.canJoin(canJoin)
.isEnd(saved.isEnd())
.openChatUrl(saved.getOpenChatUrl())
.isAttendance(isAttendance)
.build();
}

Expand Down Expand Up @@ -112,6 +116,7 @@ public StudyOnceCreateResponse toStudyOnceCreateResponse(StudyOnce saved, boolea
.canTalk(saved.isAbleToTalk())
.canJoin(canJoin)
.isEnd(saved.isEnd())
.openChatUrl(saved.getOpenChatUrl())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface StudyOnceService {

StudyOnceSearchResponse searchByStudyId(long studyId);

StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyOnceId, long memberId);

UpdateAttendanceResponse updateAttendances(long leaderId, long studyOnceId,
UpdateAttendanceRequest request, LocalDateTime now);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ public StudyOnceSearchResponse searchByStudyId(long studyId) {
StudyOnce searched = studyOnceRepository.findById(studyId)
.orElseThrow(() -> new CafegoryException(STUDY_ONCE_NOT_FOUND));
boolean canJoin = searched.canJoin(LocalDateTime.now());
return studyOnceMapper.toStudyOnceSearchResponse(searched, canJoin);
return studyOnceMapper.toStudyOnceSearchResponse(searched, canJoin, false);
}

@Override
public StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyOnceId, long memberId) {
StudyOnce searched = studyOnceRepository.findById(studyOnceId)
.orElseThrow(() -> new CafegoryException(STUDY_ONCE_NOT_FOUND));
boolean canJoin = searched.canJoin(LocalDateTime.now());
boolean isAttendance = searched.isAttendance(findMemberById(memberId));
return studyOnceMapper.toStudyOnceSearchResponse(searched, canJoin, isAttendance);
}

@Override
Expand Down Expand Up @@ -208,6 +217,9 @@ public void updateStudyOnce(long requestedMemberId, long studyOnceId, StudyOnceU
if (request.getStartDateTime() != null && request.getEndDateTime() != null) {
studyOnce.changeStudyOnceTime(request.getStartDateTime(), request.getEndDateTime());
}
if (request.getOpenChatUrl() != null) {
studyOnce.changeOpenChatUrl(request.getOpenChatUrl());
}
studyOnce.changeMaxMemberCount(request.getMaxMemberCount());
studyOnce.changeCanTalk(request.isCanTalk());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TestStudyOnceBuilder {
private int nowMemberCount = 0;
private boolean isEnd = false;
private boolean ableToTalk = true;
private String openChatUrl = "오픈채팅방 링크";
private Member leader;

public TestStudyOnceBuilder id(Long id) {
Expand Down Expand Up @@ -69,6 +70,11 @@ public TestStudyOnceBuilder leader(Member leader) {
return this;
}

public TestStudyOnceBuilder openChatUrl(String openChatUrl) {
this.openChatUrl = openChatUrl;
return this;
}

public StudyOnce build() {
StudyOnce studyOnce = StudyOnce.builder()
.id(id)
Expand All @@ -81,6 +87,7 @@ public StudyOnce build() {
.isEnd(isEnd)
.ableToTalk(ableToTalk)
.leader(leader)
.openChatUrl(openChatUrl)
.build();
return studyOnce;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static Stream<Arguments> isConflictParameters() {
void isConflict(TimeInterval timeInterval, boolean expected) {
LocalDateTime start = BASE_TIME.plusHours(4);
LocalDateTime end = BASE_TIME.plusHours(7);
StudyOnce studyOnce = makeStudyOnce(start, end);
StudyOnce studyOnce = makeStudyOnce("스터디 이름", start, end, "오픈채팅방 링크");
StudyMember studyMember = makeStudyMember(studyOnce);

boolean actual = studyMember.isConflictWith(timeInterval.start, timeInterval.end);
Expand All @@ -54,11 +54,13 @@ void isConflict(TimeInterval timeInterval, boolean expected) {
.isEqualTo(expected);
}

private StudyOnce makeStudyOnce(LocalDateTime start, LocalDateTime end) {
private StudyOnce makeStudyOnce(String name, LocalDateTime start, LocalDateTime end, String openChatUrl) {
return StudyOnce.builder()
.name(name)
.startDateTime(start)
.endDateTime(end)
.leader(new TestMemberBuilder().build())
.openChatUrl(openChatUrl)
.build();
}

Expand Down
Loading

0 comments on commit 7e3df36

Please sign in to comment.