Skip to content

Commit

Permalink
♻️ refactor: 설문조사 내부 로직 수정 (#59)
Browse files Browse the repository at this point in the history
♻️ refactor: 설문조사 내부 로직 수정 (#59)
  • Loading branch information
jinho7 authored May 24, 2024
2 parents 014cd5e + 42fd300 commit 8508c91
Show file tree
Hide file tree
Showing 26 changed files with 320 additions and 190 deletions.
1 change: 0 additions & 1 deletion user-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:2.1.0'


}

dependencyManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ApiResponse<SettingResDto.RegionNameDto> getRegion(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getRegion(user));
}

// 알림 설정 조회
// // 알림 설정 조회
@GetMapping("/noti")
public ApiResponse<SettingResDto.NotificationDto> getNotification(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getNotification(user));
Expand Down Expand Up @@ -68,86 +68,80 @@ public ApiResponse<SettingResDto.UserInfoDto> getUserInfo(@AuthUser User user) {
// 사용자 맞춤 서비스 제공
@PutMapping("/custom")
public ApiResponse<String> updateCustom(@AuthUser User user, @RequestBody SettingReqDto.CustomDto customDto) {
settingService.updateBooleanSetting(user, "CUSTOM", customDto.custom());
return ApiResponse.onSuccess("사용자 맞춤 서비스 제공이 " + customDto.custom() + "로 바뀌었습니다.");
settingService.updateCustom(user, customDto);
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 메인 화면 날씨 상세 정보 보기 (강수량, 퓽향/풍속, 미세먼지)
@PatchMapping("/display")
public ApiResponse<String> updateDisplay(@AuthUser User user, @RequestBody SettingReqDto.DisplayDto displayDto) {
settingService.updateDisplay(user, displayDto);
return ApiResponse.onSuccess(
"설정값 변경이 완료되었습니다.");
}

// 외출 알림 설정
@PutMapping("/noti/out-alert")
public ApiResponse<String> updateOutAlert(@AuthUser User user, @RequestBody SettingReqDto.OutAlertDto outAlertDto) {
settingService.updateBooleanSetting(user, "OUT_ALERT" , outAlertDto.outAlert());
return ApiResponse.onSuccess("외출 알림 설정이 " + outAlertDto.outAlert() + "로 바뀌었습니다.");
settingService.updateOutAlert(user, outAlertDto);
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 알림 설정 (요일 & 시간)
@PutMapping("/noti/out-alert-set")
public ApiResponse<String> updateOutAlertSet(@AuthUser User user, @RequestBody SettingReqDto.OutAlertSetDto outAlertSetDto) {
settingService.updateOutAlertSet(user, outAlertSetDto);
return ApiResponse.onSuccess(
outAlertSetDto.days() + "요일, "
+ outAlertSetDto.outTime() + "시로 알림 설정이 바뀌었습니다.");
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 기상 특보 알림 설정
@PutMapping("/noti/climate-alert")
public ApiResponse<String> updateClimateAlert(@AuthUser User user, @RequestBody SettingReqDto.ClimateAlertDto climateAlertDto) {
settingService.updateBooleanSetting(user, "CUSTOM", climateAlertDto.climateAlert());
return ApiResponse.onSuccess("기상 특보 알림 설정이 " + climateAlertDto.climateAlert() + "로 바뀌었습니다.");
settingService.updateClimateAlert(user, climateAlertDto);
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 사용자 맞춤 예보 설정
@PutMapping("/noti/user-alert")
public ApiResponse<String> updateUserAlert(@AuthUser User user, @RequestBody SettingReqDto.UserAlertDto userAlertDto) {
settingService.updateBooleanSetting(user, "USER_ALERT", userAlertDto.userAlert());
return ApiResponse.onSuccess("사용자 맞춤 예보 설정이 " + userAlertDto.userAlert() + "로 바뀌었습니다.");
settingService.updateUserAlert(user, userAlertDto);
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 강설 정보 알림 설정
@PutMapping("/noti/snow-alert")
public ApiResponse<String> updateSnowAlert(@AuthUser User user, @RequestBody SettingReqDto.SnowAlertDto snowAlertDto) {
settingService.updateBooleanSetting(user, "SNOW_ALERT", snowAlertDto.snowAlert());
return ApiResponse.onSuccess("강설 정보 알림 설정이 " + snowAlertDto.snowAlert() + "로 바뀌었습니다.");
settingService.updateSnowAlert(user, snowAlertDto);
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 바람 세기 알림
@PutMapping("/noti/wind")
public ApiResponse<String> updateWind(@AuthUser User user, @RequestBody SettingReqDto.WindDto windDto) {
settingService.updateWind(user, windDto);
return ApiResponse.onSuccess(
"바람 세기 알림 설정이 " + windDto.windAlert() + "로 바뀌었습니다. "
+ "강도는 " + windDto.windDegree() + " m/s 이상 일 때 알림이 발송 됩니다.");
"설정값 변경이 완료되었습니다.");
}

// 메인 화면 날씨 상세 정보 보기 (강수량, 퓽향/풍속, 미세먼지)
@PutMapping("/display")
public ApiResponse<String> updateDisplay(@AuthUser User user, @RequestBody SettingReqDto.DisplayDto displayDto) {
settingService.updateDisplay(user, displayDto);
return ApiResponse.onSuccess(
"강수량 보기는 " + displayDto.precipitation() + "로, "
+ "풍향/풍속 보기는 " + displayDto.wind() + "로, "
+ "미세먼지 보기는 " + displayDto.dust() + "로 "
+ "설정되었습니다.");
// 직장 지역 레포트 알림 받기
@PutMapping("/region-report")
public ApiResponse<String> updateRegionReport(@AuthUser User user, @RequestBody SettingReqDto.RegionReportDto regionReportDto) {
settingService.updateRegionReport(user, regionReportDto);
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 직장 지역 설정
@PutMapping("/region")
public ApiResponse<String> updateRegion(@AuthUser User user, @RequestBody SettingReqDto.RegionDto regionDto) {
settingService.updateRegion(user, regionDto);
return ApiResponse.onSuccess("직장 지역 설정이 " + regionDto.regionName() + "로 바뀌었습니다.");
}

// 직장 지역 레포트 알림 받기
@PutMapping("/region-report")
public ApiResponse<String> updateRegionReport(@AuthUser User user, @RequestBody SettingReqDto.RegionReportDto regionReportDto) {
settingService.updateBooleanSetting(user, "REGION_REPORT", regionReportDto.regionReport());
return ApiResponse.onSuccess("직장 지역 레포트 알림 설정이 " + regionReportDto.regionReport() + "로 바뀌었습니다.");
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

// 사용자 가중치 설정
@PutMapping("/user-weight")
public ApiResponse<String> updateWeight(@AuthUser User user, @RequestBody SettingReqDto.WeightDto weightDto) {
settingService.updateWeight(user, weightDto);
return ApiResponse.onSuccess("사용자 가중치가 " + weightDto.weight() + "로 바뀌었습니다.");
return ApiResponse.onSuccess("설정값 변경이 완료되었습니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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.SurveyQueryService;
import com.waither.userservice.service.commandService.SurveyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -17,12 +16,16 @@
public class SurveyController {

private final SurveyService surveyService;
private final SurveyQueryService surveyQueryService;

@PostMapping("/submit")
public ApiResponse<String> createSurvey(@AuthUser User user, @RequestBody SurveyReqDto.SurveyRequestDto surveyRequestDto) {
surveyService.createSurvey(user, surveyRequestDto);
return ApiResponse.onSuccess("survey 생성완료");
}

// @PostMapping("/reset")
// public ApiResponse<String> resetServeyData(@AuthUser User user) {
// surveyService.resetSurveyData(user);
// return ApiResponse.onSuccess("사용자의 설문 정보를 초기화 하였습니다.");
// }

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.waither.userservice.converter;

import com.waither.userservice.entity.Region;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.experimental.UtilityClass;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RegionConverter {

// Region 기본값으로 설정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import com.waither.userservice.entity.Region;
import com.waither.userservice.entity.Setting;
import com.waither.userservice.entity.User;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.experimental.UtilityClass;

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;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SettingConverter {

// Setting을 기본값으로 설정
Expand Down Expand Up @@ -40,18 +43,9 @@ public static SettingResDto.RegionNameDto toRegionNameDto(Setting setting) {
}

public static SettingResDto.NotificationDto toNotificationDto(Setting setting) {
List<String> 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());
List<String> days = setting.getDays().stream()
.map(Enum::toString)
.toList();

return new SettingResDto.NotificationDto(
setting.isOutAlert(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import com.waither.userservice.dto.request.SurveyReqDto;
import com.waither.userservice.entity.*;
import com.waither.userservice.entity.type.Season;
import com.waither.userservice.entity.enums.Season;
import com.waither.userservice.global.exception.CustomException;
import com.waither.userservice.global.response.ErrorCode;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.experimental.UtilityClass;

import static com.waither.userservice.service.commandService.SurveyService.calculateMedian;
import static com.waither.userservice.util.CalculateUtil.calculateMedian;


@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SurveyConverter {

// UserData 기본값으로 설정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.waither.userservice.dto.request.UserReqDto;
import com.waither.userservice.entity.User;
import com.waither.userservice.entity.type.UserStatus;
import com.waither.userservice.entity.enums.UserStatus;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.experimental.UtilityClass;
import org.springframework.security.crypto.password.PasswordEncoder;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UserConverter {

public static User toUser(UserReqDto.SignUpRequestDto requestDto, PasswordEncoder passwordEncoder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public record SnowAlertDto(
) { }

public record WindDto(
boolean windAlert,
Boolean windAlert,
Integer windDegree
) { }

public record DisplayDto(
boolean precipitation,
boolean wind,
boolean dust
Boolean precipitation,
Boolean wind,
Boolean dust
) {}

public record RegionDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public record WindDto(
) { }

public record DisplayDto(
boolean rainfallDisplay,
boolean windDisplay,
boolean dustDisplay
boolean precipitation,
boolean wind,
boolean dust
) { }

public record WeightDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.waither.userservice.global.BaseEntity;
import jakarta.persistence.*;

import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.Set;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
Expand Down Expand Up @@ -35,20 +39,11 @@ public class Setting extends BaseEntity {
private LocalTime outTime;

// 월 ~ 금 알림
@Column(name = "sun", nullable = false)
private boolean sun;
@Column(name = "mon", nullable = false)
private boolean mon;
@Column(name = "tue", nullable = false)
private boolean tue;
@Column(name = "wed", nullable = false)
private boolean wed;
@Column(name = "thu", nullable = false)
private boolean thu;
@Column(name = "fri", nullable = false)
private boolean fri;
@Column(name = "sat", nullable = false)
private boolean sat;
@ElementCollection
@CollectionTable(name = "setting_days", joinColumns = @JoinColumn(name = "setting_id"))
@Column(name = "day")
@Enumerated(EnumType.STRING)
private Set<DayOfWeek> days = new HashSet<>();

// 기상 특보 알림
@Column(name = "climateAlert", nullable = false)
Expand Down Expand Up @@ -76,11 +71,9 @@ public class Setting extends BaseEntity {
// 강수량 보기
@Column(name = "precipitation", nullable = false)
private boolean precipitation;

// 풍량/풍속 보기
@Column(name = "wind", nullable = false)
private boolean wind;

// 미세먼지 보기
@Column(name = "dust", nullable = false)
private boolean dust;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.waither.userservice.entity;

import com.waither.userservice.entity.type.Season;
import com.waither.userservice.entity.enums.Season;
import com.waither.userservice.global.BaseEntity;
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDateTime;
import java.time.LocalTime;

@Builder
@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.waither.userservice.entity;

import com.waither.userservice.entity.type.UserStatus;
import com.waither.userservice.entity.enums.UserStatus;
import com.waither.userservice.global.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
Expand Down Expand Up @@ -80,11 +80,11 @@ public void setSetting(Setting setSetting) {
setting = setSetting;
}

public void setUserData(List<com.waither.userservice.entity.UserData> userData) {
public void setUserData(List<UserData> userData) {
UserData = userData;
}

public void setUserMedian(List<com.waither.userservice.entity.UserMedian> userMedian) {
public void setUserMedian(List<UserMedian> userMedian) {
UserMedian = userMedian;
}
}
Loading

0 comments on commit 8508c91

Please sign in to comment.