Skip to content

Commit

Permalink
#3, #18 [Update] 유저 정보 조회 리팩터링
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 13, 2022
1 parent d2abd7f commit d76d394
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import com.mpnp.baechelin.user.dto.UserInfoResponseDto;
import com.mpnp.baechelin.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -16,11 +20,8 @@ public class UserInfoController {
private final UserInfoService userInfoService;

@GetMapping
// Security 추가 후 변경할 예정
// public ResponseEntity<UserInfoResponseDto> getUserInfo(@AuthenticationPrincipal User user) {
public ResponseEntity<UserInfoResponseDto> getUserInfo(@RequestParam Integer userId) {
log.warn("USERID {} " , userId);
// return new ResponseEntity<>(userInfoService.giveUserInfo(user), HttpStatus.OK);
return new ResponseEntity<>(userInfoService.giveUserInfo(userId), HttpStatus.OK);
@ApiOperation(value = "유저 정보를 반환합니다")
public ResponseEntity<UserInfoResponseDto> getUserInfo(@AuthenticationPrincipal User user) {
return new ResponseEntity<>(userInfoService.giveUserInfo(user.getUsername()), HttpStatus.OK);
}
}
65 changes: 2 additions & 63 deletions src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,72 +16,11 @@
@NoArgsConstructor
@Getter
public class UserInfoResponseDto {
// User info
private String name;
private List<ReviewResponseDto> reviewList;
private List<BookmarkFolderResponseDto> bookmarkFolderList;
private String email;

public UserInfoResponseDto(User user) {
this.name = user.getName();
this.reviewList = user.getReviewList().stream().map(ReviewResponseDto::new).collect(Collectors.toList());
this.bookmarkFolderList = user.getFolderList().stream().map(BookmarkFolderResponseDto::new).collect(Collectors.toList());
//folder

}

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
static class BookmarkFolderResponseDto {
private int userId;
private List<BookmarkResponseDto> folders; // 폴더 여러 개

public BookmarkFolderResponseDto(Folder folder) {
this.userId = folder.getUserId().getId();
this.folders = folder.getBookmarkList().stream().map(BookmarkResponseDto::new).collect(Collectors.toList());
}
this.email = user.getEmail();
}

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
static class BookmarkResponseDto {
private int folderId;
private int storeId;

public BookmarkResponseDto(Bookmark bookmark){
this.folderId = bookmark.getFolderId().getId();
this.storeId = bookmark.getStoreId().getId();
}
}

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
static class ReviewResponseDto {
int id; // storeId
int review; // reviewId
Double point;

String comment;
String reviewImageUrl;


LocalDateTime createdAt;
LocalDateTime modifiedAt;

public ReviewResponseDto(Review review) {
this.id = review.getStoreId().getId();
this.review = review.getId();
this.point = review.getPoint();
this.comment = review.getReview();
this.reviewImageUrl = review.getReviewImageUrl();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
public class UserInfoService {
private final UserRepository userRepository;

// TODO Security 추가 후 변경할 예정
// public UserInfoResponseDto giveUserInfo(User user){
public UserInfoResponseDto giveUserInfo(Integer userId) {
User targetUser = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("test - no user"));
public UserInfoResponseDto giveUserInfo(String socialId) {
User targetUser = userRepository.findBySocialId(socialId);
return new UserInfoResponseDto(targetUser);
// return new UserInfoResponseDto(user);
}
}

0 comments on commit d76d394

Please sign in to comment.