-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 운동 정보 입력 API
- Loading branch information
Showing
25 changed files
with
431 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/sopt/org/motivooServer/domain/health/dto/request/OnboardingRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package sopt.org.motivooServer.domain.health.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import sopt.org.motivooServer.domain.health.entity.ExerciseFrequency; | ||
import sopt.org.motivooServer.domain.health.entity.ExerciseTime; | ||
import sopt.org.motivooServer.domain.health.entity.ExerciseType; | ||
import sopt.org.motivooServer.domain.health.entity.HealthNote; | ||
import sopt.org.motivooServer.domain.user.entity.UserType; | ||
|
||
import java.util.List; | ||
|
||
public record OnboardingRequest ( | ||
String type, | ||
int age, | ||
@JsonProperty("is_exercise") | ||
boolean isExercise, | ||
@JsonProperty("exercise_type") | ||
String exerciseType, | ||
@JsonProperty("exercise_count") | ||
String exerciseCount, | ||
@JsonProperty("exercise_time") | ||
String exerciseTime, | ||
@JsonProperty("exercise_note") | ||
List<String> exerciseNote | ||
){ | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/sopt/org/motivooServer/domain/health/dto/response/OnboardingResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package sopt.org.motivooServer.domain.health.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import sopt.org.motivooServer.domain.health.entity.ExerciseLevel; | ||
|
||
public record OnboardingResponse ( | ||
@JsonProperty("user_id") | ||
Long userId, | ||
@JsonProperty("invite_code") | ||
String inviteCode, | ||
@JsonProperty("exercise_level") | ||
String exerciseLevel | ||
){ | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseFrequency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
package sopt.org.motivooServer.domain.health.entity; | ||
|
||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Arrays; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum ExerciseFrequency { | ||
|
||
// 1회 미만 | 1~2회 | 3~4회 | 5회 이상 | ||
LESS_THAN_ONCE("1회 미만"), | ||
ONCE_OR_TWICE("1~2회"), | ||
THREE_OR_FOUR_TIMES("3~4회"), | ||
FIVE_OR_MORE_TIMES("5회 이상"); | ||
|
||
private final String value; | ||
|
||
public static ExerciseFrequency of(String value) { | ||
return Arrays.stream(ExerciseFrequency.values()) | ||
.filter(exerciseFrequency -> value.equals(exerciseFrequency.value)) | ||
.findFirst() | ||
.orElseThrow(() -> new EntityNotFoundException());//TO-DO | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package sopt.org.motivooServer.domain.health.entity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import sopt.org.motivooServer.domain.health.exception.HealthException; | ||
|
||
import java.util.Arrays; | ||
|
||
import static sopt.org.motivooServer.domain.health.exception.HealthExceptionType.INVALID_EXERCISE_LEVEL; | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum ExerciseLevel { | ||
ADVANCED("고수"), | ||
INTERMEDIATE("중수"), | ||
BEGINNER("초보"); | ||
private final String value; | ||
|
||
|
||
public static ExerciseLevel of(String value) { | ||
return Arrays.stream(ExerciseLevel.values()) | ||
.filter(exerciseLevel -> value.equals(exerciseLevel.value)) | ||
.findFirst() | ||
.orElseThrow(() -> new HealthException(INVALID_EXERCISE_LEVEL)); | ||
} | ||
} |
24 changes: 23 additions & 1 deletion
24
src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
package sopt.org.motivooServer.domain.health.entity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import sopt.org.motivooServer.domain.health.exception.HealthException; | ||
|
||
import java.util.Arrays; | ||
|
||
import static sopt.org.motivooServer.domain.health.exception.HealthExceptionType.INVALID_EXERCISE_TIME; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum ExerciseTime { | ||
|
||
// 30분 미만 | 30분~1시간 | 1시간~2시간 | 2시간 이상 | ||
LESS_THAN_HALFHOUR("30분 미만"), | ||
HALFHOUR_TO_ONEHOUR("30분~1시간"), | ||
ONEHOUR_TO_TWOHOURS("1시간~2시간"), | ||
TWOHOURS_OR_MORE("2시간 이상"); | ||
|
||
private final String value; | ||
|
||
public static ExerciseTime of(String value) { | ||
return Arrays.stream(ExerciseTime.values()) | ||
.filter(exerciseTime -> value.equals(exerciseTime.value)) | ||
.findFirst() | ||
.orElseThrow(() -> new HealthException(INVALID_EXERCISE_TIME)); | ||
} | ||
|
||
} |
21 changes: 20 additions & 1 deletion
21
src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
package sopt.org.motivooServer.domain.health.entity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import sopt.org.motivooServer.domain.health.exception.HealthException; | ||
|
||
import java.util.Arrays; | ||
|
||
import static sopt.org.motivooServer.domain.health.exception.HealthExceptionType.*; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum ExerciseType { | ||
HIGH_LEVEL("고강도"), | ||
MEDIUM_LEVEL("중강도"), | ||
LOW_LEVEL("저강도") | ||
; | ||
private final String value; | ||
|
||
// 고강도 | 중강도 | 저강도 | ||
public static ExerciseType of(String value) { | ||
return Arrays.stream(ExerciseType.values()) | ||
.filter(exerciseType -> value.equals(exerciseType.value)) | ||
.findFirst() | ||
.orElseThrow(() -> new HealthException(INVALID_EXERCISE_TYPE)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
src/main/java/sopt/org/motivooServer/domain/health/repository/HealthRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package sopt.org.motivooServer.domain.health.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import sopt.org.motivooServer.domain.health.entity.Health; | ||
import sopt.org.motivooServer.domain.user.entity.User; | ||
|
||
public interface HealthRepository extends JpaRepository<Health, Long> { | ||
import java.util.Optional; | ||
|
||
public interface HealthRepository extends JpaRepository<Health, Long> { | ||
Optional<Health> findByUser(User user); | ||
Optional<Health> findByUserId(Long userId); | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/sopt/org/motivooServer/domain/health/service/CalculateScore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package sopt.org.motivooServer.domain.health.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import sopt.org.motivooServer.domain.health.entity.ExerciseFrequency; | ||
import sopt.org.motivooServer.domain.health.entity.ExerciseTime; | ||
import sopt.org.motivooServer.domain.health.entity.ExerciseType; | ||
|
||
@Service | ||
public class CalculateScore { | ||
public double calculate(boolean isExercise, ExerciseType type, | ||
ExerciseFrequency frequency, ExerciseTime time){ | ||
double exerciseScore = getExerciseScore(isExercise, type); | ||
double frequencyScore = getFrequencyScore(frequency); | ||
double timeScore = getTimeScore(time); | ||
|
||
return exerciseScore+frequencyScore+timeScore; | ||
} | ||
private double getExerciseScore(boolean isExercise, ExerciseType type) { | ||
if(!isExercise){ | ||
switch (type) { | ||
case HIGH_LEVEL: | ||
return 4.2; | ||
case MEDIUM_LEVEL: | ||
return 2.1; | ||
default: | ||
return 1.05; | ||
} | ||
} | ||
switch (type) { | ||
case HIGH_LEVEL: | ||
return 6; | ||
case MEDIUM_LEVEL: | ||
return 3; | ||
default: | ||
return 1.5; | ||
} | ||
} | ||
private double getFrequencyScore(ExerciseFrequency frequency) { | ||
switch (frequency) { | ||
case LESS_THAN_ONCE: | ||
return 1.0; | ||
case ONCE_OR_TWICE: | ||
return 2.0; | ||
case THREE_OR_FOUR_TIMES: | ||
return 3.0; | ||
default: | ||
return 4.0; | ||
} | ||
} | ||
private double getTimeScore(ExerciseTime time) { | ||
switch (time) { | ||
case LESS_THAN_HALFHOUR: | ||
return 1.0; | ||
case HALFHOUR_TO_ONEHOUR: | ||
return 2.0; | ||
case ONEHOUR_TO_TWOHOURS: | ||
return 3.0; | ||
default: | ||
return 4.0; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.