From 2e10a9bc55f6be03ade37ae03289bae0478f4e56 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Thu, 25 Jul 2024 23:08:28 +0900 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20user=20entity=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20,=20weight=20record=20entity=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beginnerfitbe/user/domain/User.java | 58 ++++++++++++------- .../weight/domain/WeightRecord.java | 18 ++++++ 2 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java diff --git a/src/main/java/com/example/beginnerfitbe/user/domain/User.java b/src/main/java/com/example/beginnerfitbe/user/domain/User.java index b465268..9753d18 100644 --- a/src/main/java/com/example/beginnerfitbe/user/domain/User.java +++ b/src/main/java/com/example/beginnerfitbe/user/domain/User.java @@ -1,11 +1,14 @@ package com.example.beginnerfitbe.user.domain; +import com.example.beginnerfitbe.weight.domain.WeightRecord; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -24,42 +27,55 @@ public class User { private String password; @Column - private String profilePictureUrl; + private int height; @Column - private String exercisePurpose; + private int weight; @Column - private String exercisePart; + private int targetWeight; @Column - private int exerciseTime; + private String targetDate; @Column - private int exerciseIntensity; + private int exerciseTime; + + @ElementCollection + private List exerciseIntensity; + + @ElementCollection + private List exerciseGoals; + + @ElementCollection + private List concernedAreas; + + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) + private List weightRecords; @Builder - public User(String email, String name, String password, String profilePictureUrl, String exercisePurpose, String exercisePart, int exerciseTime, int exerciseIntensity) { - this.email=email; + public User(String email, String name, String password, int height, int weight, int targetWeight, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { + this.email = email; this.name = name; this.password = password; - this.profilePictureUrl = profilePictureUrl; - this.exercisePurpose=exercisePurpose; - this.exercisePart =exercisePart; - this.exerciseTime=exerciseTime; + this.height = height; + this.weight = weight; + this.targetWeight = targetWeight; + this.targetDate = targetDate; + this.exerciseTime = exerciseTime; this.exerciseIntensity = exerciseIntensity; + this.exerciseGoals = exerciseGoals; + this.concernedAreas = concernedAreas; } - public void update(String name, String exercisePurpose, String exercisePart, int exerciseTime, int exerciseIntensity) { - this.name=name; - this.exercisePurpose = exercisePurpose; - this.exercisePart= exercisePart; - this.exerciseTime=exerciseTime; + public void updateHealthInfo(int height, int weight, int targetWeight, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { + this.height = height; + this.weight = weight; + this.targetWeight = targetWeight; + this.targetDate = targetDate; + this.exerciseTime = exerciseTime; this.exerciseIntensity = exerciseIntensity; + this.exerciseGoals = exerciseGoals; + this.concernedAreas = concernedAreas; } - - public void updatePicture(String newPictureUrl){ - this.profilePictureUrl = newPictureUrl; - } - } diff --git a/src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java b/src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java new file mode 100644 index 0000000..0b5a854 --- /dev/null +++ b/src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java @@ -0,0 +1,18 @@ +package com.example.beginnerfitbe.weight.domain; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class WeightRecord { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + +} From b2a46b1a86a069d3e10cfe2da02e5e162d385fa1 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Thu, 25 Jul 2024 23:27:25 +0900 Subject: [PATCH 02/10] =?UTF-8?q?refactor:=20SignUpReqDto,=20HealthInfoReq?= =?UTF-8?q?Dto=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/dto/HealthInfoReqDto.java | 21 ++++++++++++++++ .../beginnerfitbe/user/dto/SignUpReqDto.java | 18 -------------- .../user/service/AuthService.java | 24 ++++++++++--------- 3 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java new file mode 100644 index 0000000..88042f0 --- /dev/null +++ b/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java @@ -0,0 +1,21 @@ +package com.example.beginnerfitbe.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@Getter +@AllArgsConstructor + +public class HealthInfoReqDto { + private int height; + private int weight; + private int targetWeight; + private String date; + private String targetDate; + private int exerciseTime; + private List exerciseIntensity; + private List exerciseGoals; + private List concernedAreas; +} diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/SignUpReqDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/SignUpReqDto.java index 4c1e85a..9bb8de6 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/SignUpReqDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/SignUpReqDto.java @@ -1,6 +1,5 @@ package com.example.beginnerfitbe.user.dto; -import com.example.beginnerfitbe.user.domain.User; import lombok.AllArgsConstructor; import lombok.Getter; @@ -10,21 +9,4 @@ public class SignUpReqDto { private String email; private String name; private String password; - private String exercisePurpose; - private String exercisePart; - private int exerciseTime; - private int exerciseIntensity; - - public User toEntity() { - return User.builder() - .email(email) - .name(name) - .password(password) - .profilePictureUrl(null) - .exercisePurpose(exercisePurpose) - .exercisePart(exercisePart) - .exerciseTime(exerciseTime) - .exerciseIntensity(exerciseIntensity) - .build(); - } } diff --git a/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java b/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java index 8279614..472d076 100644 --- a/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java +++ b/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java @@ -10,6 +10,8 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import java.util.ArrayList; + @Service @RequiredArgsConstructor public class AuthService { @@ -21,27 +23,27 @@ public User signUp (SignUpReqDto dto){ String email=dto.getEmail(); String name=dto.getName(); String password=passwordEncoder.encode(dto.getPassword()); - String exercisePurpose = dto.getExercisePurpose(); - String exercisePart =dto.getExercisePart(); - int exerciseTime = dto.getExerciseTime(); - int exerciseIntensity = dto.getExerciseIntensity(); //중복 가입 확인 if(userService.emailCheck(email)){ throw new IllegalArgumentException("이미 등록된 사용자입니다."); } - User user = User.builder() + //회원 기본 정보만 입력 + return User.builder() .email(email) .name(name) .password(password) - .profilePictureUrl(null) - .exercisePurpose(exercisePurpose) - .exercisePart(exercisePart) - .exerciseTime(exerciseTime) - .exerciseIntensity(exerciseIntensity) + .height(0) + .weight(0) + .targetWeight(0) + .date(null) + .targetDate(null) + .exerciseTime(0) + .exerciseIntensity(new ArrayList<>()) + .concernedAreas(new ArrayList<>()) + .exerciseGoals(new ArrayList<>()) .build(); - return user; } public SignInResDto signIn(SignInReqDto dto) { UserDto userDto = userService.readByEmail(dto.getEmail()); From 2427d1328c5028f3e5dc3afbaca2b0ce5b15f06f Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Fri, 26 Jul 2024 00:11:18 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20health=20info=20update=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 20 +++-- .../user/dto/HealthInfoReqDto.java | 1 + .../beginnerfitbe/user/dto/UserDto.java | 36 +++++--- .../user/service/AuthService.java | 1 + .../user/service/UserService.java | 83 ++++++------------- 5 files changed, 69 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java b/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java index 7e28f5d..8f9f77e 100644 --- a/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java +++ b/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java @@ -2,6 +2,7 @@ import com.example.beginnerfitbe.error.StateResponse; import com.example.beginnerfitbe.jwt.util.JwtUtil; +import com.example.beginnerfitbe.user.dto.HealthInfoReqDto; import com.example.beginnerfitbe.user.dto.UserUpdateDto; import com.example.beginnerfitbe.user.service.UserService; import io.swagger.v3.oas.annotations.Operation; @@ -12,6 +13,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; + @RestController @RequiredArgsConstructor @RequestMapping("/users") @@ -43,12 +46,19 @@ ResponseEntity me(HttpServletRequest request){ Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); return ResponseEntity.ok(userService.me(userId)); } - @PutMapping("") - @Operation(summary = "사용자 정보 업데이트 메서드", description = "사용자의 수정된 정보를 받아 업데이트 합니다.") - public ResponseEntity update(HttpServletRequest request, @RequestPart("updateDto") UserUpdateDto requestDto, @RequestPart(value = "profilePicture", required = false) MultipartFile profilePicture) { - Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); - return userService.update(userId,requestDto,profilePicture); +// @PutMapping("") +// @Operation(summary = "사용자 정보 업데이트 메서드", description = "사용자의 수정된 정보를 받아 업데이트 합니다.") +// public ResponseEntity update(HttpServletRequest request, @RequestPart("updateDto") UserUpdateDto requestDto, @RequestPart(value = "profilePicture", required = false) MultipartFile profilePicture) { +// Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); +// return userService.update(userId,requestDto,profilePicture); +// } + + @PutMapping("/health-info") + @Operation(summary = "사용자 건강 정보 업데이트 메서드", description = "사용자의 건강 정보를 업데이트합니다.") + public ResponseEntity updateHealthInfo(@RequestBody HealthInfoReqDto reqDto) throws IOException { + return ResponseEntity.ok(userService.updateHealthInfo(reqDto)); } + @DeleteMapping("/withdrawal") @Operation(summary = "사용자 탈퇴 메서드", description = "사용자가 탈퇴하는 메서드입니다. ") public ResponseEntity withdrawal(HttpServletRequest request) { diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java index 88042f0..266ccde 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java @@ -9,6 +9,7 @@ @AllArgsConstructor public class HealthInfoReqDto { + private String email; private int height; private int weight; private int targetWeight; diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java index 1965667..1cbb24e 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java @@ -3,27 +3,37 @@ import com.example.beginnerfitbe.user.domain.User; import lombok.Data; +import java.util.List; + @Data public class UserDto { private Long id; private String email; private String name; private String password; - private String profilePictureUrl; - private String exercisePurpose; - private String exercisePart; + private int height; + private int weight; + private int targetWeight; + private String date; + private String targetDate; private int exerciseTime; - private int exerciseIntensity; + private List exercisePurpose; + private List exercisePart; + private List exerciseIntensity; - public UserDto(Long id, String email, String name, String password, String profilePictureUrl, String exercisePurpose, String exercisePart, int exerciseTime, int exerciseIntensity) { + public UserDto(Long id, String email, String name, String password, int height, int weight, int targetWeight, String date, String targetDate, int exerciseTime, List exercisePurpose, List exercisePart, List exerciseIntensity) { this.id = id; this.email = email; this.name = name; this.password = password; - this.profilePictureUrl = profilePictureUrl; + this.height = height; + this.weight = weight; + this.targetWeight = targetWeight; + this.date = date; + this.targetDate = targetDate; + this.exerciseTime = exerciseTime; this.exercisePurpose = exercisePurpose; this.exercisePart = exercisePart; - this.exerciseTime = exerciseTime; this.exerciseIntensity = exerciseIntensity; } @@ -33,11 +43,15 @@ public static UserDto fromEntity(User user) { user.getEmail(), user.getName(), user.getPassword(), - user.getProfilePictureUrl(), - user.getExercisePurpose(), - user.getExercisePart(), + user.getHeight(), + user.getWeight(), + user.getTargetWeight(), + user.getDate(), + user.getTargetDate(), user.getExerciseTime(), - user.getExerciseIntensity() + user.getExerciseIntensity(), + user.getExerciseGoals(), + user.getConcernedAreas() ); } } diff --git a/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java b/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java index 472d076..5920640 100644 --- a/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java +++ b/src/main/java/com/example/beginnerfitbe/user/service/AuthService.java @@ -33,6 +33,7 @@ public User signUp (SignUpReqDto dto){ .email(email) .name(name) .password(password) + .profileUrl(null) .height(0) .weight(0) .targetWeight(0) diff --git a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java index 22c284c..8b0275a 100644 --- a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java +++ b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java @@ -5,14 +5,12 @@ import com.example.beginnerfitbe.playlist.service.PlaylistService; import com.example.beginnerfitbe.s3.util.S3Uploader; import com.example.beginnerfitbe.user.domain.User; +import com.example.beginnerfitbe.user.dto.HealthInfoReqDto; import com.example.beginnerfitbe.user.dto.UserDto; -import com.example.beginnerfitbe.user.dto.UserUpdateDto; import com.example.beginnerfitbe.user.repository.UserRepository; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.List; @@ -35,8 +33,6 @@ public List list(){ public void create(User user) throws IOException { userRepository.save(user); - //플레이리스트 생성 - playlistService.create(user); } public UserDto read(Long id) { @@ -52,63 +48,38 @@ public List me(Long id){ .map(UserDto::fromEntity) .collect(Collectors.toList()); } - //회원정보 수정 - public ResponseEntity update(Long id, UserUpdateDto requestDto, MultipartFile profilePicture) { - try { - User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("User not found")); - String previousPictureUrl = user.getProfilePictureUrl(); - - boolean createSignal = true; - //정보 업데이트 - if (requestDto.getName() != null && requestDto.getExercisePurpose()!=null && requestDto.getExercisePart()!=null - && requestDto.getExerciseTime()!=0 && requestDto.getExerciseIntensity()!=0 ) { - - //건강정보 안바뀜 -> 플레이리스트 그대로 - if(requestDto.getExercisePurpose().equals(user.getExercisePurpose()) - && requestDto.getExercisePart().equals(user.getExercisePart()) - && requestDto.getExerciseIntensity()==user.getExerciseIntensity() - && requestDto.getExerciseTime()==user.getExerciseTime()){ - createSignal=false; - } - - user.update(requestDto.getName(), requestDto.getExercisePurpose(), requestDto.getExercisePart(), requestDto.getExerciseTime(), requestDto.getExerciseIntensity()); - - } - if (previousPictureUrl != null) { - s3Uploader.delete("User",previousPictureUrl); - } - //사진 업로드 or 변경 - String pictureUrl = null; - if (profilePicture != null && !profilePicture.isEmpty()) { - if (previousPictureUrl != null) { - s3Uploader.delete("User",previousPictureUrl); - } - pictureUrl = s3Uploader.upload(profilePicture, "User"); - } - user.updatePicture(pictureUrl); - userRepository.save(user); - - //플레이리스트 생성 - if(createSignal){ - playlistService.create(user); - } - - return ResponseEntity.ok(StateResponse.builder().code("SUCCESS").message("정보를 성공적으로 업데이트했습니다.").build()); - } catch (Exception e){ - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(StateResponse.builder().code("ERROR").message("오류가 발생했습니다: " + e.getMessage()).build()); - } + + //건강정보 업데이트 + public StateResponse updateHealthInfo(HealthInfoReqDto dto) throws IOException { + User user = userRepository.findByEmail(dto.getEmail()).orElseThrow(() -> new IllegalArgumentException("User not found")); + + user.updateHealthInfo( + dto.getHeight(), + dto.getWeight(), + dto.getTargetWeight(), + dto.getDate(), + dto.getTargetDate(), + dto.getExerciseTime(), + dto.getExerciseIntensity(), + dto.getExerciseGoals(), + dto.getConcernedAreas() + ); + + userRepository.save(user); + + //플레이리스트 생성 + playlistService.create(user); + + return StateResponse.builder() + .code("SUCCESS") + .message("건강정보가 업데이트 되었습니다.") + .build(); } //회원 탈퇴 public ResponseEntity withdrawal(Long id) { User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("User not found")); - //버킷 사진 삭제 - String previousPictureUrl = user.getProfilePictureUrl(); - if(previousPictureUrl!=null){ - s3Uploader.delete("User",previousPictureUrl); - } - userRepository.delete(user); return ResponseEntity.ok(StateResponse.builder().code("SUCCESS").message("성공적으로 회원탈퇴 처리되었습니다.").build()); } From fe0a1e7429c1fe6dc94d530623cb468ebe399b06 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Fri, 26 Jul 2024 00:26:20 +0900 Subject: [PATCH 04/10] =?UTF-8?q?fix:=20health-info=20token=EC=97=86?= =?UTF-8?q?=EC=9D=B4=20=EC=A0=91=EA=B7=BC=20=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/beginnerfitbe/jwt/config/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/example/beginnerfitbe/jwt/config/SecurityConfig.java b/src/main/java/com/example/beginnerfitbe/jwt/config/SecurityConfig.java index 690b628..4764040 100644 --- a/src/main/java/com/example/beginnerfitbe/jwt/config/SecurityConfig.java +++ b/src/main/java/com/example/beginnerfitbe/jwt/config/SecurityConfig.java @@ -27,6 +27,7 @@ public class SecurityConfig { "/auth/sign-in", "/auth/sign-up", "/users/emailcheck", + "/users/health-info", "/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**", From e13adccd23f6c9b701f0c7d4673a651ca1e23109 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Fri, 26 Jul 2024 00:27:18 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=EC=A0=95=EB=B3=B4=20update=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beginnerfitbe/post/dto/PostDto.java | 2 +- .../user/controller/UserController.java | 13 ++++++----- .../beginnerfitbe/user/domain/User.java | 22 ++++++++++++++----- .../beginnerfitbe/user/dto/UserUpdateDto.java | 6 ----- .../user/service/UserService.java | 14 +++++++++++- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/example/beginnerfitbe/post/dto/PostDto.java b/src/main/java/com/example/beginnerfitbe/post/dto/PostDto.java index 254ec05..ce9d3bd 100644 --- a/src/main/java/com/example/beginnerfitbe/post/dto/PostDto.java +++ b/src/main/java/com/example/beginnerfitbe/post/dto/PostDto.java @@ -39,7 +39,7 @@ public static PostDto fromEntity(Post post) { post.getCreatedAt(), post.getUser().getId(), post.getUser().getName(), - post.getUser().getProfilePictureUrl(), + post.getUser().getProfileUrl(), post.getCategory().getCategoryName() ); } diff --git a/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java b/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java index 8f9f77e..2582644 100644 --- a/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java +++ b/src/main/java/com/example/beginnerfitbe/user/controller/UserController.java @@ -46,12 +46,13 @@ ResponseEntity me(HttpServletRequest request){ Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); return ResponseEntity.ok(userService.me(userId)); } -// @PutMapping("") -// @Operation(summary = "사용자 정보 업데이트 메서드", description = "사용자의 수정된 정보를 받아 업데이트 합니다.") -// public ResponseEntity update(HttpServletRequest request, @RequestPart("updateDto") UserUpdateDto requestDto, @RequestPart(value = "profilePicture", required = false) MultipartFile profilePicture) { -// Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); -// return userService.update(userId,requestDto,profilePicture); -// } + + @PutMapping("") + @Operation(summary = "사용자 정보 업데이트 메서드", description = "사용자의 이름을 수정합니다.") + public ResponseEntity update(HttpServletRequest request, @RequestBody UserUpdateDto requestDto) { + Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); + return ResponseEntity.ok(userService.update(userId,requestDto)); + } @PutMapping("/health-info") @Operation(summary = "사용자 건강 정보 업데이트 메서드", description = "사용자의 건강 정보를 업데이트합니다.") diff --git a/src/main/java/com/example/beginnerfitbe/user/domain/User.java b/src/main/java/com/example/beginnerfitbe/user/domain/User.java index 9753d18..be7d512 100644 --- a/src/main/java/com/example/beginnerfitbe/user/domain/User.java +++ b/src/main/java/com/example/beginnerfitbe/user/domain/User.java @@ -1,6 +1,5 @@ package com.example.beginnerfitbe.user.domain; -import com.example.beginnerfitbe.weight.domain.WeightRecord; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -26,6 +25,9 @@ public class User { @Column(nullable = false) private String password; + @Column + private String profileUrl; + @Column private int height; @@ -35,6 +37,9 @@ public class User { @Column private int targetWeight; + @Column + private String date; + @Column private String targetDate; @@ -50,16 +55,19 @@ public class User { @ElementCollection private List concernedAreas; - @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) - private List weightRecords; + +// @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) +// private List weightRecords; @Builder - public User(String email, String name, String password, int height, int weight, int targetWeight, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { + public User(String email, String name, String password, String profileUrl, int height, int weight, int targetWeight, String date, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { this.email = email; this.name = name; this.password = password; + this.profileUrl=profileUrl; this.height = height; this.weight = weight; + this.date= date; this.targetWeight = targetWeight; this.targetDate = targetDate; this.exerciseTime = exerciseTime; @@ -68,14 +76,18 @@ public User(String email, String name, String password, int height, int weight, this.concernedAreas = concernedAreas; } - public void updateHealthInfo(int height, int weight, int targetWeight, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { + public void updateHealthInfo(int height, int weight, int targetWeight, String date, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { this.height = height; this.weight = weight; this.targetWeight = targetWeight; + this.date = date; this.targetDate = targetDate; this.exerciseTime = exerciseTime; this.exerciseIntensity = exerciseIntensity; this.exerciseGoals = exerciseGoals; this.concernedAreas = concernedAreas; } + public void updateName(String newName){ + this.name= newName; + } } diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/UserUpdateDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/UserUpdateDto.java index 6d0cc71..cd322ef 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/UserUpdateDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/UserUpdateDto.java @@ -6,10 +6,4 @@ @Data public class UserUpdateDto { private String name; - private String exercisePurpose; - private String exercisePart; - private int exerciseTime; - private int exerciseIntensity; - - } diff --git a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java index 8b0275a..c64a956 100644 --- a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java +++ b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java @@ -7,6 +7,7 @@ import com.example.beginnerfitbe.user.domain.User; import com.example.beginnerfitbe.user.dto.HealthInfoReqDto; import com.example.beginnerfitbe.user.dto.UserDto; +import com.example.beginnerfitbe.user.dto.UserUpdateDto; import com.example.beginnerfitbe.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -22,7 +23,6 @@ public class UserService { private final UserRepository userRepository; - private final S3Uploader s3Uploader; private final PlaylistService playlistService; public List list(){ @@ -76,6 +76,18 @@ public StateResponse updateHealthInfo(HealthInfoReqDto dto) throws IOException { .build(); } + public StateResponse update(Long userId, UserUpdateDto dto){ + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("User not found")); + user.updateName(dto.getName()); + + userRepository.save(user); + + return StateResponse.builder() + .code("SUCCESS") + .message("사용자 이름이 업데이트 되었습니다.") + .build(); + + } //회원 탈퇴 public ResponseEntity withdrawal(Long id) { User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("User not found")); From c21eceae2c484b834de703d8a9124fab43b17bb5 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Fri, 26 Jul 2024 15:05:28 +0900 Subject: [PATCH 06/10] =?UTF-8?q?chore:=20int=EC=97=90=EC=84=9C=20double?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beginnerfitbe/user/domain/User.java | 15 +++++++------- .../user/dto/HealthInfoReqDto.java | 6 +++--- .../beginnerfitbe/user/dto/UserDto.java | 8 ++++---- .../user/service/UserService.java | 6 +++++- .../weight/domain/WeightRecord.java | 20 +++++++++++++++++++ .../repository/WeightRecordRepository.java | 2 ++ 6 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java diff --git a/src/main/java/com/example/beginnerfitbe/user/domain/User.java b/src/main/java/com/example/beginnerfitbe/user/domain/User.java index be7d512..40f3e6b 100644 --- a/src/main/java/com/example/beginnerfitbe/user/domain/User.java +++ b/src/main/java/com/example/beginnerfitbe/user/domain/User.java @@ -1,5 +1,6 @@ package com.example.beginnerfitbe.user.domain; +import com.example.beginnerfitbe.weight.domain.WeightRecord; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -29,13 +30,13 @@ public class User { private String profileUrl; @Column - private int height; + private double height; @Column - private int weight; + private double weight; @Column - private int targetWeight; + private double targetWeight; @Column private String date; @@ -56,11 +57,11 @@ public class User { private List concernedAreas; -// @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) -// private List weightRecords; + @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE, orphanRemoval = true) + private List weightRecords; @Builder - public User(String email, String name, String password, String profileUrl, int height, int weight, int targetWeight, String date, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { + public User(String email, String name, String password, String profileUrl, double height, double weight, double targetWeight, String date, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { this.email = email; this.name = name; this.password = password; @@ -76,7 +77,7 @@ public User(String email, String name, String password, String profileUrl, int h this.concernedAreas = concernedAreas; } - public void updateHealthInfo(int height, int weight, int targetWeight, String date, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { + public void updateHealthInfo(double height, double weight, double targetWeight, String date, String targetDate, int exerciseTime, List exerciseIntensity, List exerciseGoals, List concernedAreas) { this.height = height; this.weight = weight; this.targetWeight = targetWeight; diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java index 266ccde..54923d3 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/HealthInfoReqDto.java @@ -10,9 +10,9 @@ public class HealthInfoReqDto { private String email; - private int height; - private int weight; - private int targetWeight; + private double height; + private double weight; + private double targetWeight; private String date; private String targetDate; private int exerciseTime; diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java index 1cbb24e..32c5218 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java @@ -11,9 +11,9 @@ public class UserDto { private String email; private String name; private String password; - private int height; - private int weight; - private int targetWeight; + private double height; + private double weight; + private double targetWeight; private String date; private String targetDate; private int exerciseTime; @@ -21,7 +21,7 @@ public class UserDto { private List exercisePart; private List exerciseIntensity; - public UserDto(Long id, String email, String name, String password, int height, int weight, int targetWeight, String date, String targetDate, int exerciseTime, List exercisePurpose, List exercisePart, List exerciseIntensity) { + public UserDto(Long id, String email, String name, String password, double height, double weight, double targetWeight, String date, String targetDate, int exerciseTime, List exercisePurpose, List exercisePart, List exerciseIntensity) { this.id = id; this.email = email; this.name = name; diff --git a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java index c64a956..e3dd71e 100644 --- a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java +++ b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java @@ -3,12 +3,12 @@ import com.example.beginnerfitbe.error.StateResponse; import com.example.beginnerfitbe.playlist.service.PlaylistService; -import com.example.beginnerfitbe.s3.util.S3Uploader; import com.example.beginnerfitbe.user.domain.User; import com.example.beginnerfitbe.user.dto.HealthInfoReqDto; import com.example.beginnerfitbe.user.dto.UserDto; import com.example.beginnerfitbe.user.dto.UserUpdateDto; import com.example.beginnerfitbe.user.repository.UserRepository; +import com.example.beginnerfitbe.weight.service.WeightRecordService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -24,6 +24,7 @@ public class UserService { private final UserRepository userRepository; private final PlaylistService playlistService; + private final WeightRecordService weightRecordService; public List list(){ return userRepository.findAll().stream() @@ -70,6 +71,9 @@ public StateResponse updateHealthInfo(HealthInfoReqDto dto) throws IOException { //플레이리스트 생성 playlistService.create(user); + //몸무게 기록 + weightRecordService.create(user.getId(), user.getWeight()); + return StateResponse.builder() .code("SUCCESS") .message("건강정보가 업데이트 되었습니다.") diff --git a/src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java b/src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java index 0b5a854..9e4c95e 100644 --- a/src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java +++ b/src/main/java/com/example/beginnerfitbe/weight/domain/WeightRecord.java @@ -1,10 +1,14 @@ package com.example.beginnerfitbe.weight.domain; +import com.example.beginnerfitbe.user.domain.User; import jakarta.persistence.*; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import java.time.LocalDateTime; @Entity @Getter @@ -14,5 +18,21 @@ public class WeightRecord { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @ManyToOne + @JoinColumn(name = "user_id", nullable = false) + private User user; + @Column(nullable = false) + @CreatedDate + private LocalDateTime date; + + @Column(nullable = false) + private double weight; + + @Builder + public WeightRecord(User user, LocalDateTime date, double weight) { + this.user = user; + this.date = date; + this.weight = weight; + } } diff --git a/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java b/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java new file mode 100644 index 0000000..41cf03d --- /dev/null +++ b/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java @@ -0,0 +1,2 @@ +package com.example.beginnerfitbe.weight.repository;public interface WeightRecordRepository { +} From a0675367cad6a40304963a75213f5eef20099dc9 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Fri, 26 Jul 2024 15:14:39 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20weight=20=EA=B8=B0=EB=A1=9D=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/service/UserService.java | 2 +- .../weight/dto/WeightRecordDto.java | 33 +++++++++++++++++ .../repository/WeightRecordRepository.java | 13 ++++++- .../weight/service/WeightRecordService.java | 36 +++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/example/beginnerfitbe/weight/dto/WeightRecordDto.java create mode 100644 src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java diff --git a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java index e3dd71e..46764cf 100644 --- a/src/main/java/com/example/beginnerfitbe/user/service/UserService.java +++ b/src/main/java/com/example/beginnerfitbe/user/service/UserService.java @@ -69,7 +69,7 @@ public StateResponse updateHealthInfo(HealthInfoReqDto dto) throws IOException { userRepository.save(user); //플레이리스트 생성 - playlistService.create(user); +// playlistService.create(user); //몸무게 기록 weightRecordService.create(user.getId(), user.getWeight()); diff --git a/src/main/java/com/example/beginnerfitbe/weight/dto/WeightRecordDto.java b/src/main/java/com/example/beginnerfitbe/weight/dto/WeightRecordDto.java new file mode 100644 index 0000000..376bd77 --- /dev/null +++ b/src/main/java/com/example/beginnerfitbe/weight/dto/WeightRecordDto.java @@ -0,0 +1,33 @@ +package com.example.beginnerfitbe.weight.dto; + +import com.example.beginnerfitbe.weight.domain.WeightRecord; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class WeightRecordDto { + private Long userId; + private String userName; + private LocalDateTime createdAt; + private double weight; + private double targetWeight; + + public WeightRecordDto(Long userId, String userName, LocalDateTime createdAt, double weight, double targetWeight) { + this.userId = userId; + this.userName = userName; + this.createdAt = createdAt; + this.weight = weight; + this.targetWeight =targetWeight; + } + + public static WeightRecordDto fromEntity(WeightRecord weightRecord){ + return new WeightRecordDto( + weightRecord.getUser().getId(), + weightRecord.getUser().getName(), + weightRecord.getDate(), + weightRecord.getWeight(), + weightRecord.getUser().getTargetWeight() + ); + } +} diff --git a/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java b/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java index 41cf03d..ba44a66 100644 --- a/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java +++ b/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java @@ -1,2 +1,13 @@ -package com.example.beginnerfitbe.weight.repository;public interface WeightRecordRepository { +package com.example.beginnerfitbe.weight.repository; + +import com.example.beginnerfitbe.user.domain.User; +import com.example.beginnerfitbe.weight.domain.WeightRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface WeightRecordRepository extends JpaRepository { + List findByUserOrderByDateAsc(User user); } diff --git a/src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java b/src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java new file mode 100644 index 0000000..370d18a --- /dev/null +++ b/src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java @@ -0,0 +1,36 @@ +package com.example.beginnerfitbe.weight.service; + +import com.example.beginnerfitbe.user.domain.User; +import com.example.beginnerfitbe.user.repository.UserRepository; +import com.example.beginnerfitbe.weight.domain.WeightRecord; +import com.example.beginnerfitbe.weight.dto.WeightRecordDto; +import com.example.beginnerfitbe.weight.repository.WeightRecordRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class WeightRecordService { + + private final WeightRecordRepository weightRecordRepository; + private final UserRepository userRepository; + + public WeightRecordDto create (Long userId, double weight){ + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("User not found")); + + WeightRecord weightRecord = WeightRecord.builder() + .user(user) + .date(LocalDateTime.now()) + .weight(weight) + .build(); + + weightRecordRepository.save(weightRecord); + + return WeightRecordDto.fromEntity(weightRecord); + } + +} From aae7ac2a55c7270e1cc6c0ac7c5453141c415976 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Fri, 26 Jul 2024 15:33:53 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20record=20=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C,=20=EC=B5=9C=EA=B7=BC=205=EA=B0=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WeightRecordController.java | 36 +++++++++++++++++++ .../repository/WeightRecordRepository.java | 1 + .../weight/service/WeightRecordService.java | 28 +++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/main/java/com/example/beginnerfitbe/weight/controller/WeightRecordController.java diff --git a/src/main/java/com/example/beginnerfitbe/weight/controller/WeightRecordController.java b/src/main/java/com/example/beginnerfitbe/weight/controller/WeightRecordController.java new file mode 100644 index 0000000..b20983e --- /dev/null +++ b/src/main/java/com/example/beginnerfitbe/weight/controller/WeightRecordController.java @@ -0,0 +1,36 @@ +package com.example.beginnerfitbe.weight.controller; + +import com.example.beginnerfitbe.jwt.util.JwtUtil; +import com.example.beginnerfitbe.weight.service.WeightRecordService; +import io.swagger.v3.oas.annotations.Operation; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/users") +public class WeightRecordController { + + private final WeightRecordService weightRecordService; + private final JwtUtil jwtUtil; + + //전체 기록 조회 + @GetMapping("/weight-records") + @Operation(summary = "몸무게 전체 기록 조회", description = "사용자의 전체 몸무게 기록을 조회합니다.") + public ResponseEntity list(HttpServletRequest request) { + Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); + return ResponseEntity.ok(weightRecordService.list(userId)); + } + + //전체 기록 조회 + @GetMapping("/recent-weight-records") + @Operation(summary = "최근 5번 몸무게 현황 조회", description = "사용자의 최근 5개 몸무게 기록을 조회합니다.") + public ResponseEntity getRecentWeightRecords(HttpServletRequest request) { + Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7)); + return ResponseEntity.ok(weightRecordService.getRecentWeightRecords(userId)); + } +} diff --git a/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java b/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java index ba44a66..ac5590d 100644 --- a/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java +++ b/src/main/java/com/example/beginnerfitbe/weight/repository/WeightRecordRepository.java @@ -10,4 +10,5 @@ @Repository public interface WeightRecordRepository extends JpaRepository { List findByUserOrderByDateAsc(User user); + List findTop5ByUserOrderByDateDesc(User user); } diff --git a/src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java b/src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java index 370d18a..5a1ca0f 100644 --- a/src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java +++ b/src/main/java/com/example/beginnerfitbe/weight/service/WeightRecordService.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -33,4 +34,31 @@ public WeightRecordDto create (Long userId, double weight){ return WeightRecordDto.fromEntity(weightRecord); } + //시간순서대로 + public List list(Long userId) { + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("User not found")); + + if(weightRecordRepository.findByUserOrderByDateAsc(user).isEmpty()){ + return null; + } + return weightRecordRepository.findByUserOrderByDateAsc(user).stream() + .map(WeightRecordDto::fromEntity) + .collect(Collectors.toList()); + } + + public List getRecentWeightRecords(Long userId) { + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("User not found")); + + if(weightRecordRepository.findTop5ByUserOrderByDateDesc(user).isEmpty()){ + return null; + } + + List recentWeightRecords = weightRecordRepository.findTop5ByUserOrderByDateDesc(user); + + recentWeightRecords.sort(Comparator.comparing(WeightRecord::getDate)); + + return recentWeightRecords.stream() + .map(WeightRecordDto::fromEntity) + .collect(Collectors.toList()); + } } From dae34bfb786e002638a61d163b91fa559572aa36 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Sat, 27 Jul 2024 00:46:23 +0900 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20friend=20dto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friend/service/FriendService.java | 60 ++++++++++++------- .../playlist/service/PlaylistService.java | 20 +++---- .../beginnerfitbe/user/dto/OtherUserDto.java | 25 +++++--- 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/example/beginnerfitbe/friend/service/FriendService.java b/src/main/java/com/example/beginnerfitbe/friend/service/FriendService.java index 774b01d..b1a5fee 100644 --- a/src/main/java/com/example/beginnerfitbe/friend/service/FriendService.java +++ b/src/main/java/com/example/beginnerfitbe/friend/service/FriendService.java @@ -74,11 +74,15 @@ public List getPendingFriendRequests(Long userId) { sender.getId(), sender.getEmail(), sender.getName(), - sender.getExercisePurpose(), - sender.getExercisePart(), + sender.getHeight(), + sender.getWeight(), + sender.getTargetWeight(), + sender.getDate(), + sender.getTargetDate(), sender.getExerciseTime(), - sender.getExerciseIntensity(), - sender.getProfilePictureUrl() + sender.getExerciseGoals(), + sender.getConcernedAreas(), + sender.getExerciseIntensity() ); }) .collect(Collectors.toList()); @@ -94,11 +98,15 @@ public List getFriendWaitingService(Long userId) { receiver.getId(), receiver.getEmail(), receiver.getName(), - receiver.getExercisePurpose(), - receiver.getExercisePart(), + receiver.getHeight(), + receiver.getWeight(), + receiver.getTargetWeight(), + receiver.getDate(), + receiver.getTargetDate(), receiver.getExerciseTime(), - receiver.getExerciseIntensity(), - receiver.getProfilePictureUrl() + receiver.getExerciseGoals(), + receiver.getConcernedAreas(), + receiver.getExerciseIntensity() ); }) .collect(Collectors.toList()); @@ -117,11 +125,15 @@ public List getAcceptedFriendRequests(Long userId) { sender.getId(), sender.getEmail(), sender.getName(), - sender.getExercisePurpose(), - sender.getExercisePart(), + sender.getHeight(), + sender.getWeight(), + sender.getTargetWeight(), + sender.getDate(), + sender.getTargetDate(), sender.getExerciseTime(), - sender.getExerciseIntensity(), - sender.getProfilePictureUrl() + sender.getExerciseGoals(), + sender.getConcernedAreas(), + sender.getExerciseIntensity() ); }) .collect(Collectors.toList()); @@ -131,11 +143,15 @@ public List getAcceptedFriendRequests(Long userId) { receiver.getId(), receiver.getEmail(), receiver.getName(), - receiver.getExercisePurpose(), - receiver.getExercisePart(), + receiver.getHeight(), + receiver.getWeight(), + receiver.getTargetWeight(), + receiver.getDate(), + receiver.getTargetDate(), receiver.getExerciseTime(), - receiver.getExerciseIntensity(), - receiver.getProfilePictureUrl() + receiver.getExerciseGoals(), + receiver.getConcernedAreas(), + receiver.getExerciseIntensity() )); } @@ -175,11 +191,15 @@ public OtherUserDto getFriendInfo(Long senderId, String receiverEmail) { friend.getId(), friend.getEmail(), friend.getName(), - friend.getExercisePurpose(), - friend.getExercisePart(), + friend.getHeight(), + friend.getWeight(), + friend.getTargetWeight(), + friend.getDate(), + friend.getTargetDate(), friend.getExerciseTime(), - friend.getExerciseIntensity(), - friend.getProfilePictureUrl() + friend.getExerciseGoals(), + friend.getConcernedAreas(), + friend.getExerciseIntensity() ); } diff --git a/src/main/java/com/example/beginnerfitbe/playlist/service/PlaylistService.java b/src/main/java/com/example/beginnerfitbe/playlist/service/PlaylistService.java index 15aadde..a0f8d28 100644 --- a/src/main/java/com/example/beginnerfitbe/playlist/service/PlaylistService.java +++ b/src/main/java/com/example/beginnerfitbe/playlist/service/PlaylistService.java @@ -69,16 +69,16 @@ public void createPlaylistDaily() { private String searchKeyword(User user) { - String query= null; - if(user.getExerciseIntensity()<=3){ - query = user.getExercisePart() + " " + user.getExercisePurpose() +" 쉬운 운동"; - } - else if(user.getExerciseIntensity()>=7){ - query = user.getExercisePart() + " " + user.getExercisePurpose() +" 매운맛 운동"; - } - else{ - query = user.getExercisePart() + " " + user.getExercisePurpose()+" 운동"; - } + String query= "운동"; +// if(user.getExerciseIntensity()<=3){ +// query = user.getExercisePart() + " " + user.getExercisePurpose() +" 쉬운 운동"; +// } +// else if(user.getExerciseIntensity()>=7){ +// query = user.getExercisePart() + " " + user.getExercisePurpose() +" 매운맛 운동"; +// } +// else{ +// query = user.getExercisePart() + " " + user.getExercisePurpose()+" 운동"; +// } return query; } diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/OtherUserDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/OtherUserDto.java index cb5ca46..bfe216f 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/OtherUserDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/OtherUserDto.java @@ -4,6 +4,8 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.List; + @Getter @AllArgsConstructor public class OtherUserDto { @@ -11,22 +13,29 @@ public class OtherUserDto { private Long id; private String email; private String name; - private String exercisePurpose; - private String exercisePart; + private double height; + private double weight; + private double targetWeight; + private String date; + private String targetDate; private int exerciseTime; - private int exerciseIntensity; - private String profilePictureUrl; + private List exercisePurpose; + private List exercisePart; + private List exerciseIntensity; public User toEntity() { return User.builder() - .email(email) .name(name) - .exercisePurpose(exercisePurpose) - .exercisePart(exercisePart) + .height(height) + .weight(weight) + .targetWeight(targetWeight) + .date(date) + .targetDate(targetDate) .exerciseTime(exerciseTime) + .exerciseGoals(exercisePurpose) + .concernedAreas(exercisePart) .exerciseIntensity(exerciseIntensity) - .profilePictureUrl(profilePictureUrl) .build(); } } From 7cfbbafec906981f1b8e8fd0f74deb867c5d2e85 Mon Sep 17 00:00:00 2001 From: wlstj <22020306jinseoyeon@gmail.com> Date: Sat, 27 Jul 2024 01:02:18 +0900 Subject: [PATCH 10/10] =?UTF-8?q?chore:=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/beginnerfitbe/user/dto/UserDto.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java b/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java index 32c5218..40907b7 100644 --- a/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java +++ b/src/main/java/com/example/beginnerfitbe/user/dto/UserDto.java @@ -17,11 +17,11 @@ public class UserDto { private String date; private String targetDate; private int exerciseTime; - private List exercisePurpose; - private List exercisePart; + private List exerciseGoals; + private List concernedAreas; private List exerciseIntensity; - public UserDto(Long id, String email, String name, String password, double height, double weight, double targetWeight, String date, String targetDate, int exerciseTime, List exercisePurpose, List exercisePart, List exerciseIntensity) { + public UserDto(Long id, String email, String name, String password, double height, double weight, double targetWeight, String date, String targetDate, int exerciseTime, List exerciseGoals, List concernedAreas, List exerciseIntensity) { this.id = id; this.email = email; this.name = name; @@ -32,8 +32,8 @@ public UserDto(Long id, String email, String name, String password, double heigh this.date = date; this.targetDate = targetDate; this.exerciseTime = exerciseTime; - this.exercisePurpose = exercisePurpose; - this.exercisePart = exercisePart; + this.exerciseGoals = exerciseGoals; + this.concernedAreas = concernedAreas; this.exerciseIntensity = exerciseIntensity; } @@ -49,9 +49,9 @@ public static UserDto fromEntity(User user) { user.getDate(), user.getTargetDate(), user.getExerciseTime(), - user.getExerciseIntensity(), user.getExerciseGoals(), - user.getConcernedAreas() + user.getConcernedAreas(), + user.getExerciseIntensity() ); } }