From 00e33466a3a1667f719900826ad561e938c36779 Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Thu, 9 May 2024 21:38:16 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20feature:=20Region=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=20Repository=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waither/userservice/entity/Region.java | 37 +++++++++++++++++++ .../repository/RegionRepository.java | 7 ++++ .../repository/SurveyRepository.java | 7 ++++ .../repository/UserDataRepository.java | 7 ++++ .../repository/UserMedianRepository.java | 7 ++++ 5 files changed, 65 insertions(+) create mode 100644 user-service/src/main/java/com/waither/userservice/entity/Region.java create mode 100644 user-service/src/main/java/com/waither/userservice/repository/RegionRepository.java create mode 100644 user-service/src/main/java/com/waither/userservice/repository/SurveyRepository.java create mode 100644 user-service/src/main/java/com/waither/userservice/repository/UserDataRepository.java create mode 100644 user-service/src/main/java/com/waither/userservice/repository/UserMedianRepository.java diff --git a/user-service/src/main/java/com/waither/userservice/entity/Region.java b/user-service/src/main/java/com/waither/userservice/entity/Region.java new file mode 100644 index 00000000..f906396b --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/entity/Region.java @@ -0,0 +1,37 @@ +package com.waither.userservice.entity; + +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.ColumnDefault; + +@Builder +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Table(name = "region") +@Entity +public class Region { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + // 지역명 (String으로) + @Column(name = "region_name") + private String regionName; + + // 경도 + @Column(name = "longitude") + private double longitude; + + // 위도 + @Column(name = "latitude") + private double latitude; + + public void update(String newRegionName, double newLongitude, double newLatitude) { + regionName = newRegionName; + longitude = newLongitude; + latitude = newLatitude; + } + +} diff --git a/user-service/src/main/java/com/waither/userservice/repository/RegionRepository.java b/user-service/src/main/java/com/waither/userservice/repository/RegionRepository.java new file mode 100644 index 00000000..6206145d --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/repository/RegionRepository.java @@ -0,0 +1,7 @@ +package com.waither.userservice.repository; + +import com.waither.userservice.entity.Region; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RegionRepository extends JpaRepository { +} diff --git a/user-service/src/main/java/com/waither/userservice/repository/SurveyRepository.java b/user-service/src/main/java/com/waither/userservice/repository/SurveyRepository.java new file mode 100644 index 00000000..9c5c004f --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/repository/SurveyRepository.java @@ -0,0 +1,7 @@ +package com.waither.userservice.repository; + +import com.waither.userservice.entity.Survey; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface SurveyRepository extends JpaRepository { +} diff --git a/user-service/src/main/java/com/waither/userservice/repository/UserDataRepository.java b/user-service/src/main/java/com/waither/userservice/repository/UserDataRepository.java new file mode 100644 index 00000000..2d2737c4 --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/repository/UserDataRepository.java @@ -0,0 +1,7 @@ +package com.waither.userservice.repository; + +import com.waither.userservice.entity.UserData; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserDataRepository extends JpaRepository { +} diff --git a/user-service/src/main/java/com/waither/userservice/repository/UserMedianRepository.java b/user-service/src/main/java/com/waither/userservice/repository/UserMedianRepository.java new file mode 100644 index 00000000..65094643 --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/repository/UserMedianRepository.java @@ -0,0 +1,7 @@ +package com.waither.userservice.repository; + +import com.waither.userservice.entity.UserMedian; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserMedianRepository extends JpaRepository { +} From f1a4f779faf9d606ea366dd0055170a0d441b74a Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Thu, 9 May 2024 21:38:56 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9C=A8=20feature:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=84=A4=EC=A0=95=20API=20GET=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AccountsController.java | 9 ++- .../controller/SettingController.java | 61 ++++++++++++--- .../dto/converter/AccountConverter.java | 6 +- .../dto/converter/SettingConverter.java | 76 +++++++++++++++++++ .../dto/request/AccountReqDto.java | 2 + .../dto/request/SettingReqDto.java | 9 ++- .../dto/response/SettingResDto.java | 41 ++++++++++ .../waither/userservice/entity/Setting.java | 31 +++----- .../com/waither/userservice/entity/User.java | 31 ++++++-- .../userservice/service/AccountsService.java | 35 +++++++-- .../userservice/service/EmailService.java | 2 +- .../QueryService/SettingQueryService.java | 44 +++++++++++ .../userservice/service/SettingService.java | 56 +++++++------- 13 files changed, 323 insertions(+), 80 deletions(-) create mode 100644 user-service/src/main/java/com/waither/userservice/dto/converter/SettingConverter.java create mode 100644 user-service/src/main/java/com/waither/userservice/service/QueryService/SettingQueryService.java diff --git a/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java b/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java index 40d8ffe3..3ca0094e 100644 --- a/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java +++ b/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java @@ -89,9 +89,10 @@ public ApiResponse updatePassword(@AuthUser User user, } - // Todo : 삭제 다시 ; soft delete로 변경 예정 - @GetMapping("/emails/delete") - public void deleteUser(@RequestParam Long userId) { - accountsService.deleteUser(userId); + // Todo : soft delete로 변경 고려 + @GetMapping("/delete") + public ApiResponse deleteUser(@AuthUser User user) { + accountsService.deleteUser(user); + return ApiResponse.onSuccess("로그아웃이 성공적으로 완료되었습니다."); } } diff --git a/user-service/src/main/java/com/waither/userservice/controller/SettingController.java b/user-service/src/main/java/com/waither/userservice/controller/SettingController.java index cdc39922..411c7ca9 100644 --- a/user-service/src/main/java/com/waither/userservice/controller/SettingController.java +++ b/user-service/src/main/java/com/waither/userservice/controller/SettingController.java @@ -1,9 +1,11 @@ package com.waither.userservice.controller; import com.waither.userservice.dto.request.SettingReqDto; +import com.waither.userservice.dto.response.SettingResDto; import com.waither.userservice.entity.User; import com.waither.userservice.global.annotation.AuthUser; import com.waither.userservice.global.response.ApiResponse; +import com.waither.userservice.service.QueryService.SettingQueryService; import com.waither.userservice.service.SettingService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -16,24 +18,25 @@ public class SettingController { private final SettingService settingService; + private final SettingQueryService settingQueryService; // 사용자 맞춤 서비스 제공 @PatchMapping("/custom") - public ApiResponse customUpdate(@AuthUser User user, @RequestBody SettingReqDto.CustomDto customDto) { + public ApiResponse updateCustom(@AuthUser User user, @RequestBody SettingReqDto.CustomDto customDto) { settingService.updateBooleanSetting(user, "CUSTOM", customDto.custom()); return ApiResponse.onSuccess("사용자 맞춤 서비스 제공이 " + customDto.custom() + "로 바뀌었습니다."); } // 외출 알림 설정 @PatchMapping("/noti/out-alert") - public ApiResponse outAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.OutAlertDto outAlertDto) { + public ApiResponse updateOutAlert(@AuthUser User user, @RequestBody SettingReqDto.OutAlertDto outAlertDto) { settingService.updateBooleanSetting(user, "OUT_ALERT" , outAlertDto.outAlert()); return ApiResponse.onSuccess("외출 알림 설정이 " + outAlertDto.outAlert() + "로 바뀌었습니다."); } // 알림 설정 (요일 & 시간) @PatchMapping("/noti/out-alert-set") - public ApiResponse outAlertSetUpdate(@AuthUser User user, @RequestBody SettingReqDto.OutAlertSetDto outAlertSetDto) { + public ApiResponse updateOutAlertSet(@AuthUser User user, @RequestBody SettingReqDto.OutAlertSetDto outAlertSetDto) { settingService.updateOutAlertSet(user, outAlertSetDto); return ApiResponse.onSuccess( outAlertSetDto.days() + "요일, " @@ -42,28 +45,28 @@ public ApiResponse outAlertSetUpdate(@AuthUser User user, @RequestBody S // 기상 특보 알림 설정 @PatchMapping("/noti/climate-alert") - public ApiResponse climateAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.ClimateAlertDto climateAlertDto) { + public ApiResponse updateClimateAlert(@AuthUser User user, @RequestBody SettingReqDto.ClimateAlertDto climateAlertDto) { settingService.updateBooleanSetting(user, "CUSTOM", climateAlertDto.climateAlert()); return ApiResponse.onSuccess("기상 특보 알림 설정이 " + climateAlertDto.climateAlert() + "로 바뀌었습니다."); } // 사용자 맞춤 예보 설정 @PatchMapping("/noti/user-alert") - public ApiResponse userAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.UserAlertDto userAlertDto) { + public ApiResponse updateUserAlert(@AuthUser User user, @RequestBody SettingReqDto.UserAlertDto userAlertDto) { settingService.updateBooleanSetting(user, "USER_ALERT", userAlertDto.userAlert()); return ApiResponse.onSuccess("사용자 맞춤 예보 설정이 " + userAlertDto.userAlert() + "로 바뀌었습니다."); } // 강설 정보 알림 설정 @PatchMapping("/noti/snow-alert") - public ApiResponse snowAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.SnowAlertDto snowAlertDto) { + public ApiResponse updateSnowAlert(@AuthUser User user, @RequestBody SettingReqDto.SnowAlertDto snowAlertDto) { settingService.updateBooleanSetting(user, "SNOW_ALERT", snowAlertDto.snowAlert()); return ApiResponse.onSuccess("강설 정보 알림 설정이 " + snowAlertDto.snowAlert() + "로 바뀌었습니다."); } // 바람 세기 알림 @PatchMapping("/noti/wind") - public ApiResponse windUpdate(@AuthUser User user, @RequestBody SettingReqDto.WindDto windDto) { + public ApiResponse updateWind(@AuthUser User user, @RequestBody SettingReqDto.WindDto windDto) { settingService.updateWind(user, windDto); return ApiResponse.onSuccess( "바람 세기 알림 설정이 " + windDto.windAlert() + "로 바뀌었습니다. " @@ -72,7 +75,7 @@ public ApiResponse windUpdate(@AuthUser User user, @RequestBody SettingR // 메인 화면 날씨 상세 정보 보기 (강수량, 퓽향/풍속, 미세먼지) @PatchMapping("/display") - public ApiResponse displayUpdate(@AuthUser User user, @RequestBody SettingReqDto.DisplayDto displayDto) { + public ApiResponse updateDisplay(@AuthUser User user, @RequestBody SettingReqDto.DisplayDto displayDto) { settingService.updateDisplay(user, displayDto); return ApiResponse.onSuccess( "강수량 보기는 " + displayDto.precipitation() + "로, " @@ -81,14 +84,54 @@ public ApiResponse displayUpdate(@AuthUser User user, @RequestBody Setti + "설정되었습니다."); } + // 직장 지역 설정 + @PatchMapping("/region") + public ApiResponse updateRegion(@AuthUser User user, @RequestBody SettingReqDto.RegionDto regionDto) { + settingService.updateRegion(user, regionDto); + return ApiResponse.onSuccess("직장 지역 설정이 " + regionDto.regionName() + "로 바뀌었습니다."); + } + // 직장 지역 레포트 알림 받기 @PatchMapping("/region-report") - public ApiResponse regionReportUpdate(@AuthUser User user, @RequestBody SettingReqDto.regionReportDto regionReportDto) { + public ApiResponse updateRegionReport(@AuthUser User user, @RequestBody SettingReqDto.RegionReportDto regionReportDto) { settingService.updateBooleanSetting(user, "REGION_REPORT", regionReportDto.regionReport()); return ApiResponse.onSuccess("직장 지역 레포트 알림 설정이 " + regionReportDto.regionReport() + "로 바뀌었습니다."); } + // ReadOnly (GET) + @GetMapping("/custom") + public ApiResponse getUserCustom(@AuthUser User user) { + return ApiResponse.onSuccess(settingQueryService.getUserCustom(user)); + } + @GetMapping("/region") + public ApiResponse getRegion(@AuthUser User user) { + return ApiResponse.onSuccess(settingQueryService.getRegion(user)); + } + @GetMapping("/noti") + public ApiResponse getNotification(@AuthUser User user) { + return ApiResponse.onSuccess(settingQueryService.getNotification(user)); + } + + @GetMapping("/noti/wind") + public ApiResponse getWind(@AuthUser User user) { + return ApiResponse.onSuccess(settingQueryService.getWind(user)); + } + + @GetMapping("/display") + public ApiResponse getDisplay(@AuthUser User user) { + return ApiResponse.onSuccess(settingQueryService.getDisplay(user)); + } + + @GetMapping("/user-weight") + public ApiResponse getWeight(@AuthUser User user) { + return ApiResponse.onSuccess(settingQueryService.getWeight(user)); + } + + @GetMapping("/mypage") + public ApiResponse getUserInfo(@AuthUser User user) { + return ApiResponse.onSuccess(settingQueryService.getUserInfo(user)); + } } diff --git a/user-service/src/main/java/com/waither/userservice/dto/converter/AccountConverter.java b/user-service/src/main/java/com/waither/userservice/dto/converter/AccountConverter.java index 4dd83c9f..9cbef719 100644 --- a/user-service/src/main/java/com/waither/userservice/dto/converter/AccountConverter.java +++ b/user-service/src/main/java/com/waither/userservice/dto/converter/AccountConverter.java @@ -1,13 +1,12 @@ package com.waither.userservice.dto.converter; import com.waither.userservice.dto.request.AccountReqDto; -import com.waither.userservice.entity.Setting; import com.waither.userservice.entity.User; import com.waither.userservice.entity.type.UserStatus; public class AccountConverter { - public static User toCreateUser(AccountReqDto.RegisterRequestDto requestDto, String encodedPw) { + public static User toUser(AccountReqDto.RegisterRequestDto requestDto, String encodedPw) { return User.builder() .email(requestDto.email()) .password(encodedPw) @@ -15,7 +14,8 @@ public static User toCreateUser(AccountReqDto.RegisterRequestDto requestDto, Str .status(UserStatus.ACTIVE) .role("ROLE_USER") .custom(true) - .setting(Setting.builder().build()) .build(); } + + } diff --git a/user-service/src/main/java/com/waither/userservice/dto/converter/SettingConverter.java b/user-service/src/main/java/com/waither/userservice/dto/converter/SettingConverter.java new file mode 100644 index 00000000..4eca7d08 --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/dto/converter/SettingConverter.java @@ -0,0 +1,76 @@ +package com.waither.userservice.dto.converter; + +import com.waither.userservice.dto.response.SettingResDto; +import com.waither.userservice.entity.Setting; +import com.waither.userservice.entity.User; + +import java.time.DayOfWeek; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SettingConverter { + + public static SettingResDto.CustomDto toCustomDto(User user) { + return new SettingResDto.CustomDto(user.isCustom()); + } + + public static SettingResDto.RegionNameDto toRegionNameDto(Setting setting) { + return new SettingResDto.RegionNameDto(setting.getRegion().getRegionName()); + } + + public static SettingResDto.NotificationDto toNotificationDto(Setting setting) { + List days = Stream.of( + new AbstractMap.SimpleEntry<>(DayOfWeek.SUNDAY, setting.isSun()), + new AbstractMap.SimpleEntry<>(DayOfWeek.MONDAY, setting.isMon()), + new AbstractMap.SimpleEntry<>(DayOfWeek.TUESDAY, setting.isTue()), + new AbstractMap.SimpleEntry<>(DayOfWeek.WEDNESDAY, setting.isWed()), + new AbstractMap.SimpleEntry<>(DayOfWeek.THURSDAY, setting.isThu()), + new AbstractMap.SimpleEntry<>(DayOfWeek.FRIDAY, setting.isFri()), + new AbstractMap.SimpleEntry<>(DayOfWeek.SATURDAY, setting.isSat()) + ) + .filter(Map.Entry::getValue) + .map(entry -> entry.getKey().toString()) + .collect(Collectors.toList()); + + return new SettingResDto.NotificationDto( + setting.isOutAlert(), + days, + setting.getOutTime(), + setting.isClimateAlert(), + setting.isUserAlert(), + setting.isSnowAlert() + ); + } + + public static SettingResDto.WindDto toWindDto(Setting setting) { + return new SettingResDto.WindDto( + setting.isWindAlert(), + setting.getWindDegree() + ); + } + + public static SettingResDto.DisplayDto toDisplayDto(Setting setting) { + return new SettingResDto.DisplayDto( + setting.isPrecipitation(), + setting.isWind(), + setting.isDust() + ); + } + + public static SettingResDto.WeightDto toWeightDto(Setting setting) { + return new SettingResDto.WeightDto( + setting.getWeight() + ); + } + + public static SettingResDto.UserInfoDto toUserInfoDto(User user) { + return new SettingResDto.UserInfoDto( + user.getEmail(), + user.getNickname() + ); + } + +} diff --git a/user-service/src/main/java/com/waither/userservice/dto/request/AccountReqDto.java b/user-service/src/main/java/com/waither/userservice/dto/request/AccountReqDto.java index 07f20de6..6c44a428 100644 --- a/user-service/src/main/java/com/waither/userservice/dto/request/AccountReqDto.java +++ b/user-service/src/main/java/com/waither/userservice/dto/request/AccountReqDto.java @@ -1,5 +1,7 @@ package com.waither.userservice.dto.request; +import com.waither.userservice.entity.User; +import com.waither.userservice.entity.type.UserStatus; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; diff --git a/user-service/src/main/java/com/waither/userservice/dto/request/SettingReqDto.java b/user-service/src/main/java/com/waither/userservice/dto/request/SettingReqDto.java index 775c6aad..590de9cf 100644 --- a/user-service/src/main/java/com/waither/userservice/dto/request/SettingReqDto.java +++ b/user-service/src/main/java/com/waither/userservice/dto/request/SettingReqDto.java @@ -41,7 +41,14 @@ public record DisplayDto( boolean dust ) {} - public record regionReportDto( + public record RegionDto( + String regionName, + double longitude, + double latitude + + ) { } + + public record RegionReportDto( boolean regionReport ) { } diff --git a/user-service/src/main/java/com/waither/userservice/dto/response/SettingResDto.java b/user-service/src/main/java/com/waither/userservice/dto/response/SettingResDto.java index 0b0917a3..4cbb54f3 100644 --- a/user-service/src/main/java/com/waither/userservice/dto/response/SettingResDto.java +++ b/user-service/src/main/java/com/waither/userservice/dto/response/SettingResDto.java @@ -1,4 +1,45 @@ package com.waither.userservice.dto.response; +import java.time.LocalTime; +import java.util.List; + public class SettingResDto { + + public record CustomDto( + boolean custom + ) { } + + public record RegionNameDto( + String regionName + ) { } + + public record NotificationDto( + boolean outAlert, + List days, + LocalTime outTime, + boolean climateAlert, + boolean userAlert, + boolean snowAlert + ) { } + + public record WindDto( + boolean windAlert, + Integer windDegree + ) { } + + public record DisplayDto( + boolean rainfallDisplay, + boolean windDisplay, + boolean dustDisplay + ) { } + + public record WeightDto( + Double weight + ) { } + + public record UserInfoDto( + String email, + String nickname + ) { } + } diff --git a/user-service/src/main/java/com/waither/userservice/entity/Setting.java b/user-service/src/main/java/com/waither/userservice/entity/Setting.java index a1a2eb88..3dbaae2b 100644 --- a/user-service/src/main/java/com/waither/userservice/entity/Setting.java +++ b/user-service/src/main/java/com/waither/userservice/entity/Setting.java @@ -25,14 +25,8 @@ public class Setting { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - // 사용자 맞춤 서비스 제공 - @Column(name = "custom") - @ColumnDefault("true") - private boolean custom; - // 외출 알림 @Column(name = "outAlert") - @ColumnDefault("false") private boolean outAlert; // 외출 시간 @@ -41,71 +35,64 @@ public class Setting { // 월 ~ 금 알림 @Column(name = "sun") - @ColumnDefault("false") private boolean sun; @Column(name = "mon") - @ColumnDefault("false") private boolean mon; @Column(name = "tue") - @ColumnDefault("false") private boolean tue; @Column(name = "wed") - @ColumnDefault("false") private boolean wed; @Column(name = "thu") - @ColumnDefault("false") private boolean thu; @Column(name = "fri") - @ColumnDefault("false") private boolean fri; @Column(name = "sat") - @ColumnDefault("false") private boolean sat; // 기상 특보 알림 @Column(name = "climateAlert") - @ColumnDefault("true") private boolean climateAlert; // 사용자 맞춤 예보 받기 @Column(name = "userAlert") - @ColumnDefault("true") private boolean userAlert; // 강설 정보 알림 @Column(name = "snowAlert") - @ColumnDefault("true") private boolean snowAlert; // 바람 세기 알림 @Column(name = "windAlert") - @ColumnDefault("true") private boolean windAlert; // 바람세기 정도 @Column(name = "windDegree") - @ColumnDefault("10") private Integer windDegree; // 직장 지역 레포트 알림 받기 @Column(name = "regionReport") - @ColumnDefault("true") private boolean regionReport; // 강수량 보기 @Column(name = "precipitation") - @ColumnDefault("true") private boolean precipitation; // 풍량/풍속 보기 @Column(name = "wind") - @ColumnDefault("true") private boolean wind; // 미세먼지 보기 @Column(name = "dust") - @ColumnDefault("true") private boolean dust; + // 사용자 가중치 + @Column(name = "weight") + private Double weight; + + // Mapping + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumn(name = "region_id", unique = true) + private Region region; + // Id에 Setter 쓰지 않기 위해, 명시적으로 지정 public void setId(Long id) { } diff --git a/user-service/src/main/java/com/waither/userservice/entity/User.java b/user-service/src/main/java/com/waither/userservice/entity/User.java index 0007f178..b4807a99 100644 --- a/user-service/src/main/java/com/waither/userservice/entity/User.java +++ b/user-service/src/main/java/com/waither/userservice/entity/User.java @@ -46,6 +46,17 @@ public class User extends BaseEntity { @Column(name = "custom", nullable = false) private boolean custom; + // Mapping + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumn(name = "setting_id", unique = true) + private Setting setting; + + @OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) + private UserData UserData; + + @OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) + private UserMedian UserMedian; + // 비밀번호 변경 public void setPassword(String password) { this.password = password; @@ -56,14 +67,20 @@ public void setNickname(String nickname) { this.nickname = nickname; } - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) - @JoinColumn(name = "setting_id", unique = true) - private Setting setting; + public void setCustom(boolean custom) { + this.custom = custom; + } - @OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) - private UserData UserData; + // 연관관계 설정 + public void setSetting(Setting setSetting) { + setting = setSetting; + } - @OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) - private UserMedian UserMedian; + public void setUserData(UserData setUserData) { + UserData = setUserData; + } + public void setUserMedian(UserMedian setUserMedian) { + UserMedian = setUserMedian; + } } diff --git a/user-service/src/main/java/com/waither/userservice/service/AccountsService.java b/user-service/src/main/java/com/waither/userservice/service/AccountsService.java index 2459b1fd..ff385b33 100644 --- a/user-service/src/main/java/com/waither/userservice/service/AccountsService.java +++ b/user-service/src/main/java/com/waither/userservice/service/AccountsService.java @@ -2,6 +2,7 @@ import com.waither.userservice.dto.converter.AccountConverter; import com.waither.userservice.dto.request.AccountReqDto; +import com.waither.userservice.entity.Region; import com.waither.userservice.entity.Setting; import com.waither.userservice.entity.User; import com.waither.userservice.jwt.dto.JwtDto; @@ -11,7 +12,7 @@ import com.waither.userservice.repository.UserRepository; import com.waither.userservice.global.exception.CustomException; import com.waither.userservice.global.response.ErrorCode; -import jakarta.transaction.Transactional; +import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -51,7 +52,31 @@ public void signup(AccountReqDto.RegisterRequestDto requestDto) { // } // 비밀번호 인코딩 String encodedPw = passwordEncoder.encode(requestDto.password()); - User newUser = AccountConverter.toCreateUser(requestDto, encodedPw); + User newUser = AccountConverter.toUser(requestDto, encodedPw); + + // Setting을 기본값으로 설정 + Setting defaultSetting = Setting.builder() + .climateAlert(true) + .userAlert(true) + .snowAlert(true) + .windAlert(true) + .windDegree(10) + .regionReport(true) + .precipitation(true) + .wind(true) + .dust(true) + .weight(0.0) + .build(); + + // Region 기본값으로 설정 + Region defaultRegion = Region.builder() + .regionName("서울시") + .longitude(37.5665) + .latitude(126.9780) + .build(); + + defaultSetting.setRegion(defaultRegion); + newUser.setSetting(defaultSetting); userRepository.save(newUser); } @@ -188,8 +213,8 @@ public void updateNickname(User user, String nickanme) { userRepository.save(user); } - public void deleteUser(Long userId){ - User userEntity = userRepository.findById(userId); - userRepository.delete(userEntity); + // 회원 삭제 + public void deleteUser(User user){ + userRepository.delete(user); } } diff --git a/user-service/src/main/java/com/waither/userservice/service/EmailService.java b/user-service/src/main/java/com/waither/userservice/service/EmailService.java index 937d99f9..bd49c5d5 100644 --- a/user-service/src/main/java/com/waither/userservice/service/EmailService.java +++ b/user-service/src/main/java/com/waither/userservice/service/EmailService.java @@ -5,7 +5,7 @@ import jakarta.mail.MessagingException; import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeMessage; -import jakarta.transaction.Transactional; +import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.mail.SimpleMailMessage; diff --git a/user-service/src/main/java/com/waither/userservice/service/QueryService/SettingQueryService.java b/user-service/src/main/java/com/waither/userservice/service/QueryService/SettingQueryService.java new file mode 100644 index 00000000..90739826 --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/service/QueryService/SettingQueryService.java @@ -0,0 +1,44 @@ +package com.waither.userservice.service.QueryService; + +import com.waither.userservice.dto.converter.SettingConverter; +import com.waither.userservice.dto.response.SettingResDto; +import com.waither.userservice.entity.User; +import org.springframework.transaction.annotation.Transactional; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class SettingQueryService { + + public SettingResDto.CustomDto getUserCustom(User user) { + return SettingConverter.toCustomDto(user); + } + public SettingResDto.RegionNameDto getRegion(User user){ + return SettingConverter.toRegionNameDto(user.getSetting()); + } + + public SettingResDto.NotificationDto getNotification(User user) { + return SettingConverter.toNotificationDto(user.getSetting()); + } + + public SettingResDto.WindDto getWind(User user) { + return SettingConverter.toWindDto(user.getSetting()); + } + + public SettingResDto.DisplayDto getDisplay(User user) { + return SettingConverter.toDisplayDto(user.getSetting()); + } + + public SettingResDto.WeightDto getWeight(User user) { + return SettingConverter.toWeightDto(user.getSetting()); + } + + public SettingResDto.UserInfoDto getUserInfo(User user) { + return SettingConverter.toUserInfoDto(user); + } + +} diff --git a/user-service/src/main/java/com/waither/userservice/service/SettingService.java b/user-service/src/main/java/com/waither/userservice/service/SettingService.java index 07dbc32e..5bc3a758 100644 --- a/user-service/src/main/java/com/waither/userservice/service/SettingService.java +++ b/user-service/src/main/java/com/waither/userservice/service/SettingService.java @@ -1,12 +1,14 @@ package com.waither.userservice.service; import com.waither.userservice.dto.request.SettingReqDto; +import com.waither.userservice.entity.Region; import com.waither.userservice.entity.Setting; import com.waither.userservice.entity.User; import com.waither.userservice.global.exception.CustomException; import com.waither.userservice.global.response.ErrorCode; +import com.waither.userservice.repository.RegionRepository; import com.waither.userservice.repository.SettingRepository; -import jakarta.transaction.Transactional; +import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -14,8 +16,7 @@ import java.time.DayOfWeek; import java.util.EnumSet; import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.stream.Collectors; @Slf4j @Service @@ -24,18 +25,15 @@ public class SettingService { private final SettingRepository settingRepository; - - public Setting getUserSetting(User user) { - return user.getSetting(); - } + private final RegionRepository regionRepository; // 토글 설정 변경 public void updateBooleanSetting(User user, String settingType, Boolean value) { - Setting setting = getUserSetting(user); + Setting setting = user.getSetting(); switch (settingType) { // 사용자 맞춤 서비스 제공 설정 변경 case "CUSTOM": - setting.setCustom(value); + user.setCustom(value); break; // 외출 알림 설정 변경 case "OUT_ALERT": @@ -65,7 +63,7 @@ public void updateBooleanSetting(User user, String settingType, Boolean value) { // 바람 세기 알림 설정 변경 public void updateWind(User user, SettingReqDto.WindDto windDto) { - Setting setting = getUserSetting(user); + Setting setting = user.getSetting(); setting.setWindAlert(windDto.windAlert()); setting.setWindDegree(windDto.windDegree()); @@ -74,7 +72,7 @@ public void updateWind(User user, SettingReqDto.WindDto windDto) { // 메인 화면 날씨 상세 정보 변경 public void updateDisplay(User user, SettingReqDto.DisplayDto displayDto) { - Setting setting = getUserSetting(user); + Setting setting = user.getSetting(); setting.setPrecipitation(displayDto.precipitation()); setting.setWind(displayDto.wind()); @@ -82,9 +80,16 @@ public void updateDisplay(User user, SettingReqDto.DisplayDto displayDto) { settingRepository.save(setting); } + // 직장 지역 설정 + public void updateRegion(User user, SettingReqDto.RegionDto regionDto) { + Region region = user.getSetting().getRegion(); + region.update(regionDto.regionName(), regionDto.longitude(), regionDto.latitude()); + regionRepository.save(region); + } + // 알림 설정 변경 (요일 & 시간) public void updateOutAlertSet(User user, SettingReqDto.OutAlertSetDto outAlertSetDto) { - Setting setting = getUserSetting(user); + Setting setting = user.getSetting(); // 요일 설정 updateDays(setting, outAlertSetDto.days()); @@ -98,22 +103,17 @@ public void updateOutAlertSet(User user, SettingReqDto.OutAlertSetDto outAlertSe // 요일 설정 업데이트 private void updateDays(Setting setting, List days) { - boolean[] dayOfWeekFlags = new boolean[7]; // 요일 개수에 해당하는 배열 생성 - - // 선택된 요일만 true로 설정 - days.forEach(day -> { - DayOfWeek dayOfWeek = DayOfWeek.valueOf(day.toUpperCase()); - dayOfWeekFlags[dayOfWeek.ordinal()] = true; - }); - - // 각 요일에 대해 해당하는 필드를 설정 - setting.setSun(dayOfWeekFlags[DayOfWeek.SUNDAY.ordinal()]); - setting.setMon(dayOfWeekFlags[DayOfWeek.MONDAY.ordinal()]); - setting.setTue(dayOfWeekFlags[DayOfWeek.TUESDAY.ordinal()]); - setting.setWed(dayOfWeekFlags[DayOfWeek.WEDNESDAY.ordinal()]); - setting.setThu(dayOfWeekFlags[DayOfWeek.THURSDAY.ordinal()]); - setting.setFri(dayOfWeekFlags[DayOfWeek.FRIDAY.ordinal()]); - setting.setSat(dayOfWeekFlags[DayOfWeek.SATURDAY.ordinal()]); + EnumSet selectedDays = days.stream() + .map(day -> DayOfWeek.valueOf(day.toUpperCase())) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(DayOfWeek.class))); + + setting.setSun(selectedDays.contains(DayOfWeek.SUNDAY)); + setting.setMon(selectedDays.contains(DayOfWeek.MONDAY)); + setting.setTue(selectedDays.contains(DayOfWeek.TUESDAY)); + setting.setWed(selectedDays.contains(DayOfWeek.WEDNESDAY)); + setting.setThu(selectedDays.contains(DayOfWeek.THURSDAY)); + setting.setFri(selectedDays.contains(DayOfWeek.FRIDAY)); + setting.setSat(selectedDays.contains(DayOfWeek.SATURDAY)); settingRepository.save(setting); } From 77aee348326d8dfa0fac0c537a798bdfc1ccaa5b Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Thu, 9 May 2024 22:44:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20deleteUser?= =?UTF-8?q?=20HTTP=20Method=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waither/userservice/controller/AccountsController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java b/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java index 3ca0094e..023e0395 100644 --- a/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java +++ b/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java @@ -90,9 +90,9 @@ public ApiResponse updatePassword(@AuthUser User user, // Todo : soft delete로 변경 고려 - @GetMapping("/delete") + @DeleteMapping("/delete") public ApiResponse deleteUser(@AuthUser User user) { accountsService.deleteUser(user); - return ApiResponse.onSuccess("로그아웃이 성공적으로 완료되었습니다."); + return ApiResponse.onSuccess(user.getEmail() + "님의 계정이 성공적으로 탈퇴되었습니다."); } } From 420525cf7c1c889be4e45d6ca1abc4297ddf5f33 Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Thu, 9 May 2024 22:54:06 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20Setting=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20boolean=20=EA=B0=92=EC=97=90=20nu?= =?UTF-8?q?llable=20=3D=20false=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waither/userservice/entity/Setting.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/user-service/src/main/java/com/waither/userservice/entity/Setting.java b/user-service/src/main/java/com/waither/userservice/entity/Setting.java index 3dbaae2b..25afdb13 100644 --- a/user-service/src/main/java/com/waither/userservice/entity/Setting.java +++ b/user-service/src/main/java/com/waither/userservice/entity/Setting.java @@ -26,7 +26,7 @@ public class Setting { private Long id; // 외출 알림 - @Column(name = "outAlert") + @Column(name = "outAlert", nullable = false) private boolean outAlert; // 외출 시간 @@ -34,58 +34,58 @@ public class Setting { private LocalTime outTime; // 월 ~ 금 알림 - @Column(name = "sun") + @Column(name = "sun", nullable = false) private boolean sun; - @Column(name = "mon") + @Column(name = "mon", nullable = false) private boolean mon; - @Column(name = "tue") + @Column(name = "tue", nullable = false) private boolean tue; - @Column(name = "wed") + @Column(name = "wed", nullable = false) private boolean wed; - @Column(name = "thu") + @Column(name = "thu", nullable = false) private boolean thu; - @Column(name = "fri") + @Column(name = "fri", nullable = false) private boolean fri; - @Column(name = "sat") + @Column(name = "sat", nullable = false) private boolean sat; // 기상 특보 알림 - @Column(name = "climateAlert") + @Column(name = "climateAlert", nullable = false) private boolean climateAlert; // 사용자 맞춤 예보 받기 - @Column(name = "userAlert") + @Column(name = "userAlert", nullable = false) private boolean userAlert; // 강설 정보 알림 - @Column(name = "snowAlert") + @Column(name = "snowAlert", nullable = false) private boolean snowAlert; // 바람 세기 알림 - @Column(name = "windAlert") + @Column(name = "windAlert", nullable = false) private boolean windAlert; // 바람세기 정도 - @Column(name = "windDegree") + @Column(name = "windDegree", nullable = false) private Integer windDegree; // 직장 지역 레포트 알림 받기 - @Column(name = "regionReport") + @Column(name = "regionReport", nullable = false) private boolean regionReport; // 강수량 보기 - @Column(name = "precipitation") + @Column(name = "precipitation", nullable = false) private boolean precipitation; // 풍량/풍속 보기 - @Column(name = "wind") + @Column(name = "wind", nullable = false) private boolean wind; // 미세먼지 보기 - @Column(name = "dust") + @Column(name = "dust", nullable = false) private boolean dust; // 사용자 가중치 - @Column(name = "weight") + @Column(name = "weight", nullable = false) private Double weight; // Mapping