From 0e80f5e5db7ab35834eeaf8b764ac432496aedcb Mon Sep 17 00:00:00 2001 From: abi-hong <68041042+abi-hong@users.noreply.github.com> Date: Sun, 11 Sep 2022 17:07:42 -0400 Subject: [PATCH 1/3] [feat] #21 - not start yet - want to change branch --- .../java/com/plantity/server/repository/PlantLogRepository.java | 2 -- .../main/java/com/plantity/server/service/MyPlantService.java | 1 + server/src/main/resources/application.properties | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/plantity/server/repository/PlantLogRepository.java b/server/src/main/java/com/plantity/server/repository/PlantLogRepository.java index 9be64d6..f9e833e 100644 --- a/server/src/main/java/com/plantity/server/repository/PlantLogRepository.java +++ b/server/src/main/java/com/plantity/server/repository/PlantLogRepository.java @@ -4,6 +4,4 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface PlantLogRepository extends JpaRepository { - - } diff --git a/server/src/main/java/com/plantity/server/service/MyPlantService.java b/server/src/main/java/com/plantity/server/service/MyPlantService.java index c4dc757..56a9668 100644 --- a/server/src/main/java/com/plantity/server/service/MyPlantService.java +++ b/server/src/main/java/com/plantity/server/service/MyPlantService.java @@ -3,6 +3,7 @@ import com.plantity.server.domain.myPlant.MyPlant; import com.plantity.server.domain.myPlant.MyPlantSaveRequestDto; import com.plantity.server.domain.plantlog.PlantLog; +import com.plantity.server.domain.plantlog.PlantLogSaveRequestDto; import com.plantity.server.repository.MyPlantRepository; import com.plantity.server.repository.PlantLogRepository; import lombok.RequiredArgsConstructor; diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index 3a26719..a5bbd59 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -6,5 +6,5 @@ spring.jpa.hibernate.ddl-auto=create #spring.jpa.properties.hibernate.globally_quoted_identifiers=true #port change -server.port=8085 +server.port=8086 From cc28b50d472c946b5086a60b40d0b00f646ab1b0 Mon Sep 17 00:00:00 2001 From: abi-hong <68041042+abi-hong@users.noreply.github.com> Date: Mon, 12 Sep 2022 13:57:02 -0400 Subject: [PATCH 2/3] =?UTF-8?q?[feat]=20#21=20-=20mypage=20=EB=82=B4=20?= =?UTF-8?q?=EC=8B=9D=EB=AC=BC=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=B0=9B?= =?UTF-8?q?=EC=95=84=EC=98=A4=EB=8A=94=20api=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?=EC=A4=91=20-=20IllegalStateException=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plantity/server/controller/MyPlantApiController.java | 8 +++++--- server/src/main/resources/application.properties | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java index 1cd2ccb..114fc92 100644 --- a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java +++ b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java @@ -99,8 +99,10 @@ public ResponseEntity putLook(@PathVariable Long userId, return MyPlantUpdateResponse.newResponse(UPDATE_LOOKPLANTLOG_SUCCESS); } - @GetMapping("/plant") - public List check(){ - return plantLogRepository.findAll(); + // 오류 해결 - https://velog.io/@youns1121/JPA-java.lang.IllegalStateException-Cannot-call-sendError-after-the-response-has-been-committed + @GetMapping("/plant/{userId}") + public List check(@PathVariable Long userId) { + usersRepository.findByUserId(userId); + return myPlantRepository.findAll(); } } diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index f830a6a..1083c31 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -6,7 +6,7 @@ spring.jpa.hibernate.ddl-auto=create #spring.jpa.properties.hibernate.globally_quoted_identifiers=true #port change -#server.port=8085 +server.port=8085 cloud.aws.stack.auto=false From 5cc701d2f3b15892466b1ed839d50eb76af8fde1 Mon Sep 17 00:00:00 2001 From: abi-hong <68041042+abi-hong@users.noreply.github.com> Date: Mon, 12 Sep 2022 19:34:14 -0400 Subject: [PATCH 3/3] =?UTF-8?q?[feat]=20#21=20-=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=99=84=EB=A3=8C=20-=20postman=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/constants/SuccessCode.java | 4 ++- .../controller/MyPlantApiController.java | 1 - .../server/controller/UsersController.java | 21 +++++++++++++--- .../server/domain/myPlant/MyPlant.java | 2 ++ .../plantity/server/domain/users/Users.java | 2 ++ .../server/domain/users/UsersRequestDto.java | 18 +++++++------ .../server/domain/users/UsersResponseDto.java | 23 +++++++++++++++++ .../server/dto/res/users/UserResponse.java | 25 +++++++++++++++++++ .../plantity/server/service/UsersService.java | 10 ++++++++ 9 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 server/src/main/java/com/plantity/server/domain/users/UsersResponseDto.java create mode 100644 server/src/main/java/com/plantity/server/dto/res/users/UserResponse.java diff --git a/server/src/main/java/com/plantity/server/constants/SuccessCode.java b/server/src/main/java/com/plantity/server/constants/SuccessCode.java index 87804d6..6684a3a 100644 --- a/server/src/main/java/com/plantity/server/constants/SuccessCode.java +++ b/server/src/main/java/com/plantity/server/constants/SuccessCode.java @@ -14,7 +14,9 @@ public enum SuccessCode { UPDATE_SUNPLANTLOG_SUCCESS(OK, "광합성 로그 등록하기를 성공했습니다."), UPDATE_REPOTPLANTLOG_SUCCESS(OK, "분갈이 로그 등록하기를 성공했습니다."), UPDATE_WATERPLANTLOG_SUCCESS(OK, "물주기 로그 등록하기를 성공했습니다."), - UPDATE_LOOKPLANTLOG_SUCCESS(OK, "관찰 로그 등록하기를 성공했습니다."); + UPDATE_LOOKPLANTLOG_SUCCESS(OK, "관찰 로그 등록하기를 성공했습니다."), + + USER_INFO_SUCCESS(OK, "유저 프로필 상세 조회를 성공했습니다."); private final HttpStatus status; private final String msg; diff --git a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java index 114fc92..f9b3620 100644 --- a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java +++ b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java @@ -99,7 +99,6 @@ public ResponseEntity putLook(@PathVariable Long userId, return MyPlantUpdateResponse.newResponse(UPDATE_LOOKPLANTLOG_SUCCESS); } - // 오류 해결 - https://velog.io/@youns1121/JPA-java.lang.IllegalStateException-Cannot-call-sendError-after-the-response-has-been-committed @GetMapping("/plant/{userId}") public List check(@PathVariable Long userId) { usersRepository.findByUserId(userId); diff --git a/server/src/main/java/com/plantity/server/controller/UsersController.java b/server/src/main/java/com/plantity/server/controller/UsersController.java index b40c424..8ba8d43 100644 --- a/server/src/main/java/com/plantity/server/controller/UsersController.java +++ b/server/src/main/java/com/plantity/server/controller/UsersController.java @@ -3,16 +3,18 @@ import com.plantity.server.config.BaseResponse2; 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.UsersRepository; import com.plantity.server.service.UsersService; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; import java.util.List; +import static com.plantity.server.constants.SuccessCode.USER_INFO_SUCCESS; + @RestController @RequiredArgsConstructor public class UsersController { @@ -25,6 +27,17 @@ public List getUsers(){ return userRepository.findAll(); } + // user 상세 정보 조회 + @GetMapping("/users/{userId}") + public ResponseEntity getUser(@PathVariable Long userId) { + + UsersRequestDto usersRequestDto = UsersRequestDto.of(userId); + + UsersResponseDto usersResponseDto = userService.userInfo(usersRequestDto); + + return UserResponse.newResponse(USER_INFO_SUCCESS, usersResponseDto); + } + // 임시로 User 추가하기 @PostMapping("/save/test/users") public BaseResponse2 postTestUsers(@RequestBody UsersRequestDto usersRequestDto){ diff --git a/server/src/main/java/com/plantity/server/domain/myPlant/MyPlant.java b/server/src/main/java/com/plantity/server/domain/myPlant/MyPlant.java index dfab943..a2efae3 100644 --- a/server/src/main/java/com/plantity/server/domain/myPlant/MyPlant.java +++ b/server/src/main/java/com/plantity/server/domain/myPlant/MyPlant.java @@ -1,6 +1,8 @@ package com.plantity.server.domain.myPlant; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonManagedReference; import com.plantity.server.domain.BaseTimeEntity; import com.plantity.server.domain.plantlog.PlantLog; import com.plantity.server.domain.users.Users; diff --git a/server/src/main/java/com/plantity/server/domain/users/Users.java b/server/src/main/java/com/plantity/server/domain/users/Users.java index 891ef20..65a55a8 100644 --- a/server/src/main/java/com/plantity/server/domain/users/Users.java +++ b/server/src/main/java/com/plantity/server/domain/users/Users.java @@ -1,6 +1,8 @@ package com.plantity.server.domain.users; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.plantity.server.domain.BaseTimeEntity; import com.plantity.server.domain.myPlant.MyPlant; import com.plantity.server.domain.plantFollowing.PlantFollowing; diff --git a/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java b/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java index b5b7677..901e593 100644 --- a/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java +++ b/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java @@ -8,19 +8,21 @@ @Setter @RequiredArgsConstructor public class UsersRequestDto { + + private Long userId; private String nickName; - //private String social; private String rating; private int score; - //private String status; - public UsersRequestDto(String nickName, String social, String rating, int score, String status){ - this.nickName = nickName; - //this.social = social; - this.rating = rating; - this.score = score; - //this.status = status; + private UsersRequestDto(Long userId){ + this.userId = userId; + //this.nickName = nickName; + //this.rating = rating; + //this.score = score; + } + public static UsersRequestDto of(Long userId) { + return new UsersRequestDto(userId); } } diff --git a/server/src/main/java/com/plantity/server/domain/users/UsersResponseDto.java b/server/src/main/java/com/plantity/server/domain/users/UsersResponseDto.java new file mode 100644 index 0000000..8504309 --- /dev/null +++ b/server/src/main/java/com/plantity/server/domain/users/UsersResponseDto.java @@ -0,0 +1,23 @@ +package com.plantity.server.domain.users; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class UsersResponseDto { + + private String nickName; + private String rating; + private int score; + + private UsersResponseDto(Users users) { + this.nickName = users.getNickName(); + this.rating = users.getRating(); + this.score = users.getScore(); + } + + public static UsersResponseDto from(Users users) { + return new UsersResponseDto(users); + } +} diff --git a/server/src/main/java/com/plantity/server/dto/res/users/UserResponse.java b/server/src/main/java/com/plantity/server/dto/res/users/UserResponse.java new file mode 100644 index 0000000..ce6e846 --- /dev/null +++ b/server/src/main/java/com/plantity/server/dto/res/users/UserResponse.java @@ -0,0 +1,25 @@ +package com.plantity.server.dto.res.users; + +import com.plantity.server.constants.SuccessCode; +import com.plantity.server.domain.users.UsersResponseDto; +import com.plantity.server.dto.BaseResponse; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.http.ResponseEntity; + +@Getter +@NoArgsConstructor +public class UserResponse extends BaseResponse { + + private UsersResponseDto data; + + private UserResponse(Boolean success, String msg, UsersResponseDto data) { + super(success, msg); + this.data = data; + } + + public static ResponseEntity newResponse(SuccessCode code, UsersResponseDto data) { + UserResponse response = new UserResponse(true, code.getMsg(), data); + return new ResponseEntity(response, code.getStatus()); + } +} diff --git a/server/src/main/java/com/plantity/server/service/UsersService.java b/server/src/main/java/com/plantity/server/service/UsersService.java index ca8ea47..8134223 100644 --- a/server/src/main/java/com/plantity/server/service/UsersService.java +++ b/server/src/main/java/com/plantity/server/service/UsersService.java @@ -2,6 +2,7 @@ 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.repository.UsersRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -24,4 +25,13 @@ public Long updateUser(Long id, UsersRequestDto userRequestDto){ } */ + + public UsersResponseDto userInfo(UsersRequestDto requestDto) { + Users users = userRepository.findById(requestDto.getUserId()).orElseThrow( + () -> new IllegalArgumentException("해당 유저가 없습니다.") + ); + + return UsersResponseDto.from(users); + + } }