Skip to content

Commit

Permalink
Merge pull request #28 from Plantity/feature/#21/mypage
Browse files Browse the repository at this point in the history
Feature/#21/mypage
  • Loading branch information
abi-hong authored Sep 13, 2022
2 parents 95662ca + 5cc701d commit d889ff2
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public ResponseEntity<MyPlantUpdateResponse> putLook(@PathVariable Long userId,
return MyPlantUpdateResponse.newResponse(UPDATE_LOOKPLANTLOG_SUCCESS);
}

@GetMapping("/plant")
public List<PlantLog> check(){
return plantLogRepository.findAll();
@GetMapping("/plant/{userId}")
public List<MyPlant> check(@PathVariable Long userId) {
usersRepository.findByUserId(userId);
return myPlantRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,6 +27,17 @@ public List<Users> getUsers(){
return userRepository.findAll();
}

// user 상세 정보 조회
@GetMapping("/users/{userId}")
public ResponseEntity<UserResponse> 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<Long> postTestUsers(@RequestBody UsersRequestDto usersRequestDto){
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<UserResponse> newResponse(SuccessCode code, UsersResponseDto data) {
UserResponse response = new UserResponse(true, code.getMsg(), data);
return new ResponseEntity(response, code.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface PlantLogRepository extends JpaRepository<PlantLog, Long> {


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.plantity.server.service;

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.PlantLogUpdateRequestDto;
import com.plantity.server.repository.MyPlantRepository;
import com.plantity.server.repository.PlantLogRepository;
import lombok.RequiredArgsConstructor;
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/com/plantity/server/service/UsersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

}
}
2 changes: 1 addition & 1 deletion server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=8086


cloud.aws.stack.auto=false
Expand Down

0 comments on commit d889ff2

Please sign in to comment.