Skip to content

Commit

Permalink
Merge pull request #51 from Cafegory/feature-49
Browse files Browse the repository at this point in the history
[BUILD SUCCESS] [BUILD SUCCESS] [BUILD SUCCESS] api 문서,,코드 변경, mapper 클래스 추가 및 코드 리팩토링
  • Loading branch information
robinjoon authored Mar 17, 2024
2 parents 1d05444 + e08aa00 commit 21bfa6b
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 218 deletions.
39 changes: 39 additions & 0 deletions src/main/java/com/example/demo/config/MapperConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.example.demo.mapper.BusinessHourMapper;
import com.example.demo.mapper.CafeMapper;
import com.example.demo.mapper.ReviewMapper;
import com.example.demo.mapper.SnsDetailMapper;
import com.example.demo.mapper.StudyOnceMapper;

@Configuration
public class MapperConfig {

@Bean
public BusinessHourMapper businessHourMapper() {
return new BusinessHourMapper();
}

@Bean
public CafeMapper cafeMapper() {
return new CafeMapper();
}

@Bean
public ReviewMapper reviewMapper() {
return new ReviewMapper();
}

@Bean
public SnsDetailMapper snsDetailMapper() {
return new SnsDetailMapper();
}

@Bean
public StudyOnceMapper studyOnceMapper() {
return new StudyOnceMapper();
}
}
24 changes: 12 additions & 12 deletions src/main/java/com/example/demo/controller/StudyOnceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class StudyOnceController {
private final StudyOnceService studyOnceService;
private final CafegoryTokenManager cafegoryTokenManager;

@GetMapping("/{studyId:[0-9]+}")
public ResponseEntity<StudyOnceSearchResponse> search(@PathVariable Long studyId) {
StudyOnceSearchResponse response = studyOnceService.searchByStudyId(studyId);
@GetMapping("/{studyOnceId:[0-9]+}")
public ResponseEntity<StudyOnceSearchResponse> search(@PathVariable Long studyOnceId) {
StudyOnceSearchResponse response = studyOnceService.searchByStudyId(studyOnceId);
return ResponseEntity.ok(response);
}

Expand All @@ -54,30 +54,30 @@ public ResponseEntity<StudyOnceSearchResponse> create(@RequestBody StudyOnceCrea
return ResponseEntity.ok(response);
}

@PostMapping("/{studyId:[0-9]+}")
public ResponseEntity<StudyOnceJoinResult> tryJoin(@PathVariable Long studyId,
@PostMapping("/{studyOnceId:[0-9]+}")
public ResponseEntity<StudyOnceJoinResult> tryJoin(@PathVariable Long studyOnceId,
@RequestHeader("Authorization") String authorization) {
long memberId = cafegoryTokenManager.getIdentityId(authorization);
LocalDateTime requestTime = LocalDateTime.now();
studyOnceService.tryJoin(memberId, studyId);
studyOnceService.tryJoin(memberId, studyOnceId);
return ResponseEntity.ok(new StudyOnceJoinResult(requestTime, true));
}

@DeleteMapping("/{studyId:[0-9]+}")
public ResponseEntity<StudyOnceJoinResult> tryQuit(@PathVariable Long studyId,
@DeleteMapping("/{studyOnceId:[0-9]+}")
public ResponseEntity<StudyOnceJoinResult> tryQuit(@PathVariable Long studyOnceId,
@RequestHeader("Authorization") String authorization) {
long memberId = cafegoryTokenManager.getIdentityId(authorization);
LocalDateTime requestTime = LocalDateTime.now();
studyOnceService.tryQuit(memberId, studyId);
studyOnceService.tryQuit(memberId, studyOnceId);
return ResponseEntity.ok(new StudyOnceJoinResult(requestTime, true));
}

@PatchMapping("/{studyId:[0-9]+}/attendance")
public ResponseEntity<UpdateAttendanceResponse> takeAttendance(@PathVariable Long studyId,
@PatchMapping("/{studyOnceId:[0-9]+}/attendance")
public ResponseEntity<UpdateAttendanceResponse> takeAttendance(@PathVariable Long studyOnceId,
@RequestHeader("Authorization") String authorization,
@RequestBody UpdateAttendanceRequest request) {
long leaderId = cafegoryTokenManager.getIdentityId(authorization);
UpdateAttendanceResponse response = studyOnceService.updateAttendances(leaderId, studyId,
UpdateAttendanceResponse response = studyOnceService.updateAttendances(leaderId, studyOnceId,
request, LocalDateTime.now());
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
@Getter
public class StudyMemberStateRequest {

private Long userId;
private Long memberId;
private boolean attendance;
private LocalDateTime lastUpdateTime;

public StudyMemberStateRequest() {
}

public StudyMemberStateRequest(Long userId, boolean attendance, LocalDateTime lastUpdateTime) {
this.userId = userId;
public StudyMemberStateRequest(Long memberId, boolean attendance, LocalDateTime lastUpdateTime) {
this.memberId = memberId;
this.attendance = attendance;
this.lastUpdateTime = lastUpdateTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@RequiredArgsConstructor
public class StudyMemberStateResponse {

private final Long userId;
private final Long memberId;
private final boolean attendance;
private final LocalDateTime lastUpdateTime;

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/example/demo/mapper/BusinessHourMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.demo.mapper;

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

import com.example.demo.domain.BusinessHour;
import com.example.demo.dto.BusinessHourResponse;

public class BusinessHourMapper {

public List<BusinessHourResponse> toBusinessHourResponses(List<BusinessHour> businessHours) {
return businessHours.stream()
.map(hour -> new BusinessHourResponse(hour.getDay(), hour.getStartTime().toString(),
hour.getEndTime().toString()))
.collect(Collectors.toList());
}

}
130 changes: 130 additions & 0 deletions src/main/java/com/example/demo/mapper/CafeMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.example.demo.mapper;

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

import com.example.demo.domain.BusinessHour;
import com.example.demo.domain.CafeImpl;
import com.example.demo.domain.CafeSearchCondition;
import com.example.demo.domain.OpenChecker;
import com.example.demo.dto.BusinessHourResponse;
import com.example.demo.dto.CafeBasicInfoResponse;
import com.example.demo.dto.CafeResponse;
import com.example.demo.dto.CafeSearchRequest;
import com.example.demo.dto.CafeSearchResponse;
import com.example.demo.dto.CanMakeStudyOnceResponse;
import com.example.demo.dto.ReviewResponse;
import com.example.demo.dto.SnsResponse;
import com.example.demo.dto.StudyOnceForCafeResponse;

public class CafeMapper {

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()
)
)
.collect(Collectors.toList());
}

public CafeBasicInfoResponse toCafeBasicInfoResponse(CafeImpl cafe,
List<BusinessHourResponse> businessHourResponses,
List<SnsResponse> snsResponses,
OpenChecker<BusinessHour> openChecker) {
return new CafeBasicInfoResponse(
cafe.getId(),
cafe.getName(),
cafe.showFullAddress(),
businessHourResponses,
cafe.isOpen(openChecker),
snsResponses,
cafe.getPhone(),
cafe.getMinBeveragePrice(),
cafe.getMaxAllowableStay().getValue(),
cafe.getAvgReviewRate()
);
}

public CafeSearchCondition toCafeSearchCondition(CafeSearchRequest request) {
return new CafeSearchCondition.Builder(request.isCanStudy(),
request.getArea())
.maxTime(request.getMaxTime())
.minMenuPrice(request.getMinBeveragePrice())
.startTime(request.getStartTime())
.endTime(request.getEndTime())
.build();
}

public CafeResponse toCafeResponse(
CafeImpl findCafe,
List<BusinessHourResponse> businessHourResponses,
List<SnsResponse> snsResponses,
List<ReviewResponse> reviewResponses,
List<StudyOnceForCafeResponse> studyOnceForCafeResponses,
OpenChecker<BusinessHour> openChecker) {
return CafeResponse.builder()
.basicInfo(
toCafeBasicInfoResponse(
findCafe,
businessHourResponses,
snsResponses,
openChecker)
)
.review(
reviewResponses
)
.meetings(
studyOnceForCafeResponses
)
.canMakeMeeting(
List.of(new CanMakeStudyOnceResponse(), new CanMakeStudyOnceResponse())
)
.build();
}

public CafeResponse toCafeResponseWithEmptyInfo(
CafeImpl findCafe,
List<BusinessHourResponse> businessHourResponses,
List<SnsResponse> snsResponses,
List<ReviewResponse> reviewResponses,
OpenChecker<BusinessHour> openChecker
) {
return CafeResponse.builder()
.basicInfo(
toCafeBasicInfoResponse(
findCafe,
businessHourResponses,
snsResponses,
openChecker)
)
.review(
reviewResponses
)
.meetings(
Collections.emptyList()
)
.canMakeMeeting(
Collections.emptyList()
)
.build();
}

}
77 changes: 77 additions & 0 deletions src/main/java/com/example/demo/mapper/ReviewMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.example.demo.mapper;

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

import com.example.demo.domain.MemberImpl;
import com.example.demo.domain.ReviewImpl;
import com.example.demo.dto.ReviewResponse;
import com.example.demo.dto.ReviewSearchResponse;
import com.example.demo.dto.WriterResponse;

public class ReviewMapper {

public List<ReviewSearchResponse> toReviewSearchResponses(List<ReviewImpl> reviews) {
return reviews.stream()
.map(review ->
new ReviewSearchResponse(
review.getId(),
produceWriterResponse(
review.getMember().getId(), review.getMember().getName(),
review.getMember().getThumbnailImage().getThumbnailImage()
),
review.getRate(),
review.getContent()
))
.collect(Collectors.toList());
}

private WriterResponse produceWriterResponse(Long memberId, String name, String thumbnailImg) {
return new WriterResponse(memberId, name, thumbnailImg);
}

public ReviewResponse toReviewResponse(ReviewImpl findReview) {
return ReviewResponse.builder()
.reviewId(findReview.getId())
.writer(
produceWriterResponse(
findReview.getMember().getId(),
findReview.getMember().getName(),
findReview.getMember().getThumbnailImage().getThumbnailImage()
))
.rate(findReview.getRate())
.content(findReview.getContent())
.build();
}

public List<ReviewResponse> toReviewResponses(List<ReviewImpl> reviews) {
return reviews.stream()
.map(review ->
produceReviewResponse(
review.getId(),
productWriterResponse(review.getMember()),
review.getRate(),
review.getContent()
)
)
.collect(Collectors.toList());
}

private ReviewResponse produceReviewResponse(Long reviewId, WriterResponse writerResponse, double rate,
String content) {
return ReviewResponse.builder()
.reviewId(reviewId)
.writer(writerResponse)
.rate(rate)
.content(content)
.build();
}

private WriterResponse productWriterResponse(MemberImpl member) {
return new WriterResponse(member.getId(),
member.getName(),
member.getThumbnailImage().getThumbnailImage()
);
}

}
16 changes: 16 additions & 0 deletions src/main/java/com/example/demo/mapper/SnsDetailMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.demo.mapper;

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

import com.example.demo.domain.SnsDetail;
import com.example.demo.dto.SnsResponse;

public class SnsDetailMapper {

public List<SnsResponse> toSnsResponses(List<SnsDetail> snsDetails) {
return snsDetails.stream()
.map(snsDetail -> new SnsResponse(snsDetail.getName(), snsDetail.getUrl()))
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 21bfa6b

Please sign in to comment.