Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor : 학원 목록 조회 2차 캐시 적용 #148

Merged
merged 11 commits into from
Feb 23, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.guzzing.studayserver.domain.academy.controller.dto.request.AcademyFilterWithScrollRequest;
import org.guzzing.studayserver.domain.academy.controller.dto.response.*;
import org.guzzing.studayserver.domain.academy.facade.AcademyFacade;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationFacadeResults;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademyDetailFacadeParam;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademyDetailFacadeResult;
import org.guzzing.studayserver.domain.academy.service.AcademyService;
Expand Down Expand Up @@ -69,12 +70,26 @@ public ResponseEntity<AcademyByLocationWithCursorResponses> findByLocationWithCu
@MemberId Long memberId
) {
AcademyByLocationWithCursorResults academiesByLocationWithCursor
= academyService.findAcademiesByLocationWithCursor(request.to(memberId));
= academyService.findAcademiesByLocationWithCursor(request.toAcademyByLocationWithCursorParam(memberId));

return ResponseEntity.status(HttpStatus.OK)
.body(AcademyByLocationWithCursorResponses.from(academiesByLocationWithCursor));
}

@GetMapping(
path = "/complexes-notLike",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<AcademyByLocationWithCursorResponses> findByLocationWithCursorNotLike(
@ModelAttribute @Valid AcademyByLocationWithCursorRequest request,
@MemberId Long memberId
) {
AcademiesByLocationFacadeResults academiesByLocation
= academyFacade.getAcademiesByLocation(request.toAcademiesByLocationFacadeParam(memberId));

return ResponseEntity.status(HttpStatus.OK)
.body(AcademyByLocationWithCursorResponses.from(academiesByLocation));
}

@GetMapping(
path = "/search",
produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationFacadeParam;
import org.guzzing.studayserver.domain.academy.service.dto.param.AcademyByLocationWithCursorParam;
import org.guzzing.studayserver.domain.academy.util.Latitude;
import org.guzzing.studayserver.domain.academy.util.Longitude;
Expand All @@ -20,12 +21,21 @@ public record AcademyByLocationWithCursorRequest(
Long lastAcademyId
) {

public AcademyByLocationWithCursorParam to(Long memberId) {
public AcademyByLocationWithCursorParam toAcademyByLocationWithCursorParam(Long memberId) {
return new AcademyByLocationWithCursorParam(
Latitude.of(lat),
Longitude.of(lng),
memberId,
lastAcademyId
);
}

public AcademiesByLocationFacadeParam toAcademiesByLocationFacadeParam(Long memberId) {
return new AcademiesByLocationFacadeParam(
Latitude.of(lat),
Longitude.of(lng),
memberId,
lastAcademyId
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.guzzing.studayserver.domain.academy.controller.dto.response;

import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationFacadeResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademiesByLocationWithScrollResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyByLocationWithCursorResults;

Expand All @@ -21,6 +22,17 @@ public static AcademyByLocationWithCursorResponses from(AcademyByLocationWithCur
);
}

public static AcademyByLocationWithCursorResponses from(AcademiesByLocationFacadeResults results) {
return new AcademyByLocationWithCursorResponses(
results.academiesByLocationFacadeResults()
.stream()
.map(AcademyByLocationWithCursorResponse::from)
.toList(),
results.lastAcademyId(),
results.hasNext()
);
}

public record AcademyByLocationWithCursorResponse(
Long academyId,
String academyName,
Expand All @@ -47,6 +59,21 @@ public static AcademyByLocationWithCursorResponse from(
result.isLiked()
);
}

public static AcademyByLocationWithCursorResponse from(
AcademiesByLocationFacadeResults.AcademiesByLocationFacadeResult result) {
return new AcademyByLocationWithCursorResponse(
result.academyId(),
result.academyName(),
result.address(),
result.contact(),
result.categories(),
result.latitude(),
result.longitude(),
result.shuttleAvailable(),
result.isLiked()
);
}
}
}

Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package org.guzzing.studayserver.domain.academy.facade;

import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationFacadeParam;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationFacadeResults;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademyDetailFacadeParam;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademyDetailFacadeResult;
import org.guzzing.studayserver.domain.academy.service.AcademyService;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyByLocationWithCursorAndNotLikeResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyGetResult;
import org.guzzing.studayserver.domain.like.service.LikeFacade;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
import java.util.stream.Collectors;

@Service
public class AcademyFacade {

Expand All @@ -27,4 +33,19 @@ public AcademyDetailFacadeResult getDetailAcademy(AcademyDetailFacadeParam param
return AcademyDetailFacadeResult.of(academyGetResult, liked);
}

@Transactional(readOnly = true)
public AcademiesByLocationFacadeResults getAcademiesByLocation(AcademiesByLocationFacadeParam param) {
AcademyByLocationWithCursorAndNotLikeResults academiesByLocationWithCursorAndNotLike
= academyService.findAcademiesByLocationWithCursorAndNotLike(param.toAcademyByLocationWithCursorParam());

Map<Long, Boolean> isLikes = academiesByLocationWithCursorAndNotLike.academiesByLocationResults()
.stream()
.collect(Collectors.toMap(
AcademyByLocationWithCursorAndNotLikeResults.AcademiesByLocationWithCursorAndNotLikeResult::academyId,
result -> likeFacade.isLiked(param.memberId(), result.academyId())
));

return AcademiesByLocationFacadeResults.to(academiesByLocationWithCursorAndNotLike, isLikes);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.guzzing.studayserver.domain.academy.facade.dto;

import org.guzzing.studayserver.domain.academy.service.dto.param.AcademyByLocationWithCursorParam;
import org.guzzing.studayserver.domain.academy.util.Latitude;
import org.guzzing.studayserver.domain.academy.util.Longitude;

public record AcademiesByLocationFacadeParam(
Latitude baseLatitude,
Longitude baseLongitude,
Long memberId,
Long lastAcademyId
) {

public AcademyByLocationWithCursorParam toAcademyByLocationWithCursorParam() {
return new AcademyByLocationWithCursorParam(
baseLatitude,
baseLongitude,
memberId,
lastAcademyId
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.guzzing.studayserver.domain.academy.facade.dto;

import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyByLocationWithCursorAndNotLikeResults;

import java.util.List;
import java.util.Map;

public record AcademiesByLocationFacadeResults(
List<AcademiesByLocationFacadeResult> academiesByLocationFacadeResults,
long lastAcademyId,
boolean hasNext
) {
public static AcademiesByLocationFacadeResults to(
AcademyByLocationWithCursorAndNotLikeResults results,
Map<Long, Boolean> isLikes
) {
return new AcademiesByLocationFacadeResults(
results.academiesByLocationResults()
.stream()
.map(result -> AcademiesByLocationFacadeResult.to(result, isLikes.get(result.academyId())))
.toList(),
results.lastAcademyId(),
results.hasNext()
);
}

public record AcademiesByLocationFacadeResult(
long academyId,
String academyName,
String address,
String contact,
List<String> categories,
double latitude,
double longitude,
String shuttleAvailable,
boolean isLiked
) {
public static AcademiesByLocationFacadeResult to(
AcademyByLocationWithCursorAndNotLikeResults.AcademiesByLocationWithCursorAndNotLikeResult result,
boolean isLiked
) {
return new AcademiesByLocationFacadeResult(
result.academyId(),
result.academyName(),
result.address(),
result.contact(),
result.categories(),
result.latitude(),
result.longitude(),
result.shuttleAvailable(),
isLiked
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jakarta.persistence.EntityNotFoundException;
import org.guzzing.studayserver.domain.academy.model.Academy;
import org.guzzing.studayserver.domain.academy.repository.dto.AcademiesByName;
import org.guzzing.studayserver.domain.academy.repository.dto.response.AcademiesByName;
import org.guzzing.studayserver.domain.academy.repository.dto.AcademyFee;
import org.guzzing.studayserver.global.error.response.ErrorCode;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package org.guzzing.studayserver.domain.academy.repository.academy;

import org.guzzing.studayserver.domain.academy.repository.dto.*;
import org.guzzing.studayserver.domain.academy.repository.dto.request.AcademyByLocationWithCursorRepositoryRequest;
import org.guzzing.studayserver.domain.academy.repository.dto.response.AcademiesByFilterWithScroll;
import org.guzzing.studayserver.domain.academy.repository.dto.response.AcademiesByLocationWithScrollRepositoryResponse;
import org.guzzing.studayserver.domain.academy.repository.dto.response.AcademyByLocationWithCursorNotLikeRepositoryResponse;
import org.guzzing.studayserver.domain.academy.repository.dto.response.AcademyByLocationWithCursorRepositoryResponse;

public interface AcademyQueryRepository {

AcademyByLocationWithCursorRepositoryResponse findAcademiesByLocationByCursor(
AcademyByLocationWithCursorRepositoryRequest request);

AcademiesByLocationWithScroll findAcademiesByLocation(
AcademyByLocationWithCursorNotLikeRepositoryResponse findAcademiesByCursorAndNotLike(
AcademyByLocationWithCursorRepositoryRequest request);

AcademiesByLocationWithScrollRepositoryResponse findAcademiesByLocation(
String pointFormat,
Long memberId,
int pageNumber,
Expand Down
Loading
Loading