Skip to content

Commit

Permalink
Merge pull request #131 from Guzzing/refactor/review
Browse files Browse the repository at this point in the history
[Refactor/review] 리뷰 도메인 리팩토링
  • Loading branch information
onetuks authored Dec 31, 2023
2 parents abde55c + 59c36ad commit 6ebcf84
Show file tree
Hide file tree
Showing 57 changed files with 894 additions and 764 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {

plugins {
id 'java'
id 'jacoco'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'com.epages.restdocs-api-spec' version "${restdocsApiSpecVersion}"
Expand Down Expand Up @@ -121,5 +122,10 @@ dependencies {
}

tasks.named('test') {
finalizedBy jacocoTestReport
useJUnitPlatform()
}

tasks.named('jacocoTestReport') {
dependsOn test
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public ResponseEntity<AcademyGetResponse> getAcademy(
@PathVariable Long academyId,
@MemberId Long memberId
) {
AcademyDetailFacadeResult detailAcademy = academyFacade.getDetailAcademy(AcademyDetailFacadeParam.of(memberId, academyId));
AcademyDetailFacadeResult detailAcademy = academyFacade.getDetailAcademy(
AcademyDetailFacadeParam.of(memberId, academyId));

return ResponseEntity.status(HttpStatus.OK)
.body(AcademyGetResponse.from(detailAcademy));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.guzzing.studayserver.domain.academy.controller.dto.response;

import java.util.List;

import org.guzzing.studayserver.domain.academy.facade.dto.AcademyDetailFacadeResult;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyGetResult;

public record AcademyGetResponse(
String academyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademiesByLocationWithScrollResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyGetResult;
import org.guzzing.studayserver.domain.academy.util.GeometryUtil;
import org.guzzing.studayserver.domain.like.service.LikeService;
import org.guzzing.studayserver.domain.like.service.LikeFacade;
import org.guzzing.studayserver.domain.region.service.RegionService;
import org.guzzing.studayserver.domain.region.service.dto.location.RegionResult;
import org.springframework.stereotype.Service;
Expand All @@ -19,16 +19,17 @@ public class AcademyFacade {

private final RegionService regionService;
private final AcademyService academyService;
private final LikeService likeService;
private final LikeFacade likeFacade;

public AcademyFacade(RegionService regionService, AcademyService academyService, LikeService likeService) {
public AcademyFacade(RegionService regionService, AcademyService academyService, LikeFacade likeFacade) {
this.regionService = regionService;
this.academyService = academyService;
this.likeService = likeService;
this.likeFacade = likeFacade;
}

@Transactional(readOnly = true)
public AcademiesByLocationWithScrollFacadeResult findByLocationWithScroll(AcademiesByLocationWithScrollFacadeParam param) {
public AcademiesByLocationWithScrollFacadeResult findByLocationWithScroll(
AcademiesByLocationWithScrollFacadeParam param) {
AcademiesByLocationWithScrollResults academiesByLocationWithScroll = academyService.findAcademiesByLocationWithScroll(
AcademiesByLocationWithScrollFacadeParam.to(param));

Expand All @@ -45,7 +46,7 @@ public AcademiesByLocationWithScrollFacadeResult findByLocationWithScroll(Academ
@Transactional(readOnly = true)
public AcademyDetailFacadeResult getDetailAcademy(AcademyDetailFacadeParam param) {
AcademyGetResult academyGetResult = academyService.getAcademy(param.academyId());
boolean liked = likeService.isLiked(param.academyId(), param.memberId());
boolean liked = likeFacade.isLiked(param.memberId(), param.academyId());

return AcademyDetailFacadeResult.of(academyGetResult, liked);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.guzzing.studayserver.domain.academy.facade.dto;

import java.util.List;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyGetResult;
import org.guzzing.studayserver.domain.academy.service.dto.result.LessonGetResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.ReviewPercentGetResult;

import java.util.List;

public record AcademyDetailFacadeResult(
String academyName,
String contact,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.guzzing.studayserver.domain.academy.model;

import static org.guzzing.studayserver.domain.academy.listener.NewReviewType.CHEAP_FEE;
import static org.guzzing.studayserver.domain.academy.listener.NewReviewType.GOOD_FACILITY;
import static org.guzzing.studayserver.domain.academy.listener.NewReviewType.GOOD_MANAGEMENT;
import static org.guzzing.studayserver.domain.academy.listener.NewReviewType.KINDNESS;
import static org.guzzing.studayserver.domain.academy.listener.NewReviewType.LOVELY_TEACHING;
import static org.guzzing.studayserver.domain.academy.listener.NewReviewType.SHUTTLE_AVAILABILITY;
import static org.guzzing.studayserver.domain.review.model.ReviewType.CHEAP_FEE;
import static org.guzzing.studayserver.domain.review.model.ReviewType.GOOD_FACILITY;
import static org.guzzing.studayserver.domain.review.model.ReviewType.GOOD_MANAGEMENT;
import static org.guzzing.studayserver.domain.review.model.ReviewType.KINDNESS;
import static org.guzzing.studayserver.domain.review.model.ReviewType.LOVELY_TEACHING;
import static org.guzzing.studayserver.domain.review.model.ReviewType.SHUTTLE_AVAILABILITY;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -17,7 +17,7 @@
import jakarta.persistence.Table;
import java.util.Map;
import lombok.Getter;
import org.guzzing.studayserver.domain.academy.listener.NewReviewType;
import org.guzzing.studayserver.domain.review.model.ReviewType;

@Getter
@Entity
Expand Down Expand Up @@ -84,12 +84,14 @@ public static ReviewCount makeDefaultReviewCount(Academy academy) {
academy);
}

public void updateSelectedReviewCount(final Map<NewReviewType, Integer> newReview) {
this.kindnessCount += newReview.get(KINDNESS);
this.goodFacilityCount += newReview.get(GOOD_FACILITY);
this.cheapFeeCount += newReview.get(CHEAP_FEE);
this.goodManagementCount += newReview.get(GOOD_MANAGEMENT);
this.lovelyTeachingCount += newReview.get(LOVELY_TEACHING);
this.shuttleAvailabilityCount += newReview.get(SHUTTLE_AVAILABILITY);
public void updateSelectedReviewCount(final Map<ReviewType, Boolean> newReview) {
final Map<ReviewType, Integer> reviewCountMap = ReviewType.convertToReviewTypeCountMap(newReview);

this.kindnessCount += reviewCountMap.get(KINDNESS);
this.goodFacilityCount += reviewCountMap.get(GOOD_FACILITY);
this.cheapFeeCount += reviewCountMap.get(CHEAP_FEE);
this.goodManagementCount += reviewCountMap.get(GOOD_MANAGEMENT);
this.lovelyTeachingCount += reviewCountMap.get(LOVELY_TEACHING);
this.shuttleAvailabilityCount += reviewCountMap.get(SHUTTLE_AVAILABILITY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;

import java.util.List;

import org.guzzing.studayserver.domain.academy.repository.dto.AcademiesByFilterWithScroll;
import org.guzzing.studayserver.domain.academy.repository.dto.AcademiesByLocationWithScroll;
import org.guzzing.studayserver.domain.academy.repository.dto.AcademyByFilterWithScroll;
Expand Down Expand Up @@ -67,7 +65,7 @@ public AcademiesByLocationWithScroll findAcademiesByLocation(
.addScalar("longitude", StandardBasicTypes.DOUBLE)
.addScalar("shuttleAvailable", StandardBasicTypes.STRING)
.addScalar("isLiked", StandardBasicTypes.BOOLEAN)
.addScalar("categoryId",StandardBasicTypes.LONG)
.addScalar("categoryId", StandardBasicTypes.LONG)
.setResultTransformer((tuple, aliases) -> new AcademyByLocationWithScroll(
(Long) tuple[0],
(String) tuple[1],
Expand All @@ -81,7 +79,6 @@ public AcademiesByLocationWithScroll findAcademiesByLocation(
))
.getResultList();


return AcademiesByLocationWithScroll.of(
academiesByLocation,
isHasNest(academiesByLocation.size(), pageSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public record AcademiesByLocationWithScroll(
Map<AcademyByLocation,List<Long>> academiesByLocation,
Map<AcademyByLocation, List<Long>> academiesByLocation,
boolean hasNext
) {

Expand All @@ -18,7 +17,8 @@ public static AcademiesByLocationWithScroll of(
Map<AcademyByLocation, List<Long>> academyIdWithCategories = new ConcurrentHashMap<>();

academiesByLocation.forEach(academyByLocationWithScroll -> {
academyIdWithCategories.computeIfAbsent(AcademyByLocation.of(academyByLocationWithScroll), k -> new ArrayList<>())
academyIdWithCategories.computeIfAbsent(AcademyByLocation.of(academyByLocationWithScroll),
k -> new ArrayList<>())
.add(academyByLocationWithScroll.categoryId());
});

Expand All @@ -27,6 +27,7 @@ public static AcademiesByLocationWithScroll of(
hasNext
);
}

public record AcademyByLocation(
Long academyId,
String academyName,
Expand All @@ -37,6 +38,7 @@ public record AcademyByLocation(
String shuttleAvailable,
boolean isLiked
) {

public static AcademyByLocation of(AcademyByLocationWithScroll academyByLocationWithScroll) {
return new AcademyByLocation(
academyByLocationWithScroll.academyId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.guzzing.studayserver.domain.academy.repository.dto;

import java.util.Objects;

public record AcademyByLocationWithScroll(
Long academyId,
String academyName,
Expand All @@ -13,4 +11,5 @@ public record AcademyByLocationWithScroll(
boolean isLiked,
Long categoryId
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface AcademyFee {

long getMaxEducationFee();
Long getMaxEducationFee();

String getAcademyName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.guzzing.studayserver.domain.academy.model.Academy;
import org.guzzing.studayserver.domain.academy.model.Lesson;
import org.guzzing.studayserver.domain.academy.model.ReviewCount;
import org.guzzing.studayserver.domain.academy.repository.academy.AcademyRepository;
import org.guzzing.studayserver.domain.academy.repository.academycategory.AcademyCategoryRepository;
import org.guzzing.studayserver.domain.academy.repository.dto.AcademiesByFilterWithScroll;
Expand All @@ -19,6 +20,7 @@
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademiesByNameResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademiesFilterWithScrollResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyAndLessonDetailResult;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyFeeInfo;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyGetResult;
import org.guzzing.studayserver.domain.academy.service.dto.result.LessonInfoToCreateDashboardResults;
import org.guzzing.studayserver.domain.academy.util.GeometryUtil;
Expand All @@ -38,14 +40,29 @@ public class AcademyService {
private final AcademyCategoryRepository academyCategoryRepository;

public AcademyService(AcademyRepository academyRepository, LessonRepository lessonRepository,
ReviewCountRepository reviewCountRepository,
AcademyCategoryRepository academyCategoryRepository) {
ReviewCountRepository reviewCountRepository,
AcademyCategoryRepository academyCategoryRepository) {
this.academyRepository = academyRepository;
this.lessonRepository = lessonRepository;
this.reviewCountRepository = reviewCountRepository;
this.academyCategoryRepository = academyCategoryRepository;
}

@Transactional(readOnly = true)
public Academy getAcademy(final long academyId) {
return academyRepository.getById(academyId);
}

@Transactional(readOnly = true)
public ReviewCount getReviewCountOfAcademy(final long academyId) {
return reviewCountRepository.getByAcademyId(academyId);
}

@Transactional(readOnly = true)
public AcademyFeeInfo findAcademyFeeInfo(final long academyId) {
return AcademyFeeInfo.from(academyRepository.findAcademyFeeInfo(academyId));
}

@Transactional(readOnly = true)
public AcademyGetResult getAcademy(Long academyId) {
return AcademyGetResult.from(
Expand All @@ -56,7 +73,8 @@ public AcademyGetResult getAcademy(Long academyId) {
}

@Transactional(readOnly = true)
public AcademiesByLocationWithScrollResults findAcademiesByLocationWithScroll(AcademiesByLocationWithScrollParam param) {
public AcademiesByLocationWithScrollResults findAcademiesByLocationWithScroll(
AcademiesByLocationWithScrollParam param) {
String diagonal = GeometryUtil.makeDiagonal(param.baseLatitude(), param.baseLongitude(), DISTANCE);

AcademiesByLocationWithScroll academiesByLocation = academyRepository.findAcademiesByLocation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.guzzing.studayserver.domain.academy.service.dto.result;

import java.util.List;
import java.util.Map;
import org.guzzing.studayserver.domain.academy.repository.dto.AcademiesByLocationWithScroll;
import org.guzzing.studayserver.domain.academy.repository.dto.AcademyByLocationWithScroll;
import org.guzzing.studayserver.domain.academy.util.CategoryInfo;

public record AcademiesByLocationWithScrollResults(
Expand All @@ -17,13 +15,13 @@ public static AcademiesByLocationWithScrollResults to(
academiesByLocationWithScroll
.academiesByLocation()
.keySet()
.stream()
.map(academyByLocation->
AcademiesByLocationResultWithScroll.from(
academyByLocation,
academiesByLocationWithScroll.academiesByLocation().
get(academyByLocation)))
.toList(),
.stream()
.map(academyByLocation ->
AcademiesByLocationResultWithScroll.from(
academyByLocation,
academiesByLocationWithScroll.academiesByLocation().
get(academyByLocation)))
.toList(),
academiesByLocationWithScroll.hasNext());
}

Expand All @@ -39,8 +37,9 @@ public record AcademiesByLocationResultWithScroll(
boolean isLiked
) {

public static AcademiesByLocationResultWithScroll from(AcademiesByLocationWithScroll.AcademyByLocation academyByLocationWithScroll,
List<Long> categories) {
public static AcademiesByLocationResultWithScroll from(
AcademiesByLocationWithScroll.AcademyByLocation academyByLocationWithScroll,
List<Long> categories) {
return new AcademiesByLocationResultWithScroll(
academyByLocationWithScroll.academyId(),
academyByLocationWithScroll.academyName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public record AcademyFeeInfo(
String academyName,
long expectedFee
Long expectedFee
) {

public static AcademyFeeInfo from(AcademyFee academyFee) {
Expand Down
Loading

0 comments on commit 6ebcf84

Please sign in to comment.