Skip to content

Commit

Permalink
Merge pull request #81 from Cafegory/feature-80
Browse files Browse the repository at this point in the history
[BUILD SUCCESS] 카공 모집글 조회 응답바디에 카공 모집글 작성자 id 추가 및 공통으로 쓰던 카공 관련 dto 분리
  • Loading branch information
donghyun0304 authored Apr 24, 2024
2 parents d6d1b25 + 94da076 commit fb89e03
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import com.example.demo.dto.study.StudyOnceCommentUpdateRequest;
import com.example.demo.dto.study.StudyOnceCommentsSearchResponse;
import com.example.demo.dto.study.StudyOnceCreateRequest;
import com.example.demo.dto.study.StudyOnceCreateResponse;
import com.example.demo.dto.study.StudyOnceInfoResponse;
import com.example.demo.dto.study.StudyOnceJoinResult;
import com.example.demo.dto.study.StudyOnceSearchListResponse;
import com.example.demo.dto.study.StudyOnceSearchRequest;
import com.example.demo.dto.study.StudyOnceSearchResponse;
import com.example.demo.dto.study.StudyOnceUpdateRequest;
Expand Down Expand Up @@ -59,22 +62,22 @@ public ResponseEntity<StudyOnceSearchResponse> search(@PathVariable Long studyOn
}

@GetMapping("/list")
public ResponseEntity<PagedResponse<StudyOnceSearchResponse>> searchList(
public ResponseEntity<PagedResponse<StudyOnceSearchListResponse>> searchList(
@ModelAttribute StudyOnceSearchRequest studyOnceSearchRequest) {
PagedResponse<StudyOnceSearchResponse> pagedResponse = studyOnceService.searchStudy(studyOnceSearchRequest);
PagedResponse<StudyOnceSearchListResponse> pagedResponse = studyOnceService.searchStudy(studyOnceSearchRequest);
return ResponseEntity.ok(pagedResponse);
}

@PostMapping("")
public ResponseEntity<StudyOnceSearchResponse> create(@RequestBody StudyOnceCreateRequest studyOnceCreateRequest,
public ResponseEntity<StudyOnceCreateResponse> create(@RequestBody StudyOnceCreateRequest studyOnceCreateRequest,
@RequestHeader("Authorization") String authorization) {
long memberId = cafegoryTokenManager.getIdentityId(authorization);
StudyOnceSearchResponse response = studyOnceService.createStudy(memberId, studyOnceCreateRequest);
StudyOnceCreateResponse response = studyOnceService.createStudy(memberId, studyOnceCreateRequest);
return ResponseEntity.ok(response);
}

@PatchMapping("/{studyOnceId:[0-9]+}")
public ResponseEntity<StudyOnceSearchResponse> update(@PathVariable Long studyOnceId,
public ResponseEntity<StudyOnceInfoResponse> update(@PathVariable Long studyOnceId,
@RequestBody StudyOnceUpdateRequest request,
@RequestHeader("Authorization") String authorization) {
long leaderId = cafegoryTokenManager.getIdentityId(authorization);
Expand All @@ -83,7 +86,7 @@ public ResponseEntity<StudyOnceSearchResponse> update(@PathVariable Long studyOn
} else {
studyOnceService.updateStudyOncePartially(leaderId, studyOnceId, request, LocalDateTime.now());
}
StudyOnceSearchResponse response = studyOnceService.findStudyOnce(studyOnceId, LocalDateTime.now());
StudyOnceInfoResponse response = studyOnceService.findStudyOnce(studyOnceId, LocalDateTime.now());
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.demo.dto.study;

import java.time.LocalDateTime;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class StudyOnceCreateResponse {
private long cafeId;
private String area;
private long studyOnceId;
private String name;
private LocalDateTime startDateTime;
private LocalDateTime endDateTime;
private int maxMemberCount;
private int nowMemberCount;
private boolean canTalk;
private boolean canJoin;
private boolean isEnd;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.demo.dto.study;

import java.time.LocalDateTime;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class StudyOnceInfoResponse {
private long cafeId;
private String area;
private long studyOnceId;
private String name;
private LocalDateTime startDateTime;
private LocalDateTime endDateTime;
private int maxMemberCount;
private int nowMemberCount;
private boolean canTalk;
private boolean canJoin;
private boolean isEnd;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.demo.dto.study;

import java.time.LocalDateTime;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class StudyOnceSearchListResponse {
private long cafeId;
private String area;
private long studyOnceId;
private String name;
private LocalDateTime startDateTime;
private LocalDateTime endDateTime;
private int maxMemberCount;
private int nowMemberCount;
private boolean canTalk;
private boolean canJoin;
private boolean isEnd;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@Data
public class StudyOnceSearchResponse {
private long cafeId;
private long creatorId;
private String area;
private long studyOnceId;
private String name;
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/example/demo/mapper/StudyOnceMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import com.example.demo.dto.WriterResponse;
import com.example.demo.dto.study.StudyOnceCommentResponse;
import com.example.demo.dto.study.StudyOnceCreateRequest;
import com.example.demo.dto.study.StudyOnceCreateResponse;
import com.example.demo.dto.study.StudyOnceForCafeResponse;
import com.example.demo.dto.study.StudyOnceInfoResponse;
import com.example.demo.dto.study.StudyOnceSearchListResponse;
import com.example.demo.dto.study.StudyOnceSearchResponse;

public class StudyOnceMapper {
Expand Down Expand Up @@ -47,8 +50,57 @@ public StudyOnce toNewEntity(StudyOnceCreateRequest studyOnceCreateRequest, Cafe
.build();
}

public StudyOnceInfoResponse toStudyOnceInfoResponse(StudyOnce saved, boolean canJoin) {
return StudyOnceInfoResponse.builder()
.cafeId(saved.getCafe().getId())
.area(saved.getCafe().getRegion())
.studyOnceId(saved.getId())
.name(saved.getName())
.startDateTime(saved.getStartDateTime())
.endDateTime(saved.getEndDateTime())
.maxMemberCount(saved.getMaxMemberCount())
.nowMemberCount(saved.getNowMemberCount())
.canTalk(saved.isAbleToTalk())
.canJoin(canJoin)
.isEnd(saved.isEnd())
.build();
}

public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolean canJoin) {
return StudyOnceSearchResponse.builder()
.cafeId(saved.getCafe().getId())
.creatorId(saved.getLeader().getId())
.area(saved.getCafe().getRegion())
.studyOnceId(saved.getId())
.name(saved.getName())
.startDateTime(saved.getStartDateTime())
.endDateTime(saved.getEndDateTime())
.maxMemberCount(saved.getMaxMemberCount())
.nowMemberCount(saved.getNowMemberCount())
.canTalk(saved.isAbleToTalk())
.canJoin(canJoin)
.isEnd(saved.isEnd())
.build();
}

public StudyOnceSearchListResponse toStudyOnceSearchListResponse(StudyOnce saved, boolean canJoin) {
return StudyOnceSearchListResponse.builder()
.cafeId(saved.getCafe().getId())
.area(saved.getCafe().getRegion())
.studyOnceId(saved.getId())
.name(saved.getName())
.startDateTime(saved.getStartDateTime())
.endDateTime(saved.getEndDateTime())
.maxMemberCount(saved.getMaxMemberCount())
.nowMemberCount(saved.getNowMemberCount())
.canTalk(saved.isAbleToTalk())
.canJoin(canJoin)
.isEnd(saved.isEnd())
.build();
}

public StudyOnceCreateResponse toStudyOnceCreateResponse(StudyOnce saved, boolean canJoin) {
return StudyOnceCreateResponse.builder()
.cafeId(saved.getCafe().getId())
.area(saved.getCafe().getRegion())
.studyOnceId(saved.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.example.demo.dto.PagedResponse;
import com.example.demo.dto.study.StudyMembersResponse;
import com.example.demo.dto.study.StudyOnceCreateRequest;
import com.example.demo.dto.study.StudyOnceCreateResponse;
import com.example.demo.dto.study.StudyOnceInfoResponse;
import com.example.demo.dto.study.StudyOnceSearchListResponse;
import com.example.demo.dto.study.StudyOnceSearchRequest;
import com.example.demo.dto.study.StudyOnceSearchResponse;
import com.example.demo.dto.study.StudyOnceUpdateRequest;
Expand All @@ -17,7 +20,7 @@ public interface StudyOnceService {

void tryQuit(long memberIdThatExpectedToQuit, long studyId);

PagedResponse<StudyOnceSearchResponse> searchStudy(StudyOnceSearchRequest studyOnceSearchRequest);
PagedResponse<StudyOnceSearchListResponse> searchStudy(StudyOnceSearchRequest studyOnceSearchRequest);

StudyOnceSearchResponse searchByStudyId(long studyId);

Expand All @@ -26,13 +29,13 @@ UpdateAttendanceResponse updateAttendances(long leaderId, long studyOnceId,

void updateAttendance(long leaderId, long studyOnceId, long memberId, Attendance attendance, LocalDateTime now);

StudyOnceSearchResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest);
StudyOnceCreateResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest);

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

StudyMembersResponse findStudyMembersById(Long studyOnceId);

StudyOnceSearchResponse findStudyOnce(Long studyOnceId, LocalDateTime now);
StudyOnceInfoResponse findStudyOnce(Long studyOnceId, LocalDateTime now);

boolean doesOnlyStudyLeaderExist(Long studyOnceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.example.demo.dto.study.StudyMemberStateResponse;
import com.example.demo.dto.study.StudyMembersResponse;
import com.example.demo.dto.study.StudyOnceCreateRequest;
import com.example.demo.dto.study.StudyOnceCreateResponse;
import com.example.demo.dto.study.StudyOnceInfoResponse;
import com.example.demo.dto.study.StudyOnceSearchListResponse;
import com.example.demo.dto.study.StudyOnceSearchRequest;
import com.example.demo.dto.study.StudyOnceSearchResponse;
import com.example.demo.dto.study.StudyOnceUpdateRequest;
Expand Down Expand Up @@ -79,15 +82,15 @@ private void deleteStudy(StudyOnce studyOnce) {
}

@Override
public PagedResponse<StudyOnceSearchResponse> searchStudy(StudyOnceSearchRequest studyOnceSearchRequest) {
public PagedResponse<StudyOnceSearchListResponse> searchStudy(StudyOnceSearchRequest studyOnceSearchRequest) {
int totalCount = Math.toIntExact(studyOnceRepository.count(studyOnceSearchRequest));
int sizePerPage = studyOnceSearchRequest.getSizePerPage();
int maxPage = calculateMaxPage(totalCount, sizePerPage);
List<StudyOnce> allByStudyOnceSearchRequest = studyOnceRepository.findAllByStudyOnceSearchRequest(
studyOnceSearchRequest);
List<StudyOnceSearchResponse> searchResults = allByStudyOnceSearchRequest
List<StudyOnceSearchListResponse> searchResults = allByStudyOnceSearchRequest
.stream()
.map(studyOnce -> studyOnceMapper.toStudyOnceSearchResponse(studyOnce,
.map(studyOnce -> studyOnceMapper.toStudyOnceSearchListResponse(studyOnce,
studyOnce.canJoin(LocalDateTime.now())))
.collect(Collectors.toList());
return new PagedResponse<>(studyOnceSearchRequest.getPage(), maxPage, searchResults.size(), searchResults);
Expand Down Expand Up @@ -177,7 +180,7 @@ private StudyOnce findStudyOnceById(long studyOnceId) {
}

@Override
public StudyOnceSearchResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest) {
public StudyOnceCreateResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest) {
Cafe cafe = cafeRepository.findById(studyOnceCreateRequest.getCafeId())
.orElseThrow(() -> new CafegoryException(CAFE_NOT_FOUND));
//ToDo 카페 영업시간 이내인지 확인 하는 작업 추가 필요
Expand All @@ -186,7 +189,7 @@ public StudyOnceSearchResponse createStudy(long leaderId, StudyOnceCreateRequest
StudyOnce studyOnce = studyOnceMapper.toNewEntity(studyOnceCreateRequest, cafe, leader);
StudyOnce saved = studyOnceRepository.save(studyOnce);
boolean canJoin = true;
return studyOnceMapper.toStudyOnceSearchResponse(saved, canJoin);
return studyOnceMapper.toStudyOnceCreateResponse(saved, canJoin);
}

@Override
Expand Down Expand Up @@ -240,9 +243,9 @@ public StudyMembersResponse findStudyMembersById(Long studyOnceId) {
}

@Override
public StudyOnceSearchResponse findStudyOnce(Long studyOnceId, LocalDateTime now) {
public StudyOnceInfoResponse findStudyOnce(Long studyOnceId, LocalDateTime now) {
StudyOnce studyOnce = findStudyOnceById(studyOnceId);
return studyOnceMapper.toStudyOnceSearchResponse(studyOnce, studyOnce.canJoin(now));
return studyOnceMapper.toStudyOnceInfoResponse(studyOnce, studyOnce.canJoin(now));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.example.demo.dto.profile.ProfileResponse;
import com.example.demo.dto.profile.ProfileUpdateRequest;
import com.example.demo.dto.study.StudyOnceCreateRequest;
import com.example.demo.dto.study.StudyOnceSearchResponse;
import com.example.demo.dto.study.StudyOnceCreateResponse;
import com.example.demo.exception.CafegoryException;
import com.example.demo.repository.cafe.InMemoryCafeRepository;
import com.example.demo.repository.member.InMemoryMemberRepository;
Expand Down Expand Up @@ -50,7 +50,7 @@ void successWhenRequestMemberIsLeaderWithTargetMember() {
long targetMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId();
LocalDateTime start = LocalDateTime.now().plusHours(4);
StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, start.plusHours(5), cafeId);
StudyOnceSearchResponse study = studyOnceService.createStudy(requestMemberId, studyOnceCreateRequest);
StudyOnceCreateResponse study = studyOnceService.createStudy(requestMemberId, studyOnceCreateRequest);
studyOnceService.tryJoin(targetMemberId, study.getStudyOnceId());
Assertions.assertDoesNotThrow(() -> profileService.get(requestMemberId, targetMemberId));
}
Expand Down
Loading

0 comments on commit fb89e03

Please sign in to comment.