feat(user-service): 고객 고유번호 리스트로 고객 가져오기 API 구현

This commit is contained in:
bum12ark
2022-03-15 16:47:54 +09:00
parent f6c5fd0c8d
commit 44dc5a10ec
3 changed files with 30 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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());
}
}

View File

@@ -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;