Skip to content

Commit

Permalink
♻️ refactor : 사용자 맞춤 서비스 제공 끌 경우 초기화 (#159)
Browse files Browse the repository at this point in the history
♻️ refactor : 사용자 맞춤 서비스 제공 끌 경우 초기화 (#159)
  • Loading branch information
jinho7 authored Jul 11, 2024
2 parents 390767d + 5bb46a5 commit f7c43d8
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class UserController {
private final UserService userService;

// 회원가입
@Operation(summary = "Sign Up", description = "회원가입")
@Operation(summary = "회원가입")
@PostMapping("/signup")
public ResponseEntity<ApiResponse<String>> register(@Valid @RequestBody UserReqDto.SignUpRequestDto requestDto) {
public ResponseEntity<ApiResponse<String>> signup(@Valid @RequestBody UserReqDto.SignUpRequestDto requestDto) {
userService.signup(requestDto);
// SignUp 때만 201 Created 사용
return ResponseEntity
Expand All @@ -35,6 +35,18 @@ public ResponseEntity<ApiResponse<String>> register(@Valid @RequestBody UserReqD
);
}

@Operation(summary = "로그인", description = "사용자 로그인을 수행합니다. (Swagger 문서용)")
@PostMapping("/login")
public ApiResponse<JwtDto> login(@RequestBody UserReqDto.LoginRequestDto loginRequestDto) {
return null; // 실제 구현은 Spring Security에서 처리
}

@Operation(summary = "로그아웃", description = "사용자 로그아웃을 수행합니다. (Swagger 문서용)")
@PostMapping("/logout")
public ApiResponse<Void> logout() {
return null; // 실제 구현은 Spring Security에서 처리
}

// Jwt 토큰 재발급
@GetMapping("/reissue")
public ApiResponse<JwtDto> reissueToken(@RequestHeader("RefreshToken") String refreshToken) {
Expand Down Expand Up @@ -89,24 +101,11 @@ public ApiResponse<String> updatePassword(@AuthUser User user,
return ApiResponse.onSuccess("비밀번호가 변경되었습니다.");
}


// Todo : soft delete로 변경 고려
@DeleteMapping("/delete")
public ApiResponse<String> deleteUser(@AuthUser User user) {
userService.deleteUser(user);
return ApiResponse.onSuccess(user.getEmail() + "님의 계정이 성공적으로 탈퇴되었습니다.");
}


@Operation(summary = "로그인", description = "사용자 로그인을 수행합니다. (Swagger 문서용)")
@PostMapping("/login")
public ApiResponse<JwtDto> login(@RequestBody UserReqDto.LoginRequestDto loginRequestDto) {
return null; // 실제 구현은 Spring Security에서 처리
}

@Operation(summary = "로그아웃", description = "사용자 로그아웃을 수행합니다. (Swagger 문서용)")
@PostMapping("/logout")
public ApiResponse<Void> logout() {
return null; // 실제 구현은 Spring Security에서 처리
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SettingConverter {

// Setting을 기본값으로 설정
public static Setting createSetting() {
// Setting을 기본값으로 설정
return Setting.builder()
.climateAlert(true)
.userAlert(true)
.snowAlert(true)
.windAlert(true)
.windDegree(10)
.regionReport(true)
.precipitation(true)
.wind(true)
.dust(true)
.weight(0.0)
.build();
}

public static SettingResDto.CustomDto toCustomDto(User user) {
return SettingResDto.CustomDto.builder()
.custom(user.isCustom())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,6 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SurveyConverter {

// UserData 기본값으로 설정
public static UserData createUserData(Season season) {
switch (season) {
case SPRING_AUTUMN:
return UserData.builder()
.level1(10.0)
.level2(17.0)
.level3(24.0)
.level4(27.0)
.level5(30.0)
.season(season)
.build();
case SUMMER:
return UserData.builder()
.level1(15.0)
.level2(24.0)
.level3(30.0)
.level4(33.0)
.level5(36.0)
.season(season)
.build();
case WINTER:
return UserData.builder()
.level1(-17.0)
.level2(-7.0)
.level3(0.0)
.level4(6.0)
.level5(12.0)
.season(season)
.build();
default:
throw new CustomException(ErrorCode.INVALID_SEASON);
}
}

// UserMedian 기본값으로 설정
public static UserMedian createUserMedian(UserData userData) {
return UserMedian.builder()
.medianOf1And2(calculateMedian(userData.getLevel1(), userData.getLevel2()))
.medianOf2And3(calculateMedian(userData.getLevel2(), userData.getLevel3()))
.medianOf3And4(calculateMedian(userData.getLevel3(), userData.getLevel4()))
.medianOf4And5(calculateMedian(userData.getLevel4(), userData.getLevel5()))
.season(userData.getSeason())
.build();
}

public static Survey toSurvey(SurveyReqDto.SurveyRequestDto surveyRequestDto, Double temp, Season season) {
return Survey.builder()
.temp(temp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.waither.userservice.converter;

import com.waither.userservice.dto.request.UserReqDto;
import com.waither.userservice.dto.response.KakaoResDto;
import com.waither.userservice.entity.User;
import com.waither.userservice.entity.enums.UserStatus;
import lombok.AccessLevel;
Expand All @@ -22,4 +23,15 @@ public static User toUser(UserReqDto.SignUpRequestDto requestDto, PasswordEncode
.build();
}

public static User toUser(KakaoResDto.UserInfoResponseDto userInfo) {
return User.builder()
.authId(userInfo.getId())
.nickname(userInfo.getKakaoAccount().getProfile().getNickName())
.email(userInfo.getKakaoAccount().getEmail())
.status(UserStatus.ACTIVE)
.custom(true)
.role("ROLE_USER")
.build();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public class Region extends BaseEntity {
@Column(name = "latitude")
private double latitude;

// Region 기본값으로 설정
public static Region createRegion() {
// Region 기본값으로 설정
return Region.builder()
.regionName("서울시")
.longitude(37.5665)
.latitude(126.9780)
.build();
}

public void update(String newRegionName, double newLongitude, double newLatitude) {
regionName = newRegionName;
longitude = newLongitude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ public class Setting extends BaseEntity {
@JoinColumn(name = "region_id", unique = true)
private Region region;

// Setting을 기본값으로 설정
public static Setting createSetting() {
// Setting을 기본값으로 설정
return Setting.builder()
.climateAlert(true)
.userAlert(true)
.snowAlert(true)
.windAlert(true)
.windDegree(10)
.regionReport(true)
.precipitation(true)
.wind(true)
.dust(true)
.weight(0.0)
.build();
}

// Id에 Setter 쓰지 않기 위해, 명시적으로 지정
public void setId(Long id) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.waither.userservice.global.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.time.LocalDateTime;

Expand Down Expand Up @@ -32,7 +34,7 @@ public class Survey extends BaseEntity {
@Enumerated(EnumType.STRING)
private Season season;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.*;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Entity
Expand Down Expand Up @@ -63,10 +64,13 @@ public class User extends BaseEntity {
private Setting setting;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UserData> UserData;
private List<Survey> surveys = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UserMedian> UserMedian;
private List<UserData> userData = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UserMedian> userMedian = new ArrayList<>();

// 비밀번호 변경
public void setPassword(String password) {
Expand All @@ -83,17 +87,21 @@ public void setCustom(boolean custom) {
this.custom = custom;
}


// 연관관계 설정
public void setSetting(Setting setSetting) {
setting = setSetting;
public void addSurvey(Survey survey) {
surveys.add(survey);
survey.setUser(this);
}

public void setSetting(Setting setting) {
this.setting = setting;
}

public void setUserData(List<UserData> userData) {
UserData = userData;
this.userData = userData;
}

public void setUserMedian(List<UserMedian> userMedian) {
UserMedian = userMedian;
this.userMedian = userMedian;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.waither.userservice.entity;

import com.waither.userservice.converter.SurveyConverter;
import com.waither.userservice.entity.enums.Season;
import com.waither.userservice.global.BaseEntity;
import com.waither.userservice.global.exception.CustomException;
import com.waither.userservice.global.response.ErrorCode;
import jakarta.persistence.*;
import lombok.*;

import java.util.Arrays;
import java.util.List;

@Builder
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -30,13 +34,60 @@ public class UserData extends BaseEntity {
@Enumerated(EnumType.STRING)
private Season season;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public void setUser(User user) {
this.user = user;
}

// UserData 기본값으로 설정
public static UserData createUserData(Season season) {
switch (season) {
case SPRING_AUTUMN:
return UserData.builder()
.level1(10.0)
.level2(17.0)
.level3(24.0)
.level4(27.0)
.level5(30.0)
.season(season)
.build();
case SUMMER:
return UserData.builder()
.level1(15.0)
.level2(24.0)
.level3(30.0)
.level4(33.0)
.level5(36.0)
.season(season)
.build();
case WINTER:
return UserData.builder()
.level1(-17.0)
.level2(-7.0)
.level3(0.0)
.level4(6.0)
.level5(12.0)
.season(season)
.build();
default:
throw new CustomException(ErrorCode.INVALID_SEASON);
}
}

public static List<UserData> createUserDataList(User user) {
return Arrays.stream(Season.values())
.map(season -> {
UserData userData = createUserData(season);
// 연관관계 설정
userData.setUser(user);
return userData;
})
.toList();
}

public Double getLevel(int level) {
return switch (level) {
case 1 -> level1;
Expand Down
Loading

0 comments on commit f7c43d8

Please sign in to comment.