Skip to content

Commit

Permalink
feat : 학원 목록 조회 2차 캐시 및 좋아요 분리 컨트롤러 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
byeolhaha committed Feb 23, 2024
1 parent 80c648d commit 35633fb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
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()
);
}
}
}

0 comments on commit 35633fb

Please sign in to comment.