Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fest] user 조회 #33

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -71,5 +79,16 @@ public ResponseEntity<?> signIn(
return ResponseEntity.badRequest().body(e.getMessage());
}
}
@GetMapping("/list")
public BaseResponse<List<UserDto>> list(){

List<User> userList = userService.findByAll();
//List<Faq> faqList = faqService.findByKeyword(keyword);
List<UserDto> resultDto = userList.stream()
.map(data-> modelMapper.map(data, UserDto.class))
.collect(Collectors.toList());

return BaseResponse.onSuccess(resultDto);
}

}
48 changes: 48 additions & 0 deletions src/main/java/com/example/hicardi/domain/user/dto/UserDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cart> carts = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -90,6 +92,8 @@ public User findUserByloginId(String loginId){
public User findUserByMemberId(Long memberId){
return userRepository.findByMemberId(memberId);
}

public List<User> findByAll(){return userRepository.findAll();}
}