feat(store): 매장 고유번호들로 매장 리스트 가져오기
This commit is contained in:
@@ -1,21 +1,30 @@
|
|||||||
package com.justpickup.storeservice.domain.store.dto;
|
package com.justpickup.storeservice.domain.store.dto;
|
||||||
|
|
||||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AccessLevel;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
@Builder
|
|
||||||
public class StoreDto {
|
public class StoreDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
|
|
||||||
public StoreDto(Store store) {
|
@Builder
|
||||||
this.id = store.getId();
|
public StoreDto(Long id, String name, String phoneNumber) {
|
||||||
this.name = store.getName();
|
this.id = id;
|
||||||
this.phoneNumber = store.getPhoneNumber();
|
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);
|
List<SearchStoreResult> findFavoriteStore(SearchStoreCondition condition, Long userId);
|
||||||
StoreDto findStoreById(Long storeId);
|
StoreDto findStoreById(Long storeId);
|
||||||
StoreByUserIdDto findStoreByUserId(Long userId);
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -52,7 +53,7 @@ public class StoreServiceImpl implements StoreService {
|
|||||||
Store store = storeRepository.findById(storeId)
|
Store store = storeRepository.findById(storeId)
|
||||||
.orElseThrow(() -> new NotExistStoreException(storeId + "는 없는 매장 고유번호입니다."));
|
.orElseThrow(() -> new NotExistStoreException(storeId + "는 없는 매장 고유번호입니다."));
|
||||||
|
|
||||||
return new StoreDto(store);
|
return StoreDto.of(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,4 +63,12 @@ public class StoreServiceImpl implements StoreService {
|
|||||||
|
|
||||||
return StoreByUserIdDto.of(store);
|
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.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/store")
|
|
||||||
public class StoreController {
|
public class StoreController {
|
||||||
|
|
||||||
private final StoreService storeService;
|
private final StoreService storeService;
|
||||||
|
|
||||||
@GetMapping("/{storeId}")
|
@GetMapping("/store/{storeId}")
|
||||||
public ResponseEntity<Result> getStore(@PathVariable("storeId") Long storeId) {
|
public ResponseEntity<Result> getStore(@PathVariable("storeId") Long storeId) {
|
||||||
StoreDto storeDto = storeService.findStoreById(storeId);
|
StoreDto storeDto = storeService.findStoreById(storeId);
|
||||||
|
|
||||||
@@ -39,4 +40,16 @@ public class StoreController {
|
|||||||
this.phoneNumber = storeDto.getPhoneNumber();
|
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