Skip to content

Commit

Permalink
Merge pull request #103 from MoDooS/main
Browse files Browse the repository at this point in the history
feat: 알람 모두 읽기 처리
  • Loading branch information
taekyun-yoon authored Aug 29, 2023
2 parents 7e29ef0 + 37695e6 commit 15ea805
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.study.modoos.alarm.response.ReadAlarmResponse;
import com.study.modoos.alarm.service.AlarmService;
import com.study.modoos.common.CurrentUser;
import com.study.modoos.common.exception.ErrorCode;
import com.study.modoos.common.exception.ModoosException;
import com.study.modoos.common.response.NormalResponse;
import com.study.modoos.member.entity.Member;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -34,4 +37,16 @@ public ResponseEntity<Slice<AlarmResponse>> getComment(@CurrentUser Member curre
public ResponseEntity<ReadAlarmResponse> readAlarm(@CurrentUser Member currentUser, @PathVariable Long alarmId) {
return ResponseEntity.ok(alarmService.readAlarm(currentUser, alarmId));
}

@GetMapping("/read/all")
public ResponseEntity<NormalResponse> readAllAlarm(@CurrentUser Member currentUser){
try {
alarmService.readAllAlarm(currentUser);
return ResponseEntity.ok(NormalResponse.success());
}
catch (ModoosException ex){
throw new ModoosException(ErrorCode.MEMBER_HAS_NOT_ALARM);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;


@Repository
public interface AlarmRepository extends JpaRepository<Alarm, Long> {
Slice<Alarm> findByMemberOrderByCreatedAtDesc(Member member, Pageable sortedPageable);
Optional<Alarm> findByStudyAndMemberAndAlarmType(Study study, Member member, AlarmType alarmType);
List<Alarm>findByMemberAndIsRead(Member member, boolean read);
}
16 changes: 15 additions & 1 deletion src/main/java/com/study/modoos/alarm/service/AlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.study.modoos.member.repository.MemberRepository;
import com.study.modoos.participant.repository.ParticipantRepository;
import com.study.modoos.study.entity.Study;
import com.study.modoos.study.repository.StudyRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -130,4 +129,19 @@ public ReadAlarmResponse readAlarm(Member currentUser, Long alarmId) {
alarmRepository.save(requestAlarm);
return ReadAlarmResponse.readAlarm(requestAlarm, true);
}

public void readAllAlarm(Member currentUser) {
Member member = memberRepository.findByEmail(currentUser.getEmail())
.orElseThrow(() -> new ModoosException(ErrorCode.MEMBER_NOT_FOUND));

List<Alarm> unreadAlarms = alarmRepository.findByMemberAndIsRead(member, false);
if (unreadAlarms.isEmpty()){
throw new ModoosException(ErrorCode.MEMBER_HAS_NOT_ALARM);
}else {
for (Alarm alarm : unreadAlarms) {
alarm.readAlarm(true);
alarmRepository.save(alarm);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public enum ErrorCode {
INVALID_COOKIE_NAME(HttpStatus.NOT_FOUND, "JwtFilter > resolveToken 에서 쿠키 이름이 다릅니다", "cookie.getName()으로 쿠키 이름을 확인해주세요"),
MISS_DEADLINE(HttpStatus.FORBIDDEN, "해당 스터디의 모집 마감일이 지났습니다.", "해당 스터디는 모집이 종료되었습니다." ),
MEMBER_NOT_IN_ALARM(HttpStatus.NOT_FOUND, "해당 수신자에 대한 알림 데이터가 없습니다." , "알림이 생기면 확인해주세요"),
ALARM_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 알람을 찾을 수 없습니다.", "alarmId를 확인해주세요");
ALARM_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 알람을 찾을 수 없습니다.", "alarmId를 확인해주세요"),
MEMBER_HAS_NOT_ALARM(HttpStatus.NOT_FOUND, "해당 회원은 알림이 존재하지 않습니다.", "알림이 있는지 확인해주세요");


private final HttpStatus httpStatus;
Expand Down

0 comments on commit 15ea805

Please sign in to comment.