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 : 지역 이름 검색과 학원 무한 스크롤 쿼리 분리 #144

Merged
merged 7 commits into from
Feb 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import org.guzzing.studayserver.domain.academy.controller.dto.response.AcademyGetResponse;
import org.guzzing.studayserver.domain.academy.controller.dto.response.LessonInfoToCreateDashboardResponses;
import org.guzzing.studayserver.domain.academy.facade.AcademyFacade;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationWithScrollFacadeResult;
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.AcademiesByLocationWithScrollResults;
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.LessonInfoToCreateDashboardResults;
Expand Down Expand Up @@ -60,11 +60,11 @@ public ResponseEntity<AcademiesByLocationWithScrollResponses> findByLocationWith
@ModelAttribute @Valid AcademyByLocationWithScrollRequest request,
@MemberId Long memberId
) {
AcademiesByLocationWithScrollFacadeResult response = academyFacade.findByLocationWithScroll(
AcademyByLocationWithScrollRequest.to(request, memberId));
AcademiesByLocationWithScrollResults academiesByLocationWithScroll =
academyService.findAcademiesByLocationWithScroll(request.to(memberId));

return ResponseEntity.status(HttpStatus.OK)
.body(AcademiesByLocationWithScrollResponses.from(response));
.body(AcademiesByLocationWithScrollResponses.from(academiesByLocationWithScroll));
}

@GetMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationWithScrollFacadeParam;
import org.guzzing.studayserver.domain.academy.service.dto.param.AcademiesByLocationWithScrollParam;

public record AcademyByLocationWithScrollRequest(
@NotNull(message = "Latitude cannot be null")
@DecimalMin(value = "-90", message = "Invalid latitude")
Double lat,
@NotNull(message = "Latitude cannot be null")
@DecimalMin(value = "-90", message = "Invalid latitude")
Double lat,

@NotNull(message = "Longitude cannot be null")
@DecimalMin(value = "-180", message = "Invalid longitude")
Double lng,
@NotNull(message = "Longitude cannot be null")
@DecimalMin(value = "-180", message = "Invalid longitude")
Double lng,

@PositiveOrZero
int pageNumber
@PositiveOrZero
int pageNumber
) {

public static AcademiesByLocationWithScrollFacadeParam to(AcademyByLocationWithScrollRequest request,
Long memberId) {
return new AcademiesByLocationWithScrollFacadeParam(
request.lat,
request.lng,
memberId,
request.pageNumber
public AcademiesByLocationWithScrollParam to(Long memberId) {
return new AcademiesByLocationWithScrollParam(
lat,
lng,
memberId,
pageNumber
);
}
}
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
package org.guzzing.studayserver.domain.academy.controller.dto.response;

import java.util.List;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationWithScrollFacadeResult;

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

public record AcademiesByLocationWithScrollResponses(
List<AcademyByLocationWithScrollResponse> academiesByLocationResponse,
String sido,
String sigungu,
String upmyeondong,
boolean hasNext
List<AcademyByLocationWithScrollResponse> academiesByLocationResponse,
String sido,
String sigungu,
String upmyeondong,
boolean hasNext
) {

public static AcademiesByLocationWithScrollResponses from(
AcademiesByLocationWithScrollFacadeResult academiesByLocationResult) {
AcademiesByLocationWithScrollResults academiesByLocationResult) {
return new AcademiesByLocationWithScrollResponses(
academiesByLocationResult.academiesByLocationResults()
.stream()
.map(AcademyByLocationWithScrollResponse::from)
.toList(),
academiesByLocationResult.sido(),
academiesByLocationResult.sigungu(),
academiesByLocationResult.upmyeondong(),
academiesByLocationResult.hasNext()
academiesByLocationResult.academiesByLocationResults()
.stream()
.map(AcademyByLocationWithScrollResponse::from)
.toList(),
"서울시",
"강남구",
"대치동",
academiesByLocationResult.hasNext()
);
}

public record AcademyByLocationWithScrollResponse(
Long academyId,
String academyName,
String address,
String contact,
List<String> categories,
Double latitude,
Double longitude,
String shuttleAvailable,
boolean isLiked
Long academyId,
String academyName,
String address,
String contact,
List<String> categories,
Double latitude,
Double longitude,
String shuttleAvailable,
boolean isLiked
) {

public static AcademyByLocationWithScrollResponse from(
AcademiesByLocationWithScrollFacadeResult.AcademyByLocationWithScrollFacadeResult result) {
AcademiesByLocationWithScrollResults.AcademiesByLocationResultWithScroll result) {
return new AcademyByLocationWithScrollResponse(
result.academyId(),
result.academyName(),
result.address(),
result.contact(),
result.categories(),
result.latitude(),
result.longitude(),
result.shuttleAvailable(),
result.isLiked()
result.academyId(),
result.academyName(),
result.address(),
result.contact(),
result.categories(),
result.latitude(),
result.longitude(),
result.shuttleAvailable(),
result.isLiked()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,24 @@
package org.guzzing.studayserver.domain.academy.facade;

import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationWithScrollFacadeParam;
import org.guzzing.studayserver.domain.academy.facade.dto.AcademiesByLocationWithScrollFacadeResult;
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.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.LikeFacade;
import org.guzzing.studayserver.domain.region.service.RegionService;
import org.guzzing.studayserver.domain.region.service.dto.location.RegionResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AcademyFacade {

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

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

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

RegionResult regionContainingPoint = regionService.findRegionContainingPoint(
GeometryUtil.createPoint(
param.lat(),
param.lng()));

return AcademiesByLocationWithScrollFacadeResult.from(
academiesByLocationWithScroll,
regionContainingPoint);
}

@Transactional(readOnly = true)
public AcademyDetailFacadeResult getDetailAcademy(AcademyDetailFacadeParam param) {
AcademyGetResult academyGetResult = academyService.getAcademy(param.academyId());
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Positive;
import org.guzzing.studayserver.domain.region.aop.ValidSido;
import org.guzzing.studayserver.domain.region.aop.ValidSigungu;
import org.guzzing.studayserver.domain.region.aop.ValidUpmyeondong;
import org.guzzing.studayserver.domain.region.controller.dto.RegionGetNameRequest;
import org.guzzing.studayserver.domain.region.controller.dto.RegionGetNameResponse;
import org.guzzing.studayserver.domain.region.controller.dto.RegionLocationResponse;
import org.guzzing.studayserver.domain.region.controller.dto.RegionResponse;
import org.guzzing.studayserver.domain.region.service.RegionService;
import org.guzzing.studayserver.domain.region.service.dto.beopjungdong.SidoResult;
import org.guzzing.studayserver.domain.region.service.dto.beopjungdong.SigunguResult;
import org.guzzing.studayserver.domain.region.service.dto.beopjungdong.UpmyeondongResult;
import org.guzzing.studayserver.domain.region.service.dto.location.RegionGetNameResult;
import org.guzzing.studayserver.domain.region.service.dto.location.RegionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(path = "/regions")
Expand Down Expand Up @@ -81,4 +82,18 @@ public ResponseEntity<RegionLocationResponse> getLocation(
.body(RegionLocationResponse.from(regionResult));
}

@GetMapping(
produces = APPLICATION_JSON_VALUE
)
public ResponseEntity<RegionGetNameResponse> getRegionName(
@ModelAttribute @Valid RegionGetNameRequest request
) {
RegionGetNameResult regionContainingPoint = regionService.getRegionName(
request.toRegionGetNameParam());

return ResponseEntity
.status(OK)
.body(RegionGetNameResponse.to(regionContainingPoint));
}

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

import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotNull;
import org.guzzing.studayserver.domain.region.service.dto.location.RegionGetNameParam;

public record RegionGetNameRequest(
@NotNull(message = "Latitude cannot be null")
@DecimalMin(value = "-90", message = "Invalid latitude")
double lat,

@NotNull(message = "Longitude cannot be null")
@DecimalMin(value = "-180", message = "Invalid longitude")
double lng
) {
public RegionGetNameParam toRegionGetNameParam() {
return new RegionGetNameParam(
lat,
lng
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.guzzing.studayserver.domain.region.controller.dto;

import org.guzzing.studayserver.domain.region.service.dto.location.RegionGetNameResult;

public record RegionGetNameResponse(
String sido,
String sigungu,
String upmyeondong
) {
public static RegionGetNameResponse to(RegionGetNameResult result) {
return new RegionGetNameResponse(
result.sido(),
result.sigungu(),
result.upmyeondong()
);
}
}
Loading
Loading