feat(store): 매장 고유번호들로 매장 리스트 가져오기
This commit is contained in:
@@ -1,21 +1,30 @@
|
||||
package com.justpickup.storeservice.domain.store.dto;
|
||||
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class StoreDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String phoneNumber;
|
||||
|
||||
public StoreDto(Store store) {
|
||||
this.id = store.getId();
|
||||
this.name = store.getName();
|
||||
this.phoneNumber = store.getPhoneNumber();
|
||||
@Builder
|
||||
public StoreDto(Long id, String name, String phoneNumber) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
public static StoreDto of(Store store) {
|
||||
StoreDto storeDto = new StoreDto();
|
||||
storeDto.id = store.getId();
|
||||
storeDto.name = store.getName();
|
||||
storeDto.phoneNumber = store.getPhoneNumber();
|
||||
return storeDto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ public interface StoreService {
|
||||
List<SearchStoreResult> findFavoriteStore(SearchStoreCondition condition, Long userId);
|
||||
StoreDto findStoreById(Long storeId);
|
||||
StoreByUserIdDto findStoreByUserId(Long userId);
|
||||
List<StoreDto> findStoreAllById(Iterable<Long> storeIds);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.data.domain.SliceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -52,7 +53,7 @@ public class StoreServiceImpl implements StoreService {
|
||||
Store store = storeRepository.findById(storeId)
|
||||
.orElseThrow(() -> new NotExistStoreException(storeId + "는 없는 매장 고유번호입니다."));
|
||||
|
||||
return new StoreDto(store);
|
||||
return StoreDto.of(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,4 +63,12 @@ public class StoreServiceImpl implements StoreService {
|
||||
|
||||
return StoreByUserIdDto.of(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StoreDto> findStoreAllById(Iterable<Long> storeIds) {
|
||||
return storeRepository.findAllById(storeIds)
|
||||
.stream()
|
||||
.map(StoreDto::of)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,18 @@ import lombok.RequiredArgsConstructor;
|
||||
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.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/store")
|
||||
public class StoreController {
|
||||
|
||||
private final StoreService storeService;
|
||||
|
||||
@GetMapping("/{storeId}")
|
||||
@GetMapping("/store/{storeId}")
|
||||
public ResponseEntity<Result> getStore(@PathVariable("storeId") Long storeId) {
|
||||
StoreDto storeDto = storeService.findStoreById(storeId);
|
||||
|
||||
@@ -39,4 +40,16 @@ public class StoreController {
|
||||
this.phoneNumber = storeDto.getPhoneNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/stores/{storeIds}")
|
||||
public ResponseEntity<Result> getStores(@PathVariable("storeIds") List<Long> storeIds) {
|
||||
|
||||
List<StoreDto> storeDtoList = storeService.findStoreAllById(storeIds);
|
||||
|
||||
List<GetStoreResponse> responses = storeDtoList.stream()
|
||||
.map(GetStoreResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return ResponseEntity.ok(Result.createSuccessResult(responses));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user