Skip to content

Commit

Permalink
Merge pull request #34 from KUSITMS-Team-A/fix/33-find-store
Browse files Browse the repository at this point in the history
[#33] 가게 찾기 조회 스펙 변경
  • Loading branch information
yeop0740 authored Nov 22, 2023
2 parents 9c84543 + b5d485c commit cfacc67
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.backend.domain.store.dto;

import com.backend.domain.store.entity.BusinessHour;
import com.backend.domain.user.dto.RepresentativeDto;
import com.backend.domain.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -14,6 +16,8 @@
@AllArgsConstructor
public class ReadStoreDetailsDto {

private RepresentativeDto user;

private Long storeId;

private String storeName;
Expand All @@ -38,8 +42,9 @@ public class ReadStoreDetailsDto {

private boolean isPicked;

public static ReadStoreDetailsDto from(StoreDetailsDto store, List<BusinessHour> businessHours) {
public static ReadStoreDetailsDto from(StoreDetailsDto store, List<BusinessHour> businessHours, User user) {
return ReadStoreDetailsDto.builder()
.user(RepresentativeDto.from(user))
.storeId(store.getStoreId())
.storeName(store.getStoreName())
.category(store.getCategory().getCategoryName())
Expand All @@ -51,10 +56,14 @@ public static ReadStoreDetailsDto from(StoreDetailsDto store, List<BusinessHour>
.distance(store.getDistance())
.mapUrl(store.getMapUrl())
.isPicked(store.getIsPicked())
.businessHours(businessHours.stream()
.map(BusinessHourDto::from)
.toList())
.businessHours(createBusinessHourDtos(businessHours))
.build();
}

private static List<BusinessHourDto> createBusinessHourDtos(List<BusinessHour> businessHours) {
return businessHours.stream()
.map(BusinessHourDto::from)
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.backend.domain.store.dto;

import com.backend.domain.user.dto.RepresentativeDto;
import com.backend.domain.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -14,6 +16,8 @@
@AllArgsConstructor
public class ReadStoresDto {

private RepresentativeDto user;

private List<StoresDto> stores;

private int pageNumber;
Expand All @@ -22,8 +26,9 @@ public class ReadStoresDto {

private boolean hasNext;

public static ReadStoresDto from(Page<StoresDto> stores) {
public static ReadStoresDto from(Page<StoresDto> stores, User user) {
return ReadStoresDto.builder()
.user(RepresentativeDto.from(user))
.stores(stores.getContent())
.pageNumber(stores.getNumber())
.totalCount(stores.getTotalElements())
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/backend/domain/store/service/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ReadStoreDetailsDto readStoreDetails(LoginUser loginUser, Long storeId) {
User user = userRepository.findByEmail(loginUser.getEmail()).orElseThrow(RuntimeException::new);
StoreDetailsDto storeDetail = storeRepository.findStoreDetailById(user.getId(), storeId, user.getUniversity().getLatitude(), user.getUniversity().getLongitude()).orElseThrow(RuntimeException::new);
List<BusinessHour> businessHours = businessHourRepository.findByStoreStoreId(storeId);
return ReadStoreDetailsDto.from(storeDetail, businessHours);
return ReadStoreDetailsDto.from(storeDetail, businessHours, user);
}

public void createPick(LoginUser loginUser, PickRequest request) {
Expand Down Expand Up @@ -78,17 +78,17 @@ public ReadStoresDto readStores(LoginUser loginUser, ReadRequest request) {
if (request.getIsPicked()) {
if (request.getCategory().equals(Category.NONE)) {
Page<StoresDto> stores = storeRepository.findAllContainsNameAndPicked(user.getId(), university.getLongitude(), university.getLatitude(), keyword, pageRequest);
return ReadStoresDto.from(stores);
return ReadStoresDto.from(stores, user);
}
Page<StoresDto> stores = storeRepository.findAllContainsNameAndPickedAndCategory(user.getId(), university.getLongitude(), university.getLatitude(), keyword, request.getCategory().name(), pageRequest);
return ReadStoresDto.from(stores);
return ReadStoresDto.from(stores, user);
}
if (request.getCategory().equals(Category.NONE)) {
Page<StoresDto> stores = storeRepository.findAllContainsName(user.getId(), university.getLongitude(), university.getLatitude(), keyword, pageRequest);
return ReadStoresDto.from(stores);
return ReadStoresDto.from(stores, user);
}
Page<StoresDto> stores = storeRepository.findAllContainsNameAndCategory(user.getId(), university.getLongitude(), university.getLatitude(), keyword, request.getCategory().name(), pageRequest);
return ReadStoresDto.from(stores);
return ReadStoresDto.from(stores, user);
}

private String getKeyword(ReadRequest request) {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/backend/domain/user/dto/RepresentativeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.backend.domain.user.dto;

import com.backend.domain.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RepresentativeDto {

private Long id;

private String name;

private Double latitude;

private Double longitude;

public static RepresentativeDto from(User user) {
return RepresentativeDto.builder()
.id(user.getId())
.name(user.getTypeName())
.latitude(user.getUniversity().getLatitude())
.longitude(user.getUniversity().getLongitude())
.build();
}

}

0 comments on commit cfacc67

Please sign in to comment.