-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Cafegory/feature-49
[BUILD SUCCESS] [BUILD SUCCESS] [BUILD SUCCESS] api 문서,,코드 변경, mapper 클래스 추가 및 코드 리팩토링
- Loading branch information
Showing
13 changed files
with
409 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/demo/mapper/BusinessHourMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/main/java/com/example/demo/mapper/SnsDetailMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.