Skip to content

Commit

Permalink
Merge pull request #57 from Cafegory/feature-55
Browse files Browse the repository at this point in the history
[BUILD SUCCESS] [BUILD SUCCESS] [BUILD FAIL] Feature 55 카공 장소 변경api, 카공 참여자 정보 조회 api
  • Loading branch information
donghyun0304 authored Mar 24, 2024
2 parents f2466f6 + 48f8337 commit f69ad4e
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/example/demo/config/MapperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.example.demo.mapper.CafeMapper;
import com.example.demo.mapper.ReviewMapper;
import com.example.demo.mapper.SnsDetailMapper;
import com.example.demo.mapper.StudyMemberMapper;
import com.example.demo.mapper.StudyOnceMapper;

@Configuration
Expand Down Expand Up @@ -36,4 +37,9 @@ public SnsDetailMapper snsDetailMapper() {
public StudyOnceMapper studyOnceMapper() {
return new StudyOnceMapper();
}

@Bean
public StudyMemberMapper studyMemberMapper() {
return new StudyMemberMapper();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public ResponseEntity<PagedResponse<ReviewSearchResponse>> reviewList(ReviewSear
public ResponseEntity<ReviewResponse> saveReview(@PathVariable Long cafeId,
@RequestHeader("Authorization") String authorization,
@RequestBody @Validated ReviewSaveRequest reviewSaveRequest) {

long memberId = cafegoryTokenManager.getIdentityId(authorization);
Long savedReviewId = reviewService.saveReview(memberId, cafeId, reviewSaveRequest);
ReviewResponse response = reviewQueryService.searchOne(savedReviewId);
Expand All @@ -54,7 +53,6 @@ public ResponseEntity<ReviewResponse> saveReview(@PathVariable Long cafeId,
public ResponseEntity<ReviewResponse> updateReview(@PathVariable Long reviewId,
@RequestHeader("Authorization") String authorization,
@RequestBody @Validated ReviewUpdateRequest reviewUpdateRequest) {

long memberId = cafegoryTokenManager.getIdentityId(authorization);
reviewService.updateReview(memberId, reviewId, reviewUpdateRequest);
ReviewResponse response = reviewQueryService.searchOne(reviewId);
Expand All @@ -64,7 +62,6 @@ public ResponseEntity<ReviewResponse> updateReview(@PathVariable Long reviewId,
@DeleteMapping("/cafe/review/{reviewId}")
public ResponseEntity<ReviewResponse> deleteReview(@PathVariable Long reviewId,
@RequestHeader("Authorization") String authorization) {

long memberId = cafegoryTokenManager.getIdentityId(authorization);
ReviewResponse response = reviewQueryService.searchOne(reviewId);
reviewService.deleteReview(memberId, reviewId);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/example/demo/controller/StudyOnceController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.demo.controller;

import static com.example.demo.exception.ExceptionType.*;

import java.time.LocalDateTime;

import org.springframework.http.ResponseEntity;
Expand All @@ -15,13 +17,18 @@
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.domain.auth.CafegoryTokenManager;
import com.example.demo.dto.CafeSearchResponse;
import com.example.demo.dto.PagedResponse;
import com.example.demo.dto.StudyMembersResponse;
import com.example.demo.dto.StudyOnceCreateRequest;
import com.example.demo.dto.StudyOnceJoinResult;
import com.example.demo.dto.StudyOnceSearchRequest;
import com.example.demo.dto.StudyOnceSearchResponse;
import com.example.demo.dto.UpdateAttendanceRequest;
import com.example.demo.dto.UpdateAttendanceResponse;
import com.example.demo.exception.CafegoryException;
import com.example.demo.repository.StudyOnceRepository;
import com.example.demo.service.CafeQueryService;
import com.example.demo.service.StudyOnceService;

import lombok.RequiredArgsConstructor;
Expand All @@ -32,6 +39,8 @@
public class StudyOnceController {
private final StudyOnceService studyOnceService;
private final CafegoryTokenManager cafegoryTokenManager;
private final CafeQueryService cafeQueryService;
private final StudyOnceRepository studyOnceRepository;

@GetMapping("/{studyOnceId:[0-9]+}")
public ResponseEntity<StudyOnceSearchResponse> search(@PathVariable Long studyOnceId) {
Expand Down Expand Up @@ -82,4 +91,25 @@ public ResponseEntity<UpdateAttendanceResponse> takeAttendance(@PathVariable Lon
return ResponseEntity.ok(response);
}

@PatchMapping("/{studyOnceId:[0-9]+}/location")
public ResponseEntity<CafeSearchResponse> changeCafe(@PathVariable Long studyOnceId,
@RequestHeader("Authorization") String authorization,
@RequestBody Long cafeId) {
long leaderId = cafegoryTokenManager.getIdentityId(authorization);
Long changedCafeId = studyOnceService.changeCafe(leaderId, studyOnceId, cafeId);
CafeSearchResponse response = cafeQueryService.searchCafeBasicInfoById(changedCafeId);
return ResponseEntity.ok(response);
}

@GetMapping("/{studyOnceId:[0-9]+}/member/list")
public ResponseEntity<StudyMembersResponse> findStudyMemberList(@PathVariable Long studyOnceId,
@RequestHeader("Authorization") String authorization) {
long leaderId = cafegoryTokenManager.getIdentityId(authorization);
if (!studyOnceService.isStudyOnceLeader(leaderId, studyOnceId)) {
throw new CafegoryException(STUDY_ONCE_LEADER_PERMISSION_DENIED);
}
StudyMembersResponse response = studyOnceService.findStudyMembersById(studyOnceId);
return ResponseEntity.ok(response);
}

}
1 change: 1 addition & 0 deletions src/main/java/com/example/demo/domain/MemberImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ public class MemberImpl implements Member {
public void addStudyMember(StudyMember studyMember) {
studyMembers.add(studyMember);
}

}
5 changes: 5 additions & 0 deletions src/main/java/com/example/demo/domain/StudyOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public interface StudyOnce {
StudyMember tryQuit(Member memberThatExpectedToQuit, LocalDateTime requestTime);

void updateAttendance(Member leader, Member member, boolean attendance);

void changeCafe(CafeImpl cafe);

boolean isLeader(MemberImpl member);

}
11 changes: 11 additions & 0 deletions src/main/java/com/example/demo/domain/StudyOnceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ public void updateAttendance(Member leader, Member member, boolean attendance) {

}

@Override
public void changeCafe(CafeImpl cafe) {
this.cafe = cafe;
cafe.getStudyOnceGroup().add(this);
}

@Override
public boolean isLeader(MemberImpl member) {
return leader.getId().equals(member.getId());
}

public boolean canJoin(LocalDateTime baseDateTime) {
Duration between = Duration.between(baseDateTime, startDateTime);
return between.toSeconds() >= 60 * 60;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/example/demo/dto/MemberResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.demo.dto;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class MemberResponse {

private final long memberId;
private final String name;
private final String thumbnailImg;
}
14 changes: 14 additions & 0 deletions src/main/java/com/example/demo/dto/StudyMembersResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.demo.dto;

import java.util.List;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StudyMembersResponse {

private final List<MemberResponse> joinedMembers;

}
2 changes: 2 additions & 0 deletions src/main/java/com/example/demo/exception/ExceptionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public enum ExceptionType {
STUDY_ONCE_TRY_QUIT_NOT_JOIN(CONFLICT, "참여중인 카공이 아닙니다."),
STUDY_ONCE_LEADER_QUIT_FAIL(CONFLICT, "카공장은 다른 참여자가 있는 경우 참여 취소를 할 수 없습니다."),
STUDY_ONCE_INVALID_LEADER(BAD_REQUEST, "스터디 리더가 아닙니다."),
STUDY_ONCE_LEADER_PERMISSION_DENIED(FORBIDDEN, "스터디 리더만 권한이 있습니다."),
STUDY_ONCE_LOCATION_CHANGE_PERMISSION_DENIED(FORBIDDEN, "스터디 리더만 장소 변경을 할 권한이 있습니다."),
STUDY_ONCE_EARLY_TAKE_ATTENDANCE(BAD_REQUEST, "스터디 출석체크는 스터디 시작 10분 이후여야 합니다."),
STUDY_ONCE_LATE_TAKE_ATTENDANCE(BAD_REQUEST, "스터디 출석체크는 스터디 진행시간 절반이 지나기전에만 변경할 수 있습니다. "),
MEMBER_NOT_FOUND(NOT_FOUND, "없는 회원입니다."),
Expand Down
42 changes: 25 additions & 17 deletions src/main/java/com/example/demo/mapper/CafeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,35 @@ public List<CafeSearchResponse> toCafeSearchResponses(List<CafeImpl> cafes,
OpenChecker<BusinessHour> openChecker) {
return cafes.stream()
.map(cafe ->
new CafeSearchResponse(
cafe.getId(),
cafe.getName(),
cafe.showFullAddress(),
cafe.getBusinessHours().stream()
.map(hour -> new BusinessHourResponse(hour.getDay(), hour.getStartTime().toString(),
hour.getEndTime().toString()))
.collect(Collectors.toList()),
cafe.isOpen(openChecker),
cafe.getSnsDetails().stream()
.map(s -> new SnsResponse(s.getName(), s.getUrl()))
.collect(Collectors.toList()),
cafe.getPhone(),
cafe.getMinBeveragePrice(),
cafe.getMaxAllowableStay().getValue(),
cafe.getAvgReviewRate()
)
produceCafeSearchResponse(cafe, openChecker)
)
.collect(Collectors.toList());
}

private CafeSearchResponse produceCafeSearchResponse(CafeImpl cafe, OpenChecker<BusinessHour> openChecker) {
return new CafeSearchResponse(
cafe.getId(),
cafe.getName(),
cafe.showFullAddress(),
cafe.getBusinessHours().stream()
.map(hour -> new BusinessHourResponse(hour.getDay(), hour.getStartTime().toString(),
hour.getEndTime().toString()))
.collect(Collectors.toList()),
cafe.isOpen(openChecker),
cafe.getSnsDetails().stream()
.map(s -> new SnsResponse(s.getName(), s.getUrl()))
.collect(Collectors.toList()),
cafe.getPhone(),
cafe.getMinBeveragePrice(),
cafe.getMaxAllowableStay().getValue(),
cafe.getAvgReviewRate()
);
}

public CafeSearchResponse toCafeSearchResponse(CafeImpl cafe, OpenChecker<BusinessHour> openChecker) {
return produceCafeSearchResponse(cafe, openChecker);
}

public CafeBasicInfoResponse toCafeBasicInfoResponse(CafeImpl cafe,
List<BusinessHourResponse> businessHourResponses,
List<SnsResponse> snsResponses,
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/example/demo/mapper/StudyMemberMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.demo.mapper;

import java.util.List;
import java.util.stream.Collectors;

import com.example.demo.domain.StudyMember;
import com.example.demo.dto.MemberResponse;

public class StudyMemberMapper {

public List<MemberResponse> toMemberResponses(List<StudyMember> studyMembers) {
return studyMembers.stream()
.map(studyMember -> new MemberResponse(
studyMember.getMember().getId(),
studyMember.getMember().getName(),
studyMember.getMember().getThumbnailImage().getThumbnailImage()))
.collect(Collectors.toList());
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/example/demo/service/CafeQueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface CafeQueryService {

CafeResponse searchCafeById(Long cafeId);

CafeSearchResponse searchCafeBasicInfoById(Long cafeId);

CafeResponse searchCafeForMemberByCafeId(Long cafeId, Long memberId);

CafeResponse searchCafeForNotMemberByCafeId(Long cafeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public CafeResponse searchCafeById(Long cafeId) {
);
}

@Override
public CafeSearchResponse searchCafeBasicInfoById(Long cafeId) {
return cafeMapper.toCafeSearchResponse(findCafeById(cafeId), openChecker);
}

private CafeImpl findCafeById(Long cafeId) {
return cafeRepository.findById(cafeId)
.orElseThrow(() -> new CafegoryException(CAFE_NOT_FOUND));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/service/StudyOnceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.example.demo.domain.Attendance;
import com.example.demo.dto.PagedResponse;
import com.example.demo.dto.StudyMembersResponse;
import com.example.demo.dto.StudyOnceCreateRequest;
import com.example.demo.dto.StudyOnceSearchRequest;
import com.example.demo.dto.StudyOnceSearchResponse;
Expand All @@ -25,4 +26,10 @@ UpdateAttendanceResponse updateAttendances(long leaderId, long studyOnceId,
void updateAttendance(long leaderId, long studyOnceId, long memberId, Attendance attendance, LocalDateTime now);

StudyOnceSearchResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest);

Long changeCafe(Long requestMemberId, Long studyOnceId, Long changingCafeId);

StudyMembersResponse findStudyMembersById(Long studyOnceId);

boolean isStudyOnceLeader(Long memberId, Long studyOnceId);
}
36 changes: 36 additions & 0 deletions src/main/java/com/example/demo/service/StudyOnceServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
import com.example.demo.domain.StudyMember;
import com.example.demo.domain.StudyMemberId;
import com.example.demo.domain.StudyOnceImpl;
import com.example.demo.dto.MemberResponse;
import com.example.demo.dto.PagedResponse;
import com.example.demo.dto.StudyMemberStateRequest;
import com.example.demo.dto.StudyMemberStateResponse;
import com.example.demo.dto.StudyMembersResponse;
import com.example.demo.dto.StudyOnceCreateRequest;
import com.example.demo.dto.StudyOnceSearchRequest;
import com.example.demo.dto.StudyOnceSearchResponse;
import com.example.demo.dto.UpdateAttendanceRequest;
import com.example.demo.dto.UpdateAttendanceResponse;
import com.example.demo.exception.CafegoryException;
import com.example.demo.mapper.StudyMemberMapper;
import com.example.demo.mapper.StudyOnceMapper;
import com.example.demo.repository.MemberRepository;
import com.example.demo.repository.StudyMemberRepository;
Expand All @@ -43,6 +46,7 @@ public class StudyOnceServiceImpl implements StudyOnceService {
private final MemberRepository memberRepository;
private final StudyMemberRepository studyMemberRepository;
private final StudyOnceMapper studyOnceMapper;
private final StudyMemberMapper studyMemberMapper;

@Override
public void tryJoin(long memberIdThatExpectedToJoin, long studyId) {
Expand Down Expand Up @@ -192,4 +196,36 @@ private MemberImpl getMember(long leaderId, LocalDateTime startDateTime) {
return leader;
}

@Override
public Long changeCafe(Long requestMemberId, Long studyOnceId, final Long changingCafeId) {
final StudyOnceImpl studyOnce = findStudyOnceById(studyOnceId);
if (!isStudyOnceLeader(requestMemberId, studyOnceId)) {
throw new CafegoryException(STUDY_ONCE_LOCATION_CHANGE_PERMISSION_DENIED);
}
studyOnce.changeCafe(findCafeById(changingCafeId));
return changingCafeId;
}

@Override
public StudyMembersResponse findStudyMembersById(Long studyOnceId) {
StudyOnceImpl studyOnce = findStudyOnceById(studyOnceId);
List<MemberResponse> memberResponses = studyMemberMapper.toMemberResponses(studyOnce.getStudyMembers());
return new StudyMembersResponse(memberResponses);
}

@Override
public boolean isStudyOnceLeader(Long memberId, Long studyOnceId) {
StudyOnceImpl studyOnce = findStudyOnceById(studyOnceId);
return studyOnce.isLeader(findMemberById(memberId));
}

private MemberImpl findMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new CafegoryException(MEMBER_NOT_FOUND));
}

private CafeImpl findCafeById(Long cafeId) {
return cafeRepository.findById(cafeId)
.orElseThrow(() -> new CafegoryException(CAFE_NOT_FOUND));
}
}
Loading

0 comments on commit f69ad4e

Please sign in to comment.