Skip to content

Commit

Permalink
[fix] add validation condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Aug 20, 2024
1 parent ce12448 commit e3f871d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public HankkiResponse<HeartDeleteResponse> deleteHeartStore(@UserId final Long u

@PostMapping("/stores/validate")
public HankkiResponse<StoreDuplicateValidationResponse> validateDuplicatedStore(@RequestBody final StoreDuplicateValidationRequest request) {
return HankkiResponse.success(CommonSuccessCode.OK, storeQueryService.validateDuplicatedStore(StoreValidationCommand.of(request.universityId(), request.latitude(), request.longitude())));
return HankkiResponse.success(CommonSuccessCode.OK, storeQueryService.validateDuplicatedStore(StoreValidationCommand.of(request.universityId(), request.latitude(), request.longitude(), request.storeName())));
}

@PostMapping("/stores")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public record StoreDuplicateValidationRequest(
long universityId,
double latitude,
double longitude
double longitude,
String storeName
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ protected Store findByIdWithHeartAndIsDeletedFalse(final Long id) {
.orElseThrow(() -> new NotFoundException(StoreErrorCode.STORE_NOT_FOUND));
}

protected Optional<Store> findByLatitudeAndLongitudeWhereIsDeletedFalse(final double latitude, final double longitude) {
return storeRepository.findByPoint_LatitudeAndPoint_LongitudeAndIsDeletedFalse(latitude, longitude);
protected Optional<Store> findByLatitudeAndLongitudeAndNameWhereIsDeletedFalse(final double latitude, final double longitude, String name) {
return storeRepository.findByLatitudeAndLongitudeAndNameWhereIsDeletedFalse(latitude, longitude, name);
}

protected boolean existsByLatitudeAndLongitude(final double latitude, final double longitude) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private boolean hasSameUserId(final Long id, final Heart heart) {

@Transactional(readOnly = true)
public StoreDuplicateValidationResponse validateDuplicatedStore(final StoreValidationCommand command) {
return storeFinder.findByLatitudeAndLongitudeWhereIsDeletedFalse(command.latitude(), command.longitude())
return storeFinder.findByLatitudeAndLongitudeAndNameWhereIsDeletedFalse(command.latitude(), command.longitude(), command.name())
.map(store -> StoreDuplicateValidationResponse.of(store.getId(), universityStoreFinder.existsByUniversityIdAndStore(command.universityId(), store)))
.orElseGet(() -> StoreDuplicateValidationResponse.of(null, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
public record StoreValidationCommand (
long universityId,
double latitude,
double longitude
double longitude,
String name
) {
public static StoreValidationCommand of(long universityId, double latitude, double longitude) {
return new StoreValidationCommand(universityId, latitude, longitude);
public static StoreValidationCommand of(long universityId, double latitude, double longitude, String name) {
return new StoreValidationCommand(universityId, latitude, longitude, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public interface StoreRepository extends JpaRepository<Store, Long>, CustomStore
@Query("select distinct s from Store s left join fetch s.hearts where s.id = :id and s.isDeleted = false")
Optional<Store> findByIdWithHeartAndIsDeletedFalse(Long id);

@Query("select s from Store s where s.point.latitude = :latitude and s.point.longitude = :longitude and s.isDeleted = false")
Optional<Store> findByPoint_LatitudeAndPoint_LongitudeAndIsDeletedFalse(double latitude, double longitude);
@Query("select s from Store s where s.point.latitude = :latitude and s.point.longitude = :longitude and s.name = :name and s.isDeleted = false")
Optional<Store> findByLatitudeAndLongitudeAndNameWhereIsDeletedFalse(double latitude, double longitude, String name);

boolean existsByPoint_LatitudeAndPoint_Longitude(double latitude, double longitude);

Expand Down

0 comments on commit e3f871d

Please sign in to comment.