Skip to content

Commit

Permalink
refactor: 유저 등급 클래스 이름 변경 - #57
Browse files Browse the repository at this point in the history
  • Loading branch information
bs-koo committed Jul 30, 2024
1 parent 99f7fd9 commit 598a5d3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.example.mutsideout_mju.dto.response.user;

import com.example.mutsideout_mju.entity.Grade;
import com.example.mutsideout_mju.entity.UserGrade;
import lombok.Builder;
import lombok.Getter;
import org.springframework.context.annotation.Profile;

@Getter
@Builder
public class ProfileResponseData {
private String email;
private String name;
private Grade grade;
private UserGrade userGrade;

public static ProfileResponseData of(String email, String name, Grade grade) {
public static ProfileResponseData of(String email, String name, UserGrade userGrade) {
return builder()
.email(email)
.grade(grade)
.userGrade(userGrade)
.name(name)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.example.mutsideout_mju.dto.response.user;

import com.example.mutsideout_mju.entity.Grade;
import com.example.mutsideout_mju.entity.UserGrade;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class UserGradeResponseDto {
private String name;
private Grade grade;
private UserGrade userGrade;

public static UserGradeResponseDto of(String name, Grade grade) {
public static UserGradeResponseDto of(String name, UserGrade userGrade) {
return UserGradeResponseDto.builder()
.name(name)
.grade(grade)
.userGrade(userGrade)
.build();
}

public static UserGradeResponseDto from(Grade grade) {
public static UserGradeResponseDto from(UserGrade userGrade) {
return UserGradeResponseDto.builder()
.grade(grade)
.userGrade(userGrade)
.build();
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/example/mutsideout_mju/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class User extends BaseEntity {
@Column(nullable = false)
private String password;
@Enumerated(EnumType.STRING)
private Grade grade;
private UserGrade userGrade;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UserSurvey> userSurveys;
Expand All @@ -36,8 +36,8 @@ public class User extends BaseEntity {
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Room> rooms;

public void setGrade(Grade grade) {
this.grade = grade;
public void setUserGrade(UserGrade userGrade) {
this.userGrade = userGrade;
}

public void setName(String name) {
Expand All @@ -48,13 +48,13 @@ public void setPassword(String password) {
this.password = password;
}

public Grade determineGrade(long count) {
public UserGrade determineGrade(long count) {
if (count >= 4) {
return Grade.TOMATO;
return UserGrade.TOMATO;
} else if (count >= 2) {
return Grade.BANANA;
return UserGrade.BANANA;
} else {
return Grade.AVOCADO;
return UserGrade.AVOCADO;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.mutsideout_mju.entity;

public enum Grade {
public enum UserGrade {
AVOCADO,
BANANA,
TOMATO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.example.mutsideout_mju.dto.request.user.UpdateUserDto;
import com.example.mutsideout_mju.dto.response.user.ProfileResponseData;
import com.example.mutsideout_mju.dto.response.user.UserGradeResponseDto;
import com.example.mutsideout_mju.entity.Grade;
import com.example.mutsideout_mju.entity.UserGrade;
import com.example.mutsideout_mju.entity.SurveyOption;
import com.example.mutsideout_mju.entity.User;
import com.example.mutsideout_mju.entity.UserSurvey;
Expand Down Expand Up @@ -37,19 +37,19 @@ public UserGradeResponseDto calculateUserGrade(User user) {
long count = userSurveyList.stream()
.filter(userSurvey -> isValidSurveyOption(userSurvey))
.count();
Grade grade = user.determineGrade(count);
UserGrade userGrade = user.determineGrade(count);

user.setGrade(grade);
user.setUserGrade(userGrade);
userRepository.save(user);

return UserGradeResponseDto.of(user.getName(), grade);
return UserGradeResponseDto.of(user.getName(), userGrade);
}

/**
* 유저 등급 반환
*/
public UserGradeResponseDto getUserGrade(User user) {
return UserGradeResponseDto.from(user.getGrade());
return UserGradeResponseDto.from(user.getUserGrade());
}

/**
Expand Down Expand Up @@ -94,7 +94,7 @@ public void updateUser(User user, UpdateUserDto updateUserDto) {
* 유저 전체 정보(이메일, 이름, 등급) 조회
*/
public ProfileResponseData getMyPage(User user){
ProfileResponseData profileResponseData = ProfileResponseData.of(user.getEmail(), user.getName(), user.getGrade());
ProfileResponseData profileResponseData = ProfileResponseData.of(user.getEmail(), user.getName(), user.getUserGrade());
return profileResponseData;
}

Expand Down

0 comments on commit 598a5d3

Please sign in to comment.