-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from YAPP-Github/feature/PC-416-settings-api
[PC-416] 유저 설정 기능 구현
- Loading branch information
Showing
10 changed files
with
319 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
api/src/main/java/org/yapp/domain/setting/application/SettingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.yapp.domain.setting.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.yapp.core.domain.setting.Setting; | ||
import org.yapp.core.exception.ApplicationException; | ||
import org.yapp.core.exception.error.code.SettingErrorCode; | ||
import org.yapp.domain.setting.dao.SettingRepository; | ||
import org.yapp.domain.setting.dto.response.SettingInfoResponse; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SettingService { | ||
|
||
private final SettingRepository settingRepository; | ||
|
||
@Transactional | ||
public void setNotificationStatus(Long userId, boolean status) { | ||
Setting userSetting = getUserSetting(userId); | ||
userSetting.updateNotification(status); | ||
} | ||
|
||
@Transactional | ||
public void setMatchNotificationStatus(Long userId, boolean status) { | ||
Setting userSetting = getUserSetting(userId); | ||
userSetting.updateMatchNotification(status); | ||
} | ||
|
||
@Transactional | ||
public void setAcquaintanceBlockStatus(Long userId, boolean status) { | ||
Setting userSetting = getUserSetting(userId); | ||
userSetting.updateAcquaintanceBlock(status); | ||
} | ||
|
||
@Transactional | ||
public void createSetting(Long userId) { | ||
Setting setting = new Setting(userId, true, true, true); | ||
settingRepository.save(setting); | ||
} | ||
|
||
public Setting getUserSetting(Long userId) { | ||
return settingRepository.findByUserId(userId).orElseThrow(() -> new ApplicationException( | ||
SettingErrorCode.NOT_FOUND_SETTING)); | ||
} | ||
|
||
public boolean isUserNotificationEnabled(Long userId) { | ||
Setting userSetting = getUserSetting(userId); | ||
return userSetting.isNotification(); | ||
} | ||
|
||
public boolean isMatchNotificationEnabled(Long userId) { | ||
Setting userSetting = getUserSetting(userId); | ||
return userSetting.isNotification() && userSetting.isMatchNotification(); | ||
} | ||
|
||
public boolean isAcquaintanceBlockEnabled(Long userId) { | ||
Setting userSetting = getUserSetting(userId); | ||
return userSetting.isAcquaintanceBlock(); | ||
} | ||
|
||
public SettingInfoResponse getUserSettingInfo(Long userId) { | ||
Setting userSetting = getUserSetting(userId); | ||
return new SettingInfoResponse(userSetting.isNotification(), userSetting.isMatchNotification(), | ||
userSetting.isAcquaintanceBlock()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
api/src/main/java/org/yapp/domain/setting/dao/SettingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.yapp.domain.setting.dao; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.yapp.core.domain.setting.Setting; | ||
|
||
public interface SettingRepository extends JpaRepository<Setting, Long> { | ||
|
||
Optional<Setting> findByUserId(Long userId); | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/org/yapp/domain/setting/dto/request/SettingToggleRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.yapp.domain.setting.dto.request; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class SettingToggleRequest { | ||
|
||
private Boolean toggle; | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/org/yapp/domain/setting/dto/response/SettingInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.yapp.domain.setting.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class SettingInfoResponse { | ||
|
||
private Boolean isNotificationEnabled; | ||
private Boolean isMatchNotificationEnabled; | ||
private Boolean isAcquaintanceBlockEnabled; | ||
} |
Oops, something went wrong.