Skip to content

Commit

Permalink
[FIX] #48 유저 정보 조회 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYJH committed Nov 30, 2022
1 parent 284d3c3 commit 484a8dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.plantity.server.controller;

import com.plantity.server.config.BaseResponse2;
import com.plantity.server.domain.myPlant.MyPlantResponseDto;
import com.plantity.server.domain.users.UserDto;
import com.plantity.server.domain.users.Users;
import com.plantity.server.domain.users.UsersRequestDto;
import com.plantity.server.domain.users.UsersResponseDto;
import com.plantity.server.dto.res.users.UserResponse;
import com.plantity.server.repository.MyPlantRepository;
import com.plantity.server.repository.UsersRepository;
import com.plantity.server.service.UsersService;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,6 +22,7 @@
@RequiredArgsConstructor
public class UsersController {
private final UsersRepository userRepository;
private final MyPlantRepository myPlantRepository;
private final UsersService userService;

// user 목록 조회
Expand All @@ -29,9 +33,11 @@ public List<Users> getUsers(){

// user 상세 정보 조회
@GetMapping("/users/{userId}")
public BaseResponse2<UsersResponseDto> getUser(@PathVariable Long userId) {
UsersResponseDto usersResponseDto = UsersResponseDto.from(userRepository.findByUserId(userId));
return new BaseResponse2<>(usersResponseDto);
public BaseResponse2<UserDto> getUser(@PathVariable Long userId) {
UsersResponseDto usersResponseDto = UsersResponseDto.from(userRepository.findByUserId(userId)); // 유저 정보
List<MyPlantResponseDto> myPlantResponseDtos = myPlantRepository.findAllByUserIdx(userId); // 내 식물 리스트

return new BaseResponse2<>(new UserDto(usersResponseDto, myPlantResponseDtos));
}

// 임시로 User 추가하기
Expand Down
26 changes: 26 additions & 0 deletions server/src/main/java/com/plantity/server/domain/users/UserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.plantity.server.domain.users;

import com.plantity.server.domain.myPlant.MyPlantResponseDto;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
public class UserDto {

private UsersResponseDto responseDto;
private List<MyPlantResponseDto> myPlantResponseDtos;

public UserDto(UsersResponseDto responseDto, List<MyPlantResponseDto> myPlantResponseDtos){
this.responseDto = responseDto;
this.myPlantResponseDtos = myPlantResponseDtos;
}

public UserDto from (UsersResponseDto responseDto, List<MyPlantResponseDto> myPlantResponseDtos){
return new UserDto(responseDto, myPlantResponseDtos);
}
}


0 comments on commit 484a8dc

Please sign in to comment.