-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
알림 읽기 기능 구현 #775
알림 읽기 기능 구현 #775
Changes from 8 commits
5096f62
d2f942c
3c68733
4966dd2
c8244aa
04d5212
85fa66d
b3a4d72
289b63c
9e6273a
4abffa8
40618e1
3998d1d
0e10b78
0242e3a
b3e0ba1
0d9211f
b5b54c9
a54c9b2
6f432d7
d6f81ec
68e6bec
4355004
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
package com.votogether.domain.alarm.controller; | ||
|
||
import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; | ||
import com.votogether.domain.alarm.dto.ReportActionResponse; | ||
import com.votogether.domain.member.entity.Member; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.constraints.PositiveOrZero; | ||
import java.util.List; | ||
import jakarta.validation.constraints.Positive; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Tag(name = "알림", description = "알림 API") | ||
@Tag(name = "알림 커맨드", description = "알림 커맨드 API") | ||
public interface AlarmCommandControllerDocs { | ||
|
||
@Operation(summary = "신고조치알림 조회", description = "신고조치알림목록을 조회한다.") | ||
@ApiResponse(responseCode = "201", description = "조회 성공") | ||
ResponseEntity<List<ReportActionAlarmResponse>> getReportActionAlarms( | ||
@Parameter(description = "현재 페이지 위치", example = "0") | ||
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, | ||
final Member member | ||
); | ||
|
||
@Operation(summary = "신고조치알림 상세 조회", description = "신고조치알림를 상세 조회한다.") | ||
@ApiResponse(responseCode = "201", description = "조회 성공") | ||
public ResponseEntity<ReportActionResponse> getReportActionAlarm( | ||
@Parameter(description = "신고조치알림 ID", example = "1") final Long reportActionAlarmId, | ||
final Member member | ||
@Operation( | ||
summary = "알림 읽기", | ||
description = "알림을 읽을 수 있는 대상이라면 알림을 읽습니다." | ||
) | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "알림 읽기 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "알림을 읽을 수 있는 대상이 아닌 경우" | ||
), | ||
@ApiResponse( | ||
responseCode = "404", | ||
description = "알림이 존재하지 않은 경우" | ||
) | ||
}) | ||
ResponseEntity<Void> readAlarm( | ||
@Parameter(description = "알림 ID", example = "1") | ||
@Positive(message = "알림 ID는 양수만 가능합니다.") final Long alarmId, | ||
final Member loginMember | ||
); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.votogether.domain.alarm.controller; | ||
|
||
import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; | ||
import com.votogether.domain.alarm.dto.ReportActionResponse; | ||
import com.votogether.domain.alarm.dto.response.PostAlarmResponse; | ||
import com.votogether.domain.alarm.service.AlarmQueryService; | ||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.global.jwt.Auth; | ||
import jakarta.validation.constraints.PositiveOrZero; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Validated | ||
@RequiredArgsConstructor | ||
@RequestMapping("/alarms") | ||
@RestController | ||
public class AlarmQueryController implements AlarmQueryControllerDocs { | ||
|
||
private final AlarmQueryService alarmQueryService; | ||
|
||
@GetMapping("/content") | ||
public ResponseEntity<List<PostAlarmResponse>> getPostAlarm( | ||
@RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page | ||
) { | ||
final List<PostAlarmResponse> postAlarmResponses = alarmQueryService.getPostAlarm(page); | ||
return ResponseEntity.ok(postAlarmResponses); | ||
} | ||
|
||
@GetMapping("/report") | ||
public ResponseEntity<List<ReportActionAlarmResponse>> getReportActionAlarms( | ||
@RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, | ||
@Auth final Member member | ||
) { | ||
final List<ReportActionAlarmResponse> response = alarmQueryService.getReportActionAlarms(member, page); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/report/{id}") | ||
public ResponseEntity<ReportActionResponse> getReportActionAlarm( | ||
@PathVariable("id") final Long reportActionAlarmId, | ||
@Auth final Member member | ||
) { | ||
final ReportActionResponse response = alarmQueryService.getReportActionAlarm(reportActionAlarmId, member); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package com.votogether.domain.alarm.controller; | ||
|
||
import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; | ||
import com.votogether.domain.alarm.dto.ReportActionResponse; | ||
import com.votogether.domain.alarm.dto.response.PostAlarmResponse; | ||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.global.exception.ExceptionResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
|
@@ -12,10 +16,13 @@ | |
import java.util.List; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Tag(name = "알림", description = "알림 API") | ||
@Tag(name = "알림 조회", description = "알림 조회 API") | ||
public interface AlarmQueryControllerDocs { | ||
|
||
@Operation(summary = "게시글 내역 알림 조회", description = "게시글 내역 알림을 조회한다.") | ||
@Operation( | ||
summary = "게시글 내역 알림 조회", | ||
description = "게시글 내역 알림을 조회한다." | ||
) | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
|
@@ -31,4 +38,31 @@ ResponseEntity<List<PostAlarmResponse>> getPostAlarm( | |
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page | ||
); | ||
|
||
@Operation( | ||
summary = "신고조치알림 조회", | ||
description = "신고조치알림목록을 조회한다." | ||
) | ||
@ApiResponse( | ||
responseCode = "201", | ||
description = "조회 성공" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 페이지가 0미만이면 400 반환한다는 내용도 포함되면 좋을 것 같아요 :) |
||
ResponseEntity<List<ReportActionAlarmResponse>> getReportActionAlarms( | ||
@Parameter(description = "현재 페이지 위치", example = "0") | ||
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, | ||
final Member member | ||
); | ||
|
||
@Operation( | ||
summary = "신고조치알림 상세 조회", | ||
description = "신고조치알림를 상세 조회한다." | ||
) | ||
@ApiResponse( | ||
responseCode = "201", | ||
description = "조회 성공" | ||
) | ||
ResponseEntity<ReportActionResponse> getReportActionAlarm( | ||
@Parameter(description = "신고조치알림 ID", example = "1") final Long reportActionAlarmId, | ||
final Member member | ||
); | ||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.votogether.domain.alarm.entity; | ||
|
||
import com.votogether.domain.alarm.entity.vo.AlarmType; | ||
import com.votogether.domain.alarm.exception.AlarmExceptionType; | ||
import com.votogether.domain.common.BaseEntity; | ||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.global.exception.BadRequestException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
|
@@ -13,6 +15,7 @@ | |
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import java.util.Objects; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
|
@@ -61,4 +64,14 @@ private Alarm( | |
this.isChecked = isChecked; | ||
} | ||
|
||
public void read() { | ||
this.isChecked = true; | ||
} | ||
|
||
public void checkOwner(final Member member) { | ||
if (!Objects.equals(this.member.getId(), member.getId())) { | ||
throw new BadRequestException(AlarmExceptionType.NOT_OWNER); | ||
} | ||
} | ||
Comment on lines
+71
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 알림 ID가 노출되어 다른 회원이 해당 ID로 |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.votogether.domain.alarm.exception; | ||
|
||
import com.votogether.global.exception.ExceptionType; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum AlarmExceptionType implements ExceptionType { | ||
|
||
NOT_FOUND_ACTION(1300, "신고조치알림이 존재하지 않습니다."), | ||
NOT_FOUND(1301, "알림이 존재하지 않습니다."), | ||
NOT_OWNER(1302, "알림을 읽을 대상이 아닙니다."), | ||
; | ||
|
||
private final int code; | ||
private final String message; | ||
|
||
AlarmExceptionType(final int code, final String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.votogether.domain.alarm.service; | ||
|
||
import com.votogether.domain.alarm.entity.Alarm; | ||
import com.votogether.domain.alarm.exception.AlarmExceptionType; | ||
import com.votogether.domain.alarm.repository.AlarmRepository; | ||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.global.exception.NotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class AlarmCommandService { | ||
|
||
private final AlarmRepository alarmRepository; | ||
|
||
public void readAlarm(final Long alarmId, final Member loginMember) { | ||
final Alarm alarm = alarmRepository.findById(alarmId) | ||
.orElseThrow(() -> new NotFoundException(AlarmExceptionType.NOT_FOUND)); | ||
|
||
alarm.checkOwner(loginMember); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 멤버와도 같이 조회해버리면 또한 알림의 대상이 누구인지 검증하는 책임은 알림 도메인에 있다고 생각하여 도메인 로직을 통해 검증할 수 있도록 하였습니다 ! |
||
alarm.read(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alarmId가 1미만인 경우도 적어주면 좋을 것 같아요.