Skip to content

Commit

Permalink
[fix] : 코드리뷰 기반 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
realisshomyang committed Feb 13, 2024
1 parent 4bc13ee commit 5c3bff0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import com.onnoff.onnoff.domain.user.User;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.time.DayOfWeek;
import java.time.LocalTime;

@Entity
@Getter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class PushNotificationSetting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
@RequiredArgsConstructor
public class PushNotificationSettingService {
public final PushNotificationSettingRepository pushNotificationSettingRepository;

@Transactional
public PushNotificationSettingResponseDTO setPushNotification(PushNotificationSettingRequestDTO pushNotificationSettingRequestDTO){
public PushNotificationSettingResponseDTO setPushNotification(PushNotificationSettingRequestDTO pushNotificationSettingRequestDTO) {
User user = UserContext.getUser();
Optional<PushNotificationSetting> pushNotificationSetting = pushNotificationSettingRepository.findByUser(user);
if (pushNotificationSetting.isPresent()){
pushNotificationSetting.get().setPushNotification(pushNotificationSettingRequestDTO);
pushNotificationSettingRepository.save(pushNotificationSetting.get());
}
else {
pushNotificationSetting = Optional.ofNullable(PushNotificationConverter.toPushNotificationSetting(pushNotificationSettingRequestDTO, user));
pushNotificationSettingRepository.save(pushNotificationSetting.get());
PushNotificationSetting pushNotificationSetting = pushNotificationSettingRepository.findByUser(user)
.orElseGet(() -> PushNotificationConverter.toPushNotificationSetting(pushNotificationSettingRequestDTO, user));
if (pushNotificationSetting.getId() != null) {
// 기존에 존재하는 설정인 경우에만 업데이트
pushNotificationSetting.setPushNotification(pushNotificationSettingRequestDTO);
}
return PushNotificationConverter.toPushNotificationResponseDTO(pushNotificationSetting.get());
pushNotificationSettingRepository.save(pushNotificationSetting);
return PushNotificationConverter.toPushNotificationResponseDTO(pushNotificationSetting);
}


@Transactional(readOnly = true)
public PushNotificationSettingResponseDTO getPushNotification(){
public PushNotificationSettingResponseDTO getPushNotification() {
User user = UserContext.getUser();
Optional<PushNotificationSetting> pushNotificationSetting = pushNotificationSettingRepository.findByUser(user);
if (pushNotificationSetting.isPresent()){
if (pushNotificationSetting.isPresent()) {
return PushNotificationConverter.toPushNotificationResponseDTO(pushNotificationSetting.get());
}
else {
} else {
return PushNotificationConverter.toPushNotificationResponseDTO(PushNotificationSetting.builder().
receivePushNotification(false).
build());
Expand Down

0 comments on commit 5c3bff0

Please sign in to comment.