11package com .api .advanced_mobile .domain .alarm .service ;
22
33import com .api .advanced_mobile .domain .alarm .entity .Alarm ;
4+ import com .api .advanced_mobile .domain .alarm .entity .enums .AlarmType ;
45import com .api .advanced_mobile .domain .alarm .exception .NotFoundAlarmException ;
56import com .api .advanced_mobile .domain .alarm .repository .AlarmRepository ;
67import com .api .advanced_mobile .domain .alarm .web .dto .AlarmRes ;
@@ -18,34 +19,45 @@ public class AlarmServiceImpl implements AlarmService{
1819 //알림 조회
1920 @ Override
2021 public AlarmRes getAlarm (Long id ) {
21- Alarm alarm = alarmRepo .findByMemberId (id )
22+ Alarm morning = alarmRepo .findByMemberIdAndType (id , AlarmType . MORNING )
2223 .orElseThrow (NotFoundAlarmException ::new );
2324
24- return AlarmRes .from (
25- alarm .isActivate ()
26- ,alarm .getAlarmTime ()
27- );
25+ Alarm night = alarmRepo .findByMemberIdAndType (id , AlarmType .NIGHT )
26+ .orElseThrow (NotFoundAlarmException ::new );
27+
28+
29+ return AlarmRes .from (morning , night );
2830 }
2931
3032 //알림 수정
3133 @ Transactional
3234 @ Override
3335 public AlarmRes modifyAlarm (Long id , ModifyAlarmReq req ) {
34- Alarm alarm = alarmRepo .findByMemberId (id )
36+
37+ Alarm morning = alarmRepo .findByMemberIdAndType (id , AlarmType .MORNING )
3538 .orElseThrow (NotFoundAlarmException ::new );
3639
37- if (req .getActivate () != null ) {
38- alarm .modifyActivate (req .getActivate ());
40+ Alarm night = alarmRepo .findByMemberIdAndType (id , AlarmType .NIGHT )
41+ .orElseThrow (NotFoundAlarmException ::new );
42+
43+
44+ updateAlarm (morning , req .getMorning ());
45+ updateAlarm (night , req .getNight ());
46+
47+
48+ return AlarmRes .from (morning , night );
49+ }
50+
51+ private void updateAlarm (Alarm alarm , ModifyAlarmReq .AlarmUpdate update ) {
52+ if (update == null ) return ;
53+
54+ if (update .getActivate () != null ) {
55+ alarm .modifyActivate (update .getActivate ());
3956 }
4057
4158 // time 변경 요청이 있을 때만 수정
42- if (req .getTime () != null ) {
43- alarm .modifyTime (req .getTime ());
59+ if (update .getTime () != null ) {
60+ alarm .modifyTime (update .getTime ());
4461 }
45-
46- return AlarmRes .from (
47- alarm .isActivate ()
48- ,alarm .getAlarmTime ()
49- );
5062 }
5163}
0 commit comments