Skip to content

Commit

Permalink
♻️ refactor: @PatchMapping("/user-weight") 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jinho7 committed May 9, 2024
1 parent 403fe38 commit 7c48fa8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,51 @@ public class SettingController {
private final SettingService settingService;
private final SettingQueryService settingQueryService;

/* --------- ReadOnly (GET) <화면 별로 Response 구성> --------- */
// 사용자 맞춤 서비스 제공 조히
@GetMapping("/custom")
public ApiResponse<SettingResDto.CustomDto> getUserCustom(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getUserCustom(user));
}

// 직장 지역 설정 조회
@GetMapping("/region")
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));
}

// 바람 세기 설정 조회
@GetMapping("/noti/wind")
public ApiResponse<SettingResDto.WindDto> getWind(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getWind(user));
}

// 메인 화면 날씨 상세 정보 조회
@GetMapping("/display")
public ApiResponse<SettingResDto.DisplayDto> getDisplay(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getDisplay(user));
}

// 사용자 가중치 설정 조회
@GetMapping("/user-weight")
public ApiResponse<SettingResDto.WeightDto> getWeight(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getWeight(user));
}

// 마이페이지 조회
@GetMapping("/mypage")
public ApiResponse<SettingResDto.UserInfoDto> getUserInfo(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getUserInfo(user));
}

/* --------- Update (Patch) --------- */

// 사용자 맞춤 서비스 제공
@PatchMapping("/custom")
public ApiResponse<String> updateCustom(@AuthUser User user, @RequestBody SettingReqDto.CustomDto customDto) {
Expand Down Expand Up @@ -98,40 +143,11 @@ public ApiResponse<String> updateRegionReport(@AuthUser User user, @RequestBody
return ApiResponse.onSuccess("직장 지역 레포트 알림 설정이 " + regionReportDto.regionReport() + "로 바뀌었습니다.");
}

/* --------- ReadOnly (GET) --------- */
@GetMapping("/custom")
public ApiResponse<SettingResDto.CustomDto> getUserCustom(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getUserCustom(user));
}

@GetMapping("/region")
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));
}

@GetMapping("/noti/wind")
public ApiResponse<SettingResDto.WindDto> getWind(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getWind(user));
}

@GetMapping("/display")
public ApiResponse<SettingResDto.DisplayDto> getDisplay(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getDisplay(user));
}

@GetMapping("/user-weight")
public ApiResponse<SettingResDto.WeightDto> getWeight(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getWeight(user));
}

@GetMapping("/mypage")
public ApiResponse<SettingResDto.UserInfoDto> getUserInfo(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getUserInfo(user));
// 사용자 가중치 설정
@PatchMapping("/user-weight")
public ApiResponse<String> updateWeight(@AuthUser User user, @RequestBody SettingReqDto.WeightDto weightDto) {
settingService.updateWeight(user, weightDto);
return ApiResponse.onSuccess("사용자 가중치가 " + weightDto.weight() + "로 바뀌었습니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ public record RegionReportDto(
boolean regionReport
) { }

public record WeightDto(
Double weight
) { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ private void updateDays(Setting setting, List<String> days) {
settingRepository.save(setting);
}

public void updateWeight(User user, SettingReqDto.WeightDto weightDto) {
Setting setting = user.getSetting();
setting.setWeight(weightDto.weight());
settingRepository.save(setting);
}

}

0 comments on commit 7c48fa8

Please sign in to comment.