feat(user-service): 고객 고유번호 리스트로 고객 가져오기 API 구현
This commit is contained in:
@@ -3,7 +3,10 @@ package com.justpickup.userservice.domain.user.service;
|
||||
import com.justpickup.userservice.domain.user.dto.CustomerDto;
|
||||
import com.justpickup.userservice.domain.user.dto.StoreOwnerDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
CustomerDto findCustomerByUserId(Long userId);
|
||||
void saveStoreOwner(StoreOwnerDto storeOwnerDto);
|
||||
List<CustomerDto> findCustomerByUserIds(List<Long> userIds);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,12 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
|
||||
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
|
||||
@Slf4j
|
||||
public class UserServiceImpl implements UserService, UserDetailsService {
|
||||
|
||||
@@ -64,7 +66,15 @@ public class UserServiceImpl implements UserService, UserDetailsService {
|
||||
StoreOwner storeOwner = new StoreOwner(email, encode, storeOwnerDto.getName(),
|
||||
storeOwnerDto.getPhoneNumber(), storeOwnerDto.getBusinessNumber());
|
||||
|
||||
StoreOwner save = userRepository.save(storeOwner);
|
||||
userRepository.save(storeOwner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomerDto> findCustomerByUserIds(List<Long> userIds) {
|
||||
return customerRepository.findAllById(userIds)
|
||||
.stream()
|
||||
.map(CustomerDto::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -35,6 +37,19 @@ public class UserController {
|
||||
.body(Result.createSuccessResult(getCustomerResponse));
|
||||
}
|
||||
|
||||
@GetMapping("/customers/{userIds}")
|
||||
public ResponseEntity getCustomers(@PathVariable List<Long> userIds) {
|
||||
|
||||
List<CustomerDto> customers = userService.findCustomerByUserIds(userIds);
|
||||
|
||||
List<GetCustomerResponse> responses = customers
|
||||
.stream()
|
||||
.map(GetCustomerResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return ResponseEntity.ok(Result.createSuccessResult(responses));
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor @AllArgsConstructor
|
||||
static class GetCustomerResponse {
|
||||
private Long userId;
|
||||
|
||||
Reference in New Issue
Block a user