Skip to content

Commit

Permalink
Merge pull request #33 from Guzzing/academies
Browse files Browse the repository at this point in the history
[학원] 학원 검색 필터 구현 및 학원 목록에서 사용자가 좋아요를 한 학원인지의 여부 추가
  • Loading branch information
byeolhaha authored Nov 9, 2023
2 parents 6a91e33 + 6e55616 commit 99aad7a
Show file tree
Hide file tree
Showing 64 changed files with 800 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML_CONTENT }}" > src/main/resources/application.yml
echo "${{ secrets.APPLICATION_COMMERCIAL_YML_CONTENT }}" > src/main/resources/application-commercial.yml
echo "${{ secrets.APPLICATION_PROD_YML_CONTENT }}" > src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_DEV_YML_CONTENT }}" > src/main/resources/application-dev.yml
echo "${{ secrets.APPLICATION_OAUTH_YML_CONTENT }}" > src/main/resources/application-oauth.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/develop-cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML_CONTENT }}" > src/main/resources/application.yml
echo "${{ secrets.APPLICATION_COMMERCIAL_YML_CONTENT }}" > src/main/resources/application-commercial.yml
echo "${{ secrets.APPLICATION_PROD_YML_CONTENT }}" > src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_DEV_YML_CONTENT }}" > src/main/resources/application-dev.yml
echo "${{ secrets.APPLICATION_OAUTH_YML_CONTENT }}" > src/main/resources/application-oauth.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import jakarta.validation.Valid;
import org.guzzing.studayserver.domain.academy.controller.dto.request.AcademiesByLocationRequest;
import org.guzzing.studayserver.domain.academy.controller.dto.request.AcademiesByNameRequest;
import org.guzzing.studayserver.domain.academy.controller.dto.request.AcademyFilterRequest;
import org.guzzing.studayserver.domain.academy.controller.dto.response.AcademiesByLocationResponses;
import org.guzzing.studayserver.domain.academy.controller.dto.response.AcademiesByNameResponses;
import org.guzzing.studayserver.domain.academy.controller.dto.response.AcademyFilterResponses;
import org.guzzing.studayserver.domain.academy.controller.dto.response.AcademyGetResponse;
import org.guzzing.studayserver.domain.academy.service.AcademyService;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademiesByLocationResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademiesByNameResults;
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademyFilterResults;
import org.guzzing.studayserver.domain.auth.memberId.MemberId;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -31,18 +35,23 @@ public AcademyController(AcademyService academyService) {
@GetMapping(
path = "/{academyId}",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<AcademyGetResponse> getAcademy(@PathVariable Long academyId) {
public ResponseEntity<AcademyGetResponse> getAcademy(
@PathVariable Long academyId,
@MemberId Long memberId
) {
return ResponseEntity.status(HttpStatus.OK)
.body(AcademyGetResponse.from(academyService.getAcademy(academyId)));
.body(AcademyGetResponse.from(academyService.getAcademy(academyId, memberId)));
}

@GetMapping(
path = "/complexes",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<AcademiesByLocationResponses> findByLocation(
@ModelAttribute @Valid AcademiesByLocationRequest request) {
@ModelAttribute @Valid AcademiesByLocationRequest request,
@MemberId Long memberId
) {
AcademiesByLocationResults academiesByLocation =
academyService.findAcademiesByLocation(AcademiesByLocationRequest.to(request));
academyService.findAcademiesByLocation(AcademiesByLocationRequest.to(request), memberId);

return ResponseEntity.status(HttpStatus.OK)
.body(AcademiesByLocationResponses.from(academiesByLocation));
Expand All @@ -51,12 +60,27 @@ public ResponseEntity<AcademiesByLocationResponses> findByLocation(
@GetMapping(
path = "/search",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<AcademiesByNameResponses> findByName(@ModelAttribute @Valid AcademiesByNameRequest request) {
public ResponseEntity<AcademiesByNameResponses> findByName(
@ModelAttribute @Valid AcademiesByNameRequest request
) {
AcademiesByNameResults academiesByNameResults = academyService.findAcademiesByName(
AcademiesByNameRequest.to(request));

return ResponseEntity.status(HttpStatus.OK)
.body(AcademiesByNameResponses.from(academiesByNameResults));
}

@GetMapping(
path = "/filter",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<AcademyFilterResponses> filterAcademies(
@ModelAttribute @Valid AcademyFilterRequest request,
@MemberId Long memberId
) {
AcademyFilterResults academyFilterResults = academyService.filterAcademies(
AcademyFilterRequest.to(request), memberId);

return ResponseEntity.status(HttpStatus.OK)
.body(AcademyFilterResponses.from(academyFilterResults));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.guzzing.studayserver.domain.academy.controller.dto.request;

import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import org.guzzing.studayserver.domain.academy.controller.dto.validation.ValidAreaOfExpertise;
import org.guzzing.studayserver.domain.academy.service.dto.param.AcademyFilterParam;

import java.util.List;

public record AcademyFilterRequest(
@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,


@ValidAreaOfExpertise
List<String> areaOfExpertises,

@Positive
Long desiredMinAmount,

@Positive
Long desiredMaxAmount
){
public static AcademyFilterParam to(AcademyFilterRequest request) {
return new AcademyFilterParam (
request.lat,
request.lng,
request.areaOfExpertises(),
request.desiredMinAmount,
request.desiredMaxAmount
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ public record AcademiesByLocationResponse(
String contact,
String areaOfExpertise,
Double latitude,
Double longitude
Double longitude,
String shuttleAvailable,
boolean isLiked
) {

public static AcademiesByLocationResponse from(AcademiesByLocationResult academiesByLocationResult) {
return new AcademiesByLocationResponse(
academiesByLocationResult.academyId(),
Expand All @@ -20,7 +21,9 @@ public static AcademiesByLocationResponse from(AcademiesByLocationResult academi
academiesByLocationResult.contact(),
academiesByLocationResult.areaOfExpertise(),
academiesByLocationResult.latitude(),
academiesByLocationResult.longitude()
academiesByLocationResult.longitude(),
academiesByLocationResult.shuttleAvailable(),
academiesByLocationResult.isLiked()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.guzzing.studayserver.domain.academy.controller.dto.response;

import java.util.List;

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

public record AcademiesByLocationResponses(
Expand All @@ -15,5 +16,4 @@ public static AcademiesByLocationResponses from(AcademiesByLocationResults acade
.toList()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public record AcademiesByNameResponse(
Double latitude,
Double longitude
) {

public static AcademiesByNameResponse from(AcademiesByNameResult academiesByNameResult) {
return new AcademiesByNameResponse(
academiesByNameResult.academyId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import org.guzzing.studayserver.domain.academy.service.dto.result.AcademiesByNameResults;
import org.springframework.data.domain.Slice;


public record AcademiesByNameResponses(
Slice<AcademiesByNameResponse> academiesByNameResponses
) {

public static AcademiesByNameResponses from(AcademiesByNameResults academiesByNameResults) {
return new AcademiesByNameResponses(
academiesByNameResults.academiesByNameResults()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.guzzing.studayserver.domain.academy.controller.dto.response;

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

public record AcademyFilterResponse(
Long academyId,
String academyName,
String fullAddress,
String contact,
String areaOfExpertise,
Double latitude,
Double longitude,
String shuttleAvailable,
boolean isLiked
) {
public static AcademyFilterResponse from(AcademyFilterResult academyFilterResult) {
return new AcademyFilterResponse(
academyFilterResult.academyId(),
academyFilterResult.academyName(),
academyFilterResult.fullAddress(),
academyFilterResult.contact(),
academyFilterResult.areaOfExpertise(),
academyFilterResult.latitude(),
academyFilterResult.longitude(),
academyFilterResult.shuttleAvailable(),
academyFilterResult.isLiked()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.guzzing.studayserver.domain.academy.controller.dto.response;

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

import java.util.List;

public record AcademyFilterResponses(
List<AcademyFilterResponse> academyFilterResponses
) {
public static AcademyFilterResponses from(AcademyFilterResults academyFilterResults) {
return new AcademyFilterResponses(
academyFilterResults.academyFilterResults()
.stream()
.map(academyFilterResult -> AcademyFilterResponse.from(academyFilterResult))
.toList()
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public record AcademyGetResponse(
String updatedDate,
String areaOfExpertise,
LessonGetResponses lessonGetResponses,
ReviewPercentGetResponse reviewPercentGetResponse
ReviewPercentGetResponse reviewPercentGetResponse,
boolean isLiked
) {

public static AcademyGetResponse from(AcademyGetResult academyGetResult) {
return new AcademyGetResponse(
academyGetResult.academyName(),
Expand All @@ -25,7 +25,8 @@ public static AcademyGetResponse from(AcademyGetResult academyGetResult) {
academyGetResult.areaOfExpertise(),

LessonGetResponses.from(academyGetResult.lessonGetResults()),
ReviewPercentGetResponse.from(academyGetResult.reviewPercentGetResult())
ReviewPercentGetResponse.from(academyGetResult.reviewPercentGetResult()),
academyGetResult.isLiked()
);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public record LessonGetResponse(
String duration,
Long totalFee
) {

public static LessonGetResponse from(LessonGetResult lesson) {
return new LessonGetResponse(
lesson.lessonId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.guzzing.studayserver.domain.academy.controller.dto.response;

import java.util.List;

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

public record LessonGetResponses(
List<LessonGetResponse> lessons
) {

public static LessonGetResponses from(LessonGetResults lessonGetResults) {
return new LessonGetResponses(
lessonGetResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public record ReviewPercentGetResponse(
int goodManagementPercent,
int lovelyTeachingPercent
) {

public static ReviewPercentGetResponse from(ReviewPercentGetResult response) {
return new ReviewPercentGetResponse(
response.kindnessPercent(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.guzzing.studayserver.domain.academy.controller.dto.validation;

public enum AreaOfExpertise {

FOREIGN_LANGUAGE("국제화"),
DANCE("기예(대)"),
ETC("기타(대)"),
READING_ROOM("독서실"),
ART_AND_MUSIC("예능(대)"),
HUMANITIES_AND_HISTORY("인문사회(대)"),
TUTORING_SCHOOL("입시.검정 및 보습"),
COMPREHENSIVE("종합(대)");

private String kind;

AreaOfExpertise(String kind) {
this.kind = kind;
}

public String getAreaOfExpertise() {
return kind;
}

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

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = ValidAreaOfExpertiseValidator.class)
public @interface ValidAreaOfExpertise {
String message() default "유효하지 않은 학원 분야입니다.";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.guzzing.studayserver.domain.academy.controller.dto.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.Arrays;
import java.util.List;

public class ValidAreaOfExpertiseValidator implements ConstraintValidator<ValidAreaOfExpertise, List<String>> {

@Override
public void initialize(ValidAreaOfExpertise constraintAnnotation) {
}

@Override
public boolean isValid(List<String> value, ConstraintValidatorContext context) {
if (value == null || value.isEmpty()) {
return false;
}

for (String areaOfExpertise : value) {
if (!isValidAreaOfExpertise(areaOfExpertise)) {
return false;
}
}

return true;
}

private boolean isValidAreaOfExpertise(String areaOfExpertise) {
return Arrays.stream(AreaOfExpertise.values())
.anyMatch(enumValue -> enumValue.getAreaOfExpertise().equals(areaOfExpertise));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import java.util.Objects;

import lombok.Getter;
import org.guzzing.studayserver.domain.academy.model.vo.Address;
import org.guzzing.studayserver.domain.academy.model.vo.Location;
Expand Down Expand Up @@ -68,7 +70,7 @@ public String getAcademyName() {
}

public String getContact() {
return academyInfo.getContact();
return academyInfo.getPhoneNumber();
}

public String getShuttleAvailability() {
Expand Down Expand Up @@ -101,4 +103,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(id, academyInfo, fullAddress, location, maxEducationFee, point);
}
}
}
Loading

0 comments on commit 99aad7a

Please sign in to comment.