Skip to content

Commit

Permalink
♻️ refactor: 댓글 알림 기능 추가 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoungj00n committed Sep 23, 2024
1 parent 248db9f commit a2c2182
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/github-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
java-version: 17 # 자바 설치
distribution: 'adopt'

- name: Add firebase configuration from secrets
run: echo ${{ secrets.FIREBASE_CONFIG }} > ./src/main/resources/firebase/sm-project-firebase.json

- name: Set Environment
uses: microsoft/variable-substitution@v1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import com.sm.project.domain.community.Comment;
import com.sm.project.domain.community.Post;
import com.sm.project.domain.member.Member;
import com.sm.project.firebase.FcmService;
import com.sm.project.repository.community.CommentRepository;
import com.sm.project.web.dto.community.CommentRequestDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;

@Service
@Slf4j
@RequiredArgsConstructor
Expand All @@ -21,15 +24,18 @@ public class CommentService {

private final CommentRepository commentRepository;
private final PostQueryService postQueryService;
private final FcmService fcmService;

public void createComment(Member member, Post post, CommentRequestDTO.CreateCommentDTO request) {
public void createComment(Member member, Post post, CommentRequestDTO.CreateCommentDTO request) throws IOException {
Comment comment = CommentConverter.toParentComment(member, post, request);
fcmService.sendMessage(post.getMember().getFcmTokenList().get(0).getToken(), member.getNickname() +"님의 댓글", request.getContent());
commentRepository.save(comment);
}

public void createChildComment(Member member, Comment parent, CommentRequestDTO.CreateCommentDTO request) {
public void createChildComment(Member member, Comment parent, CommentRequestDTO.CreateCommentDTO request) throws IOException{
Post post = postQueryService.findPostById(parent.getPost().getId());
Comment childComment = CommentConverter.toChildComment(member, post, parent, request);
fcmService.sendMessage(parent.getMember().getFcmTokenList().get(0).getToken(), member.getNickname() +"님의 댓글", request.getContent());
commentRepository.save(childComment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.sm.project.service.community.PostQueryService;
import com.sm.project.service.member.MemberQueryService;
import com.sm.project.web.dto.community.CommentRequestDTO;
import com.sm.project.web.dto.community.CommentResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -25,12 +24,11 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Slice;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.io.IOException;

@RestController
@Slf4j
Expand All @@ -54,7 +52,7 @@ public class CommentController {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST4001", description = "해당 포스트를 찾을 수 없습니다.",
content = @Content(schema = @Schema(implementation = ErrorReasonDTO.class))),
})
public ResponseDTO<?> createComment(Authentication auth, @PathVariable(name = "postId") Long postId, @RequestBody CommentRequestDTO.CreateCommentDTO request) {
public ResponseDTO<?> createComment(Authentication auth, @PathVariable(name = "postId") Long postId, @RequestBody CommentRequestDTO.CreateCommentDTO request) throws IOException {
Member member = memberQueryService.findMemberById(Long.valueOf(auth.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND));
Post post = postQueryService.findPostById(postId);
commentService.createComment(member, post, request);
Expand All @@ -72,7 +70,7 @@ public ResponseDTO<?> createComment(Authentication auth, @PathVariable(name = "p
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMENT4001", description = "해당 댓글을 찾을 수 없습니다.",
content = @Content(schema = @Schema(implementation = ErrorReasonDTO.class))),
})
public ResponseDTO<?> createChildComment(Authentication auth, @PathVariable(name = "commentId") Long commentId, @RequestBody CommentRequestDTO.CreateCommentDTO request) {
public ResponseDTO<?> createChildComment(Authentication auth, @PathVariable(name = "commentId") Long commentId, @RequestBody CommentRequestDTO.CreateCommentDTO request) throws IOException{
Member member = memberQueryService.findMemberById(Long.valueOf(auth.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND));
Comment parent = commentQueryService.findCommentById(commentId);
commentService.createChildComment(member, parent, request);
Expand Down
13 changes: 0 additions & 13 deletions src/main/resources/firebase/sm-project-firebase.json

This file was deleted.

0 comments on commit a2c2182

Please sign in to comment.