-
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
Merged
알림 읽기 기능 구현 #775
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5096f62
chore: (#766) 코드 컨벤션 수정
woo-chang d2f942c
feat: (#766) 알림 읽음 기능 구현
woo-chang 3c68733
refactor: (#766) 알림 리팩터링
woo-chang 4966dd2
feat: (#766) 알림 대상 검증 기능 구현
woo-chang c8244aa
feat: (#766) 알림 읽는 기능 구현
woo-chang 04d5212
feat: (#766) 알림 읽기 API 구현
woo-chang 85fa66d
fix: (#766) 테이블 추가
woo-chang b3a4d72
fix: (#766) 비동기 테스트를 위한 sleep 추가
woo-chang 289b63c
feat: (#766) 알림 타입 추가
woo-chang 9e6273a
test: (#766) 알림 타입이 없는 경우 테스트
woo-chang 4abffa8
feat: (#766) 신고 알림 읽는 기능 구현
woo-chang 40618e1
feat: (#766) 알림 액션 타입 생성 기능 구현
woo-chang 3998d1d
feat: (#766) 타입에 따른 알림 읽기 기능 구현
woo-chang 0e10b78
docs: (#766) 예외 상황 문서화
woo-chang 0242e3a
chore: (#766) 코드 컨벤션 수정
woo-chang b3e0ba1
docs: (#766) 예외 발생 문서화
woo-chang 0d9211f
Merge branch 'dev' into feat/#766
woo-chang b5b54c9
Merge branch 'dev' into feat/#766
woo-chang a54c9b2
chore: (#766) 코드 컨벤션 수정
woo-chang 6f432d7
chore: (#766) 개행 컨벤션 수정
woo-chang d6f81ec
Merge branch 'dev' into feat/#766
woo-chang 68e6bec
fix: (#766) DB 예약어 수정
woo-chang 4355004
fix: (#766) 이벤트 테스트 임시 수정
woo-chang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandController.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,35 @@ | ||
package com.votogether.domain.alarm.controller; | ||
|
||
import com.votogether.domain.alarm.service.AlarmCommandService; | ||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.global.jwt.Auth; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Positive; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
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 AlarmCommandController implements AlarmCommandControllerDocs { | ||
|
||
private final AlarmCommandService alarmCommandService; | ||
|
||
@PatchMapping("/{id}") | ||
public ResponseEntity<Void> readAlarm( | ||
@PathVariable("id") @Positive(message = "알림 ID는 양수만 가능합니다.") final Long alarmId, | ||
@RequestParam("type") @NotBlank(message = "알림 타입이 공백이거나 존재하지 않습니다.") final String type, | ||
@Auth final Member loginMember | ||
) { | ||
alarmCommandService.readAlarm(alarmId, type, loginMember); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandControllerDocs.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,51 @@ | ||
package com.votogether.domain.alarm.controller; | ||
|
||
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; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Positive; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Tag(name = "알림 커맨드", description = "알림 커맨드 API") | ||
public interface AlarmCommandControllerDocs { | ||
|
||
@Operation( | ||
summary = "알림 읽기", | ||
description = "알림을 읽을 수 있는 대상이라면 알림을 읽습니다." | ||
) | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "알림 읽기 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = """ | ||
1.알림 ID가 양수가 아닌 경우 | ||
|
||
2.알림을 읽을 수 있는 대상이 아닌 경우 | ||
""", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
), | ||
@ApiResponse( | ||
responseCode = "404", | ||
description = "알림이 존재하지 않은 경우", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
) | ||
}) | ||
ResponseEntity<Void> readAlarm( | ||
@Parameter(description = "알림 ID", example = "1") | ||
@Positive(message = "알림 ID는 양수만 가능합니다.") final Long alarmId, | ||
@Parameter(description = "알림 타입", example = "CONTENT") | ||
@NotBlank(message = "알림 타입이 공백이거나 존재하지 않습니다.") final String alarmType, | ||
final Member loginMember | ||
); | ||
|
||
} |
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
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
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/votogether/domain/alarm/entity/vo/AlarmActionType.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,20 @@ | ||
package com.votogether.domain.alarm.entity.vo; | ||
|
||
import com.votogether.domain.alarm.exception.AlarmExceptionType; | ||
import com.votogether.global.exception.BadRequestException; | ||
import java.util.Arrays; | ||
|
||
public enum AlarmActionType { | ||
|
||
CONTENT, | ||
REPORT, | ||
; | ||
|
||
public static AlarmActionType from(final String actionType) { | ||
return Arrays.stream(AlarmActionType.values()) | ||
.filter(alarmActionType -> alarmActionType.name().equals(actionType)) | ||
.findFirst() | ||
.orElseThrow(() -> new BadRequestException(AlarmExceptionType.NOT_FOUND_ACTION_TYPE)); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/com/votogether/domain/alarm/exception/AlarmExceptionType.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,23 @@ | ||
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, "알림을 읽을 대상이 아닙니다."), | ||
NOT_FOUND_ACTION_TYPE(1303, "등록되지 않은 알림 동작입니다."), | ||
; | ||
|
||
private final int code; | ||
private final String message; | ||
|
||
AlarmExceptionType(final int code, final String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
} |
20 changes: 0 additions & 20 deletions
20
...d/src/main/java/com/votogether/domain/alarm/exception/ReportActionAlarmExceptionType.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/votogether/domain/alarm/service/AlarmCommandService.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,28 @@ | ||
package com.votogether.domain.alarm.service; | ||
|
||
import com.votogether.domain.alarm.entity.vo.AlarmActionType; | ||
import com.votogether.domain.alarm.service.strategy.AlarmReadStrategy; | ||
import com.votogether.domain.alarm.service.strategy.AlarmReadStrategyProvider; | ||
import com.votogether.domain.member.entity.Member; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class AlarmCommandService { | ||
|
||
private final AlarmReadStrategyProvider alarmReadStrategyProvider; | ||
|
||
public void readAlarm( | ||
final Long alarmId, | ||
final String type, | ||
final Member loginMember | ||
) { | ||
final AlarmActionType alarmActionType = AlarmActionType.from(type); | ||
final AlarmReadStrategy alarmReadStrategy = alarmReadStrategyProvider.getStrategy(alarmActionType); | ||
alarmReadStrategy.read(alarmId, loginMember); | ||
} | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/votogether/domain/alarm/service/strategy/AlarmReadStrategy.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,9 @@ | ||
package com.votogether.domain.alarm.service.strategy; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
|
||
public interface AlarmReadStrategy { | ||
|
||
void read(final Long id, final Member member); | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Q
자신 것이 아닌 알람을 읽을 수 있는 경우는 어떤 상황에 있을 수 있는지 궁금합니다
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.
알림 ID가 노출되어 다른 회원이 해당 ID로
API
를 요청하는 것을 방지하기 위한 방어 코드입니다 :)