diff --git a/src/main/java/com/example/hicardi/domain/user/controller/UserController.java b/src/main/java/com/example/hicardi/domain/user/controller/UserController.java index 7b438c4..602ddbd 100644 --- a/src/main/java/com/example/hicardi/domain/user/controller/UserController.java +++ b/src/main/java/com/example/hicardi/domain/user/controller/UserController.java @@ -1,19 +1,27 @@ package com.example.hicardi.domain.user.controller; +import com.example.hicardi.domain.product.dto.ProductDto; +import com.example.hicardi.domain.product.entity.Product; import com.example.hicardi.domain.user.dto.LoginRequestDTO; import com.example.hicardi.domain.user.dto.LoginResponseDTO; import com.example.hicardi.domain.user.dto.SignUpRequestDTO; +import com.example.hicardi.domain.user.dto.UserDto; import com.example.hicardi.domain.user.entity.User; import com.example.hicardi.domain.user.service.UserService; +import com.example.hicardi.global.exception.base.BaseResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.modelmapper.ModelMapper; import org.springframework.http.ResponseEntity; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.List; +import java.util.stream.Collectors; + @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/user") @@ -22,7 +30,7 @@ public class UserController { private final UserService userService; - + private final ModelMapper modelMapper; //회원가입 @PostMapping("/sign-up") public ResponseEntity signUpUser(@Validated @RequestBody SignUpRequestDTO dto @@ -71,5 +79,16 @@ public ResponseEntity signIn( return ResponseEntity.badRequest().body(e.getMessage()); } } + @GetMapping("/list") + public BaseResponse> list(){ + + List userList = userService.findByAll(); + //List faqList = faqService.findByKeyword(keyword); + List resultDto = userList.stream() + .map(data-> modelMapper.map(data, UserDto.class)) + .collect(Collectors.toList()); + + return BaseResponse.onSuccess(resultDto); + } } diff --git a/src/main/java/com/example/hicardi/domain/user/dto/UserDto.java b/src/main/java/com/example/hicardi/domain/user/dto/UserDto.java new file mode 100644 index 0000000..a5eaadc --- /dev/null +++ b/src/main/java/com/example/hicardi/domain/user/dto/UserDto.java @@ -0,0 +1,48 @@ +package com.example.hicardi.domain.user.dto; + +import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Data +public class UserDto { + private Long memberId; + + private MEMBERSHIP membershipVerification; + + private BUSINESS businessClassification; + private String loginId; + + private String password; + + private String name; + + private String businessName; + + private String businessNumber; + + + private String address; + + private String landLine; + + + private String phoneNumber; + + + private String email; + + + private GENDER gender; + + private String birthDate; + + + private String ykiho; +} diff --git a/src/main/java/com/example/hicardi/domain/user/entity/User.java b/src/main/java/com/example/hicardi/domain/user/entity/User.java index 9dfa473..d268dcb 100644 --- a/src/main/java/com/example/hicardi/domain/user/entity/User.java +++ b/src/main/java/com/example/hicardi/domain/user/entity/User.java @@ -85,6 +85,6 @@ public class User { @ToString.Exclude @Builder.Default - @OneToMany(mappedBy = "user",cascade = CascadeType.REMOVE) + @OneToMany(mappedBy = "user",cascade = CascadeType.REMOVE, fetch = FetchType.EAGER) private List carts = new ArrayList<>(); } diff --git a/src/main/java/com/example/hicardi/domain/user/service/UserService.java b/src/main/java/com/example/hicardi/domain/user/service/UserService.java index 8ca5f89..07d1ff8 100644 --- a/src/main/java/com/example/hicardi/domain/user/service/UserService.java +++ b/src/main/java/com/example/hicardi/domain/user/service/UserService.java @@ -12,6 +12,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @Slf4j @RequiredArgsConstructor @@ -90,6 +92,8 @@ public User findUserByloginId(String loginId){ public User findUserByMemberId(Long memberId){ return userRepository.findByMemberId(memberId); } + + public List findByAll(){return userRepository.findAll();} }