Skip to content

Commit

Permalink
✨ feat: 사용자 설정 API GET 기능 (#41)
Browse files Browse the repository at this point in the history
✨ feat: 사용자 설정 API GET 기능 (#41)
  • Loading branch information
jinho7 authored May 9, 2024
2 parents ad3723e + 420525c commit e8e6663
Show file tree
Hide file tree
Showing 18 changed files with 405 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ public ApiResponse<String> updatePassword(@AuthUser User user,
}


// Todo : 삭제 다시 ; soft delete로 변경 예정
@GetMapping("/emails/delete")
public void deleteUser(@RequestParam Long userId) {
accountsService.deleteUser(userId);
// Todo : soft delete로 변경 고려
@DeleteMapping("/delete")
public ApiResponse<String> deleteUser(@AuthUser User user) {
accountsService.deleteUser(user);
return ApiResponse.onSuccess(user.getEmail() + "님의 계정이 성공적으로 탈퇴되었습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,24 +18,25 @@
public class SettingController {

private final SettingService settingService;
private final SettingQueryService settingQueryService;

// 사용자 맞춤 서비스 제공
@PatchMapping("/custom")
public ApiResponse<String> customUpdate(@AuthUser User user, @RequestBody SettingReqDto.CustomDto customDto) {
public ApiResponse<String> 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<String> outAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.OutAlertDto outAlertDto) {
public ApiResponse<String> 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<String> outAlertSetUpdate(@AuthUser User user, @RequestBody SettingReqDto.OutAlertSetDto outAlertSetDto) {
public ApiResponse<String> updateOutAlertSet(@AuthUser User user, @RequestBody SettingReqDto.OutAlertSetDto outAlertSetDto) {
settingService.updateOutAlertSet(user, outAlertSetDto);
return ApiResponse.onSuccess(
outAlertSetDto.days() + "요일, "
Expand All @@ -42,28 +45,28 @@ public ApiResponse<String> outAlertSetUpdate(@AuthUser User user, @RequestBody S

// 기상 특보 알림 설정
@PatchMapping("/noti/climate-alert")
public ApiResponse<String> climateAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.ClimateAlertDto climateAlertDto) {
public ApiResponse<String> 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<String> userAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.UserAlertDto userAlertDto) {
public ApiResponse<String> 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<String> snowAlertUpdate(@AuthUser User user, @RequestBody SettingReqDto.SnowAlertDto snowAlertDto) {
public ApiResponse<String> 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<String> windUpdate(@AuthUser User user, @RequestBody SettingReqDto.WindDto windDto) {
public ApiResponse<String> updateWind(@AuthUser User user, @RequestBody SettingReqDto.WindDto windDto) {
settingService.updateWind(user, windDto);
return ApiResponse.onSuccess(
"바람 세기 알림 설정이 " + windDto.windAlert() + "로 바뀌었습니다. "
Expand All @@ -72,7 +75,7 @@ public ApiResponse<String> windUpdate(@AuthUser User user, @RequestBody SettingR

// 메인 화면 날씨 상세 정보 보기 (강수량, 퓽향/풍속, 미세먼지)
@PatchMapping("/display")
public ApiResponse<String> displayUpdate(@AuthUser User user, @RequestBody SettingReqDto.DisplayDto displayDto) {
public ApiResponse<String> updateDisplay(@AuthUser User user, @RequestBody SettingReqDto.DisplayDto displayDto) {
settingService.updateDisplay(user, displayDto);
return ApiResponse.onSuccess(
"강수량 보기는 " + displayDto.precipitation() + "로, "
Expand All @@ -81,14 +84,54 @@ public ApiResponse<String> displayUpdate(@AuthUser User user, @RequestBody Setti
+ "설정되었습니다.");
}

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

// 직장 지역 레포트 알림 받기
@PatchMapping("/region-report")
public ApiResponse<String> regionReportUpdate(@AuthUser User user, @RequestBody SettingReqDto.regionReportDto regionReportDto) {
public ApiResponse<String> 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<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));
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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)
.nickname("추워하는 곰탱이")
.status(UserStatus.ACTIVE)
.role("ROLE_USER")
.custom(true)
.setting(Setting.builder().build())
.build();
}


}
Original file line number Diff line number Diff line change
@@ -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<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());

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()
);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) { }

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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
) { }

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading

0 comments on commit e8e6663

Please sign in to comment.