Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#20 user health info #24

Merged
merged 11 commits into from
Jul 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ public List<OtherUserDto> 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());
Expand All @@ -94,11 +98,15 @@ public List<OtherUserDto> 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());
Expand All @@ -117,11 +125,15 @@ public List<OtherUserDto> 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());
Expand All @@ -131,11 +143,15 @@ public List<OtherUserDto> 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()
));
}

Expand Down Expand Up @@ -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()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +13,8 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
@RequestMapping("/users")
Expand Down Expand Up @@ -43,12 +46,20 @@ 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<StateResponse> update(HttpServletRequest request, @RequestPart("updateDto") UserUpdateDto requestDto, @RequestPart(value = "profilePicture", required = false) MultipartFile profilePicture) {
@Operation(summary = "사용자 정보 업데이트 메서드", description = "사용자의 이름을 수정합니다.")
public ResponseEntity<?> update(HttpServletRequest request, @RequestBody UserUpdateDto requestDto) {
Long userId = jwtUtil.getUserId(jwtUtil.resolveToken(request).substring(7));
return userService.update(userId,requestDto,profilePicture);
return ResponseEntity.ok(userService.update(userId,requestDto));
}

@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<StateResponse> withdrawal(HttpServletRequest request) {
Expand Down
69 changes: 49 additions & 20 deletions src/main/java/com/example/beginnerfitbe/user/domain/User.java
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -24,42 +27,68 @@ public class User {
private String password;

@Column
private String profilePictureUrl;
private String profileUrl;

@Column
private String exercisePurpose;
private double height;

@Column
private String exercisePart;
private double weight;

@Column
private int exerciseTime;
private double targetWeight;

@Column
private String date;

@Column
private int exerciseIntensity;
private String targetDate;

@Column
private int exerciseTime;

@ElementCollection
private List<String> exerciseIntensity;

@ElementCollection
private List<String> exerciseGoals;

@ElementCollection
private List<String> concernedAreas;


@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<WeightRecord> 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, String profileUrl, double height, double weight, double targetWeight, String date, String targetDate, int exerciseTime, List<String> exerciseIntensity, List<String> exerciseGoals, List<String> concernedAreas) {
this.email = email;
this.name = name;
this.password = password;
this.profilePictureUrl = profilePictureUrl;
this.exercisePurpose=exercisePurpose;
this.exercisePart =exercisePart;
this.exerciseTime=exerciseTime;
this.profileUrl=profileUrl;
this.height = height;
this.weight = weight;
this.date= date;
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(double height, double weight, double targetWeight, String date, String targetDate, int exerciseTime, List<String> exerciseIntensity, List<String> exerciseGoals, List<String> 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 updatePicture(String newPictureUrl){
this.profilePictureUrl = newPictureUrl;
public void updateName(String newName){
this.name= newName;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.beginnerfitbe.user.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@AllArgsConstructor

public class HealthInfoReqDto {
private String email;
private double height;
private double weight;
private double targetWeight;
private String date;
private String targetDate;
private int exerciseTime;
private List<String> exerciseIntensity;
private List<String> exerciseGoals;
private List<String> concernedAreas;
}
25 changes: 17 additions & 8 deletions src/main/java/com/example/beginnerfitbe/user/dto/OtherUserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,38 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@AllArgsConstructor
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<String> exercisePurpose;
private List<String> exercisePart;
private List<String> 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();
}
}
18 changes: 0 additions & 18 deletions src/main/java/com/example/beginnerfitbe/user/dto/SignUpReqDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.beginnerfitbe.user.dto;

import com.example.beginnerfitbe.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -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();
}
}
Loading