Skip to content

Commit

Permalink
Merge pull request #49 from OmokNoonE/feature/notificationAOP
Browse files Browse the repository at this point in the history
[PR] AOP 알림 기능 및 쪽지 기능 구현
  • Loading branch information
ms1011 authored Apr 12, 2024
2 parents 63808b2 + 40a0399 commit 108501c
Show file tree
Hide file tree
Showing 14 changed files with 601 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ public class CommentDTO {

private String memberId;

private String nickname; // 필요없으면 지움

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface CommentService {
void modifyComment(CommentDTO commentDetailDTO);
void removeComment(int commentid);
List<CommentReplyDTO> viewCommentListByMe(String memberId);

CommentDTO getCommentById(Integer commentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken;
Expand All @@ -11,11 +12,11 @@
import org.omoknoone.onionhotsayyo.comment.command.dto.CommentDTO;
import org.omoknoone.onionhotsayyo.comment.command.dto.CommentReplyDTO;
import org.omoknoone.onionhotsayyo.comment.command.repository.CommentRepository;
import org.omoknoone.onionhotsayyo.member.aggregate.Member;
import org.omoknoone.onionhotsayyo.member.dto.MemberDTO;
import org.omoknoone.onionhotsayyo.member.service.MemberService;
import org.omoknoone.onionhotsayyo.reply.command.aggregate.Reply;
import org.omoknoone.onionhotsayyo.reply.command.dto.ReplyDTO;
import org.omoknoone.onionhotsayyo.reply.command.service.ReplyService;
import org.omoknoone.onionhotsayyo.reply.command.repository.ReplyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -24,16 +25,19 @@
public class CommentServiceImpl implements CommentService {
private final ModelMapper modelMapper;
private final CommentRepository commentRepository;
private final ReplyService replyService;
private final ReplyRepository replyRepository;
private final MemberService memberService;

@Autowired
public CommentServiceImpl(ModelMapper modelMapper, CommentRepository commentRepository, ReplyService replyService, MemberService memberService) {
public CommentServiceImpl(ModelMapper modelMapper, CommentRepository commentRepository,
ReplyRepository replyRepository,
MemberService memberService) {
this.modelMapper = modelMapper;
this.commentRepository = commentRepository;
this.replyService = replyService;
this.memberService = memberService;
}
this.replyRepository = replyRepository;
this.memberService = memberService;
}


@Transactional
@Override
Expand All @@ -42,7 +46,6 @@ public void createComment(CommentDTO commentDTO) {

Comment comment = modelMapper.map(commentDTO, Comment.class);
commentRepository.save(comment);

}

@Transactional
Expand All @@ -67,6 +70,12 @@ public void removeComment(int commentId) {
findcomment.setDeleted(true);
}

public CommentDTO getCommentById(int commentId) {
Comment findcomment = commentRepository.findById(commentId)
.orElseThrow(() -> new RuntimeException("댓글을 찾을 수 없습니다."));
return modelMapper.map(findcomment, CommentDTO.class);
}

@Override
public List<CommentReplyDTO> viewCommentListByMe(String memberId) {

Expand All @@ -75,7 +84,10 @@ public List<CommentReplyDTO> viewCommentListByMe(String memberId) {
List<Comment> commentList = commentRepository.findAllByMemberId(memberId);
List<CommentDTO> commentDTOList = modelMapper.map(commentList, new TypeToken<List<CommentDTO>>() {}.getType());

List<ReplyDTO> replyDTOList = replyService.viewReplyListByMemberId(memberId);
// List<ReplyDTO> replyDTOList = replyService.viewReplyListByMemberId(memberId);
List<Reply> replyList = replyRepository.findAllByMemberId(memberId);
List<ReplyDTO> replyDTOList = modelMapper.map(replyList, new TypeToken<List<ReplyDTO>>() {}.getType());


List<CommentReplyDTO> commentReplyDTOList = new ArrayList<>();
for (CommentDTO commentDTO : commentDTOList) {
Expand All @@ -102,4 +114,10 @@ public List<CommentReplyDTO> viewCommentListByMe(String memberId) {

return commentReplyDTOList;
}

@Override
public CommentDTO getCommentById(Integer commentId) {
Comment comment = commentRepository.findById(commentId).orElseThrow(IllegalArgumentException::new);
return modelMapper.map(comment, CommentDTO.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public void followMember(FollowDTO followDTO) {
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
Follow follow = modelMapper.map(followDTO, Follow.class);
followRepository.save(follow);

// 팔로우 당한 사람에게 팔로우 알림 전송
Member fromMember = memberRepository.findByMemberId(follow.getFromMemberId());
String fromMemberNickName = fromMember.getNickname();
String notifyMessage = fromMemberNickName + "님이 나를 팔로우 했습니다.";
notificationService.send(follow.getToMemberId(), notifyMessage);
// }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.omoknoone.onionhotsayyo.letter.command.aggregate;

import java.time.LocalDateTime;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.CreationTimestamp;
import org.omoknoone.onionhotsayyo.member.aggregate.Member;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Table;

@Entity
@Table(name = "letter")
public class Letter {

@Id
@Column(name = "letter_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int letterId;

@Column(name = "message")
private String message;

@Column(name = "event_time")
@CreationTimestamp
private LocalDateTime eventTime;

@Column(name = "is_checked")
@ColumnDefault("false")
private boolean isChecked;

@JoinColumn(name = "send_id")
private String sendId;

@JoinColumn(name = "receive_id")
private String receiveId;

public Letter() {
}

public Letter(int letterId, String message, LocalDateTime eventTime, boolean isChecked, String sendId,
String receiveId) {
this.letterId = letterId;
this.message = message;
this.eventTime = eventTime;
this.isChecked = isChecked;
this.sendId = sendId;
this.receiveId = receiveId;
}

public int getLetterId() {
return letterId;
}

public void setLetterId(int letterId) {
this.letterId = letterId;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public LocalDateTime getEventTime() {
return eventTime;
}

public void setEventTime(LocalDateTime eventTime) {
this.eventTime = eventTime;
}

public boolean isChecked() {
return isChecked;
}

public void setChecked(boolean checked) {
isChecked = checked;
}

public String getSendId() {
return sendId;
}

public void setSendId(String sendId) {
this.sendId = sendId;
}

public String getReceiveId() {
return receiveId;
}

public void setReceiveId(String receiveId) {
this.receiveId = receiveId;
}

@Override
public String toString() {
return "Letter{" +
"letterId=" + letterId +
", message='" + message + '\'' +
", eventTime=" + eventTime +
", isChecked=" + isChecked +
", sendId='" + sendId + '\'' +
", receiveId='" + receiveId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.omoknoone.onionhotsayyo.letter.command.controller;

import java.util.List;

import org.modelmapper.ModelMapper;
import org.omoknoone.onionhotsayyo.letter.command.dto.LetterDTO;
import org.omoknoone.onionhotsayyo.letter.command.service.LetterService;
import org.omoknoone.onionhotsayyo.notification.command.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/letters")
public class LetterController {
private final LetterService letterService;
private final NotificationService notificationService;
private final ModelMapper modelMapper;

@Autowired
public LetterController(LetterService letterService, NotificationService notificationService,
ModelMapper modelMapper) {
this.letterService = letterService;
this.notificationService = notificationService;
this.modelMapper = modelMapper;
}

// 쪽지 발송
@PostMapping("/send")
public ResponseEntity<LetterDTO> sendLetter(@RequestBody LetterDTO letterDTO) {
LetterDTO sendLetter = letterService.sendLetter(letterDTO);
return ResponseEntity.status(HttpStatus.CREATED).body(sendLetter);
}

// 쪽지 수신 확인
@PutMapping("/check/{letterId}")
public ResponseEntity<LetterDTO> checkLetter(@PathVariable(name = "letterId") int letterId) {
LetterDTO readLetter = letterService.checkLetter(letterId);
return ResponseEntity.status(HttpStatus.OK).body(readLetter);
}


// // 송수신 쪽지 모두 확인
// @GetMapping("/list/myletter/{memberId}")
// public ResponseEntity<List<LetterDTO>> viewLetterByMe(@PathVariable(name = "memberId") String memberId) {
// List<LetterDTO> letterList = letterService.viewLetterByMe(memberId);
// return ResponseEntity.status(HttpStatus.OK).body(letterList);
// }

// 내가 보낸 쪽지
@GetMapping("/mysendletter/{memberId}")
public ResponseEntity<List<LetterDTO>> viewSendLetter(@PathVariable(name = "memberId") String memberId) {
List<LetterDTO> sendLetterList = letterService.viewSendLetter(memberId);
return ResponseEntity.status(HttpStatus.OK).body(sendLetterList);
}

// 내가 받은 쪽지
@GetMapping("/myreceiveletter/{memberId}")
public ResponseEntity<List<LetterDTO>> viewReceiveLetter(@PathVariable(name = "memberId") String memberId) {
List<LetterDTO> receiveLetter = letterService.viewReceiveLetter(memberId);
return ResponseEntity.status(HttpStatus.OK).body(receiveLetter);
}

// 안 읽은 상태의 쪽지 조회
@GetMapping("/unreadletter/{memberId}")
public ResponseEntity<List<LetterDTO>> viewUnreadLetter(@PathVariable(name = "memberId") String memberId) {
List<LetterDTO> unreadletter = letterService.viewUnreadLetter(memberId);
return ResponseEntity.status(HttpStatus.OK).body(unreadletter);
}




@GetMapping("/health_check")
public String healthCheck() {
return "Good";
}
}
Loading

0 comments on commit 108501c

Please sign in to comment.