Skip to content

Commit

Permalink
refactor: 댓글은 오름차순으로 정렬
Browse files Browse the repository at this point in the history
  • Loading branch information
yurim0628 committed Jun 4, 2024
2 parents 675571d + d1f784a commit 0a5e380
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class FCMConstants {
public static final String FCM_TOKEN_PREFIX = "fcm_token:";
public static final long FCM_TOKEN_EXPIRATION = 1000L * 60 * 60 * 24 * 60;

public static final String COMMUNITY_URL_PREFIX = "/community/";
public static final String DEFAULT_TITLE = "offispace";
public static final String DEFAULT_IMAGE = "https://sabujak-image-bucket.s3.ap-northeast-2.amazonaws.com/offispace+icon.png";
public static final String TARGET_URL_KEY = "targetUrl";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

import java.util.Map;

import static com.example.sabujak.fcm.constants.FCMConstants.DEFAULT_TITLE;
import static com.example.sabujak.fcm.constants.FCMConstants.TARGET_URL_KEY;
import static com.example.sabujak.fcm.constants.FCMConstants.*;
import static com.example.sabujak.fcm.exception.FCMErrorCode.*;
import static com.google.firebase.messaging.MessagingErrorCode.*;

Expand All @@ -36,6 +35,7 @@ private Notification createNotification(String body) {
return Notification.builder()
.setTitle(DEFAULT_TITLE)
.setBody(body)
.setImage(DEFAULT_IMAGE)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.web.multipart.MultipartFile;

import static com.example.sabujak.post.constants.PaginationConstants.*;
import static org.springframework.data.domain.Sort.Direction.ASC;
import static org.springframework.data.domain.Sort.Direction.DESC;

@RestController
Expand Down Expand Up @@ -100,7 +101,7 @@ public ResponseEntity<Response<CustomSlice<CommentResponse>>> getComments(
page = DEFAULT_PAGE,
size = DEFAULT_COMMENT_PAGE_SIZE,
sort = DEFAULT_SORT_FIELD,
direction = DESC
direction = ASC
) Pageable pageable,
@AuthenticationPrincipal Access access
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Optional<Comment> findWithMemberAndPostByPostIdAndCommentId(
"from Comment c " +
"join fetch c.member m " +
"where c.post.id = :postId and " +
"(:cursorId is null or c.id < :cursorId)"
"(:cursorId is null or c.id > :cursorId)"
)
List<Comment> findWithMemberByPostIdAndCursorId(
@Param("postId") Long postId,
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/example/sabujak/post/service/PostFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.example.sabujak.post.entity.*;
import com.example.sabujak.member.entity.Member;
import com.example.sabujak.member.service.MemberService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -19,6 +18,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.example.sabujak.fcm.constants.FCMConstants.COMMUNITY_URL_PREFIX;
import static com.example.sabujak.notification.utils.NotificationContent.createCommentContent;

@Slf4j
Expand All @@ -32,7 +32,6 @@ public class PostFacade {
private final PostLikeService postLikeService;
private final CommentService commentService;

private final HttpServletRequest request;
private final ApplicationEventPublisher publisher;

@Transactional(readOnly = true)
Expand Down Expand Up @@ -152,7 +151,8 @@ public void saveComment(Long postId, SaveCommentRequest saveCommentRequest, Stri
if(!commenterEmail.equals(writerEmail)) {
log.info("Creating and Publishing Event for Writer Notification.");
String content = createCommentContent(post.getTitle(), commenter.getMemberName());
publisher.publishEvent(new SaveCommentEvent(request.getRequestURI(), content, writerEmail, writer));
String targetUrl = createTargetUrl(post.getId());
publisher.publishEvent(new SaveCommentEvent(targetUrl, content, writerEmail, writer));
}
}

Expand Down Expand Up @@ -198,4 +198,8 @@ private CommentResponse createCommentResponse(Comment comment, String viewerEmai

return CommentResponse.of(comment, writer, isWriter);
}

private String createTargetUrl(Long id) {
return COMMUNITY_URL_PREFIX + id;
}
}

0 comments on commit 0a5e380

Please sign in to comment.