Skip to content
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

[BE] 알람 조회,수정,삭제 기능 #161

Merged
merged 21 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 65 additions & 20 deletions be/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,93 +49,93 @@ operation::login_failedByWrongPassword[snippets='http-response']

==== 성공

operation::registerComment_success[snippets='http-request,http-response']
operation::comment_register_success[snippets='http-request,http-response']

==== 바디가 없을 때

operation::registerComment_failed_by_request_body_not_exists[snippets='http-response']
operation::comment_register_failed_by_request_body_not_exists[snippets='http-response']

==== 댓글이 없을 때

operation::registerComment_failed_by_content_not_exists[snippets='http-response']
operation::comment_register_failed_by_content_not_exists[snippets='http-response']

==== 댓글이 비여 있으면

operation::registerComment_failed_by_content_is_empty[snippets='http-response']
operation::comment_register_failed_by_content_is_empty[snippets='http-response']

==== 댓글이 공백 일때

operation::registerComment_failed_by_content_is_blank[snippets='http-response']
operation::comment_register_failed_by_content_is_blank[snippets='http-response']

==== 댓글이 200자를 넘을 때

operation::registerComment_failed_by_content_is_larger_than_200[snippets='http-response']
operation::comment_register_failed_by_content_is_larger_than_200[snippets='http-response']

==== 피드가 존재하지 않을 때

operation::registerComment_failed_by_feed_not_exists[snippets='http-response']
operation::comment_register_failed_by_feed_not_exists[snippets='http-response']

==== 피드 아이디가 없을 때

operation::registerComment_failed_by_feed_id_not_exists[snippets='http-response']
operation::comment_register_failed_by_feed_id_not_exists[snippets='http-response']

=== 댓글 수정

==== 성공

operation::editComment_success[snippets='http-request,http-response']
operation::comment_edit_success[snippets='http-request,http-response']

==== 바디가 없을 때

operation::editComment_failed_by_request_body_not_exists[snippets='http-response']
operation::comment_edit_failed_by_request_body_not_exists[snippets='http-response']

==== 댓글이 비여 있으면

operation::editComment_failed_by_content_is_empty[snippets='http-response']

==== 댓글이 공백 일때

operation::editComment_failed_by_content_is_blank[snippets='http-response']
operation::comment_edit_failed_by_content_is_blank[snippets='http-response']

==== 댓글이 200자를 넘을 때

operation::editComment_failed_by_content_is_larger_than_200[snippets='http-response']
operation::comment_edit_failed_by_content_is_larger_than_200[snippets='http-response']

==== 댓글이 존재하지 않을 때

operation::editComment_failed_by_comment_not_exists[snippets='http-response']
operation::comment_edit_failed_by_comment_not_exists[snippets='http-response']

==== 댓글이 이미 삭제되었을 때

operation::editComment_failed_by_comment_is_deleted[snippets='http-response']
operation::comment_edit_failed_by_comment_is_deleted[snippets='http-response']

=== 댓글 삭제

==== 성공

operation::deleteComment_success[snippets='http-request,http-response']
operation::comment_delete_success[snippets='http-request,http-response']

==== 댓글이 존재하지 않을 때

operation::deleteComment_failed_by_comment_not_exists[snippets='http-response']
operation::comment_delete_failed_by_comment_not_exists[snippets='http-response']

==== 댓글이 이미 삭제되었을 때

operation::deleteComment_failed_by_comment_is_deleted[snippets='http-response']
operation::comment_delete_failed_by_comment_is_deleted[snippets='http-response']

=== 피드별 댓글 조회

==== 성공

operation::fetchComments_success[snippets='http-request,http-response']
operation::comments_fetch_success[snippets='http-request,http-response']

==== 성공 - 페이징

operation::fetchComments_with_page_success[snippets='http-request,http-response']
operation::comments_fetch_with_page_success[snippets='http-request,http-response']

==== 피드가 존재하지 않을 때

operation::fetchComments_failed_by_feed_id_not_exists[snippets='http-response']
operation::comments_fetch_failed_by_feed_id_not_exists[snippets='http-response']

[[member]]
== 회원
Expand Down Expand Up @@ -222,3 +222,48 @@ operation::findMoodyById_success[snippets='http-request,http-response']




[[notification]]
== 알람

=== 알람 전체 조회

==== 성공 - 페이징

operation::notification_request_all_success[snippets='http-request,http-response']

=== 개별 알람 조회

==== 성공 (예시: 읽음으로 변경 )

operation::notification_request_single_success[snippets='http-request,http-response']

=== 알람 개별 상태 변경

==== 성공 - 읽음

operation::notification_change_status_success[snippets='http-request,http-response']

=== 알람 일괄 상태 변경

==== 성공 - 읽음

operation::notification_change_all_status_success[snippets='http-request,http-response']

=== 알람 개별 삭제

==== 성공

operation::notification_delete_success[snippets='http-request,http-response']

=== 알람 전체 삭제

==== 성공

operation::notification_delete_all_success[snippets='http-request,http-response']

=== 알람 일괄적으로 삭제

==== 성공

operation::notification_delete_notification_list_success[snippets='http-request,http-response']
2 changes: 0 additions & 2 deletions be/src/main/java/com/foodymoody/be/DocumentController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.foodymoody.be;

import java.util.Map;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down
4 changes: 1 addition & 3 deletions be/src/main/java/com/foodymoody/be/auth/util/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ public class JwtUtil {

private long accessTokenExp;
private long refreshTokenExp;
private String secret;
private String issuer;
private SecretKey secretKey;
private ClaimUtil claimUtil;

public JwtUtil(
@Value("${jwt.token.exp.access}") long accessTokenExp,
@Value("${jwt.token.exp.refresh}")long refreshTokenExp,
@Value("${jwt.token.exp.refresh}") long refreshTokenExp,
@Value("${jwt.token.secret}") String secret,
@Value("${jwt.token.issuer}") String issuer,
ClaimUtil claimUtil) {
this.accessTokenExp = accessTokenExp;
this.refreshTokenExp = refreshTokenExp;
this.secret = secret;
this.issuer = issuer;
this.secretKey = Keys.hmacShaKeyFor(secret.getBytes());
this.claimUtil = claimUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.foodymoody.be.comment.domain;

import static com.foodymoody.be.comment.domain.CommentDomainMapper.mapperToNotificationEvent;

import com.foodymoody.be.common.event.NotificationEvents;
import com.foodymoody.be.common.exception.CommentDeletedException;
import java.time.LocalDateTime;
import javax.persistence.EmbeddedId;
Expand Down Expand Up @@ -30,6 +33,7 @@ public Comment(CommentId id, String content, String feedId, boolean deleted,
this.memberId = memberId;
this.createdAt = createdAt;
this.updatedAt = createdAt;
NotificationEvents.publish(mapperToNotificationEvent(feedId));
}

public CommentId getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.foodymoody.be.comment.domain;

import com.foodymoody.be.common.event.NotificationEvent;
import com.foodymoody.be.common.event.NotificationType;
import java.time.LocalDateTime;

public class CommentAddNotificationEvent implements NotificationEvent {

private String memberId;
private String message;
private NotificationType notificationType;
private LocalDateTime createdAt;

private CommentAddNotificationEvent(String memberId, String message, NotificationType notificationType,
LocalDateTime createdAt) {
this.memberId = memberId;
this.message = message;
this.notificationType = notificationType;
this.createdAt = createdAt;
}

public static CommentAddNotificationEvent of(String memberId, String message, NotificationType notificationType,
LocalDateTime createdAt) {
return new CommentAddNotificationEvent(memberId, message, notificationType, createdAt);
}

@Override
public NotificationType getNotificationType() {
return notificationType;
}

@Override
public String getMessage() {
return message;
}

@Override
public String getMemberId() {
return memberId;
}

@Override
public LocalDateTime getCreatedAt() {
return createdAt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.foodymoody.be.comment.domain;

import com.foodymoody.be.common.event.NotificationType;
import java.time.LocalDateTime;

public class CommentDomainMapper {

private CommentDomainMapper() {
throw new IllegalStateException("Utility class");
}

public static CommentAddNotificationEvent mapperToNotificationEvent(String feedId) {
return CommentAddNotificationEvent.of("1",
feedId + "에 댓글이 추가되였습니다.",
NotificationType.COMMENT_ADDED,
LocalDateTime.now());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.foodymoody.be.common.event;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@RequiredArgsConstructor
@Configuration
public class EventsConfiguration {

private final ApplicationContext applicationContext;

@Bean
public InitializingBean notificationEventsInitializer() {
return () -> NotificationEvents.setPublisher(applicationContext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.foodymoody.be.common.event;

import java.time.LocalDateTime;

public interface NotificationEvent {

NotificationType getNotificationType();

String getMessage();

String getMemberId();

LocalDateTime getCreatedAt();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.foodymoody.be.common.event;

import org.springframework.context.ApplicationEventPublisher;


public class NotificationEvents {

private static ApplicationEventPublisher publisher;

private NotificationEvents() {
throw new IllegalStateException("Utility class");
}

public static void publish(NotificationEvent event) {
publisher.publishEvent(event);
}

static void setPublisher(ApplicationEventPublisher publisher) {
NotificationEvents.publisher = publisher;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.foodymoody.be.common.event;

public enum NotificationType {
COMMENT_ADDED,
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.foodymoody.be.common.filter;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.foodymoody.be.auth.util.JwtUtil;
import com.foodymoody.be.common.exception.ErrorMessage;
import com.foodymoody.be.common.exception.ErrorResponse;
import com.foodymoody.be.common.util.HttpHeaderType;
import com.foodymoody.be.common.util.HttpHeaderParser;
import com.foodymoody.be.auth.util.JwtUtil;
import com.foodymoody.be.common.util.HttpHeaderType;
import io.jsonwebtoken.JwtException;
import java.io.IOException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
try {
String customUri = extractCustomUri(httpRequest);
if (!isInWhiteList(customUri)) {
String header = httpRequest.getHeader(HttpHeaderType.AUTHORIZATION.NAME);
String header = httpRequest.getHeader(HttpHeaderType.AUTHORIZATION.headerName);
String token = HttpHeaderParser.parse(header, HttpHeaderType.AUTHORIZATION);
Map<String, String> parsed = jwtUtil.parseAccessToken(token);
request.setAttribute("id", parsed.get("id"));
Expand Down Expand Up @@ -86,4 +86,4 @@ private boolean isInWhiteList(String uri) {
return whiteList.stream().anyMatch(whitelist -> Pattern.matches(whitelist, uri));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private HttpHeaderParser() {
}

public static String parse(String header, HttpHeaderType type) {
return parse(header, type.SKIM);
return parse(header, type.skim);
}

private static String parse(String header, String skim) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ public enum HttpHeaderType {

AUTHORIZATION("Authorization", "Bearer");

public final String NAME;
public final String SKIM;
public final String headerName;
public final String skim;

HttpHeaderType(String headerName, String skim) {
this.NAME = headerName;
this.SKIM = skim;
this.headerName = headerName;
this.skim = skim;
}

}
Loading