Skip to content

Commit

Permalink
Merge pull request #533 from nheo9143/feat/changenoti-532
Browse files Browse the repository at this point in the history
[feat] changenoti message close #532
  • Loading branch information
nheo9143 authored Mar 17, 2022
2 parents c410a8d + af1d353 commit 06bb6da
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ void deleteComment(@RequestParam("commentId") @Positive (message = "{invalid.req

CommentResponseDTO findCommentByUserId (@SortDefault.SortDefaults({@SortDefault(sort = "id", direction = Sort.Direction.DESC)}) Pageable pageable,
HttpServletRequest request);
CommentListResponseDTO findCommentByPost (@RequestParam("boardId") @Positive (message = "{invalid.request}")Long boardId, @RequestParam("postId") @Positive (message = "{invalid.request}")Long postId, HttpServletRequest request);
CommentListResponseDTO findCommentByPost (@RequestParam("postId") @Positive (message = "{invalid.request}")Long postId, HttpServletRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,13 @@ public void saveComment(Long boardId, Long postId, CommentRequestDTO requestDTO,
Post post = postService.findById(postId);
if (post.getCommentCnt() >= 1000)
throw new BusinessException("{invalid.request}");
User author = userService.findById(post.getAuthorId());
User postAuthor = userService.findById(post.getAuthorId());
commentService.save(boardId,post, user, requestDTO.getContent());
postService.updateComment(postId, 1L);
if (author.getId() != user.getId()) {
if (author.getIsChecked() == false) {
Noti noti = notificationService.findByUserAndPost(author, post);
if (noti != null)
notificationService.delete(noti.getId());
}
notificationService.save(author, post, "post", post.getTitle(), requestDTO.getContent());
userService.setCheck(author);
notificationService.checkNoti(postAuthor, user, post);
if (postAuthor.getId() != user.getId()) {
notificationService.save(postAuthor, post, "post", post.getTitle(), requestDTO.getContent());
userService.setCheck(postAuthor);
}
}

Expand Down Expand Up @@ -88,7 +84,7 @@ public CommentResponseDTO findCommentByUserId (Pageable pageable, HttpServletReq
}

@RequestMapping(value={"/comment"}, method = RequestMethod.GET)
public CommentListResponseDTO findCommentByPost (Long boardId, Long postId, HttpServletRequest request){
public CommentListResponseDTO findCommentByPost (Long postId, HttpServletRequest request){
Post post = postService.findById(postId);
User user = tokenService.findUserByAccessToken(HeaderUtil.getAccessToken(request));
HashMap<Long, CommentDTO> commentDTOHashMap = new LinkedHashMap<>(1001, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import javax.validation.Valid;

public interface ReCommentController {
void createReComment(@RequestParam(value = "commentId")Long targetCmmtId, @RequestBody @Valid CommentRequestDTO content, HttpServletRequest request);
void saveReComment(@RequestParam(value = "commentId")Long targetCmmtId, @RequestBody @Valid CommentRequestDTO content, HttpServletRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ReCommentControllerImpl implements ReCommentController {
private final NotificationService notificationService;

@RequestMapping(value = "/recomment", method = RequestMethod.POST)
public void createReComment(Long targetCmmtId, CommentRequestDTO requestDTO, HttpServletRequest request) {
public void saveReComment(Long targetCmmtId, CommentRequestDTO requestDTO, HttpServletRequest request) {
Comment targetCmmt = commentService.findCommentById(targetCmmtId);
Comment rootCmmt = targetCmmt;
while (rootCmmt.getRootCommentId() != null)
Expand All @@ -43,26 +43,18 @@ public void createReComment(Long targetCmmtId, CommentRequestDTO requestDTO, Htt
Post post = rootCmmt.getPost();
reCommentService.save(targetCmmt, rootCmmtId, user.getId(), requestDTO.getContent());
postService.updateComment(rootCmmt.getPost().getId(), 1L);
User rtAuthor = userService.findById(rootCmmt.getAuthorId());
User targetAuthor = userService.findById(rootCmmt.getTargetAuthorId());
User pstAuthor = userService.findById(post.getAuthorId());

if (pstAuthor.getId() != user.getId()) {
if (pstAuthor.getIsChecked() == false) {
Noti noti = notificationService.findByUserAndPost(pstAuthor, post);
if (noti != null)
notificationService.delete(noti.getId());
}
notificationService.checkNoti(pstAuthor, user, post);
notificationService.save(pstAuthor, post, "post", post.getTitle(), requestDTO.getContent());
userService.setCheck(pstAuthor);
}
if (rtAuthor.getId() != user.getId()) {
if (rtAuthor.getIsChecked() == false) {
Noti noti = notificationService.findByUserAndPost(rtAuthor, post);
if (noti != null)
notificationService.delete(noti.getId());
}
notificationService.save(rtAuthor, post, "comment", rootCmmt.getContent(), requestDTO.getContent());
userService.setCheck(rtAuthor);
}
if (targetAuthor.getId() != user.getId()) {
notificationService.checkNoti(targetAuthor, user, post);
notificationService.save(targetAuthor, post, "comment", rootCmmt.getContent(), requestDTO.getContent());
userService.setCheck(targetAuthor);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
public class NotiDTO {
Expand All @@ -12,12 +14,14 @@ public class NotiDTO {
private String contentType;
private String title;
private String content;
private LocalDateTime modifiedDate;

public NotiDTO(Noti noti) {
this.id = noti.getId();
this.postId = noti.getPost().getId();
this.contentType = noti.getContentType();
this.title = noti.getTitle();
this.content = noti.getContent();
this.modifiedDate = noti.getModifiedDate();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.blind.api.domain.notification.controller;

import com.blind.api.domain.notification.DTO.NotiDTO;
import com.blind.api.domain.notification.domain.Noti;
import org.springframework.web.bind.annotation.RequestParam;

Expand All @@ -8,6 +9,6 @@

public interface NotificationController {

List<Noti> getNoti(HttpServletRequest request);
List<NotiDTO> getNoti(HttpServletRequest request);
void delNoti(HttpServletRequest request, @RequestParam("id") Long id);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.blind.api.domain.notification.controller;

import com.blind.api.domain.notification.DTO.NotiDTO;
import com.blind.api.domain.notification.domain.Noti;
import com.blind.api.domain.notification.service.NotificationService;
import com.blind.api.domain.security.jwt.v1.service.TokenService;
Expand All @@ -12,6 +13,7 @@
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
Expand All @@ -22,15 +24,26 @@ public class NotificationControllerImpl implements NotificationController {
private final TokenService tokenService;

@RequestMapping(value = {"/notification"}, method= RequestMethod.GET)
public List<Noti> getNoti(HttpServletRequest request){
public List<NotiDTO> getNoti(HttpServletRequest request){
User user = tokenService.findUserByAccessToken(HeaderUtil.getAccessToken(request));
List<Noti> notiList = notificationService.getNoti(user);
List<NotiDTO> dtoList = new ArrayList<>();
notiList.stream().forEach(noti -> {
dtoList.add(new NotiDTO(noti));
});
userService.delCheck(user);
return notificationService.getNoti(user);
return dtoList;
}

@RequestMapping(value = {"/notification"}, method= RequestMethod.DELETE)
public void delNoti(HttpServletRequest request, Long id){
User user = tokenService.findUserByAccessToken(HeaderUtil.getAccessToken(request));
notificationService.delete(id);
}

@RequestMapping(value = {"/notification/all"}, method= RequestMethod.DELETE)
public void delAllNoti(HttpServletRequest request, Long id){
User user = tokenService.findUserByAccessToken(HeaderUtil.getAccessToken(request));
notificationService.deleteByUser(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.blind.api.domain.post.v2.domain.Post;
import com.blind.api.domain.user.v2.domain.User;
import com.blind.api.global.entity.BaseTimeEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -16,7 +17,7 @@
@Setter
@NoArgsConstructor
@DynamicInsert
public class Noti {
public class Noti extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
Expand All @@ -40,6 +41,9 @@ public class Noti {
@Column(name = "content")
private String content;

@Column(name = "count", columnDefinition = "Integer default 1")
private Long count;

@Builder
public Noti(User user, Post post, String contentType, String title, String content) {
this.user = user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import com.blind.api.domain.post.v2.domain.Post;
import com.blind.api.domain.user.v2.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface NotificationRepository extends JpaRepository<Noti, Long> {
List<Noti> findByUser(User user);
List<Noti> findByUserOrderByCreatedDateDesc(User user);
void deleteById(Long id);
Noti findByUserAndPost(User user, Post post);
void deleteAllByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

@Service
@AllArgsConstructor
Expand All @@ -18,18 +17,25 @@ public class NotificationService {

@Transactional
public Noti save(User user, Post post, String contentType, String title, String content) {
return notificationRepository.save(Noti.builder()
.user(user)
.post(post)
.contentType(contentType)
.title(title)
.content(content)
.build());
Noti noti = notificationRepository.findByUserAndPost(user, post);
if (noti != null) {
noti = notificationRepository.save(Noti.builder()
.user(user)
.post(post)
.contentType(contentType)
.title(title)
.content(content)
.build());
} else {
noti.setContent(content);
noti.setCount(noti.getCount() + 1L);
}
return noti;
}

@Transactional
public List<Noti> getNoti(User user) {
return notificationRepository.findByUser(user);
return notificationRepository.findByUserOrderByCreatedDateDesc(user);
}

@Transactional
Expand All @@ -40,4 +46,18 @@ public void delete(Long id) {
public Noti findByUserAndPost(User user, Post post) {
return notificationRepository.findByUserAndPost(user, post);
}

@Transactional
public void deleteByUser(User user) {
notificationRepository.deleteAllByUser(user);
}

@Transactional
public void checkNoti(User rootUser, User authorUser, Post post) {
if (rootUser.getIsChecked() == true) {
Noti noti = notificationRepository.findByUserAndPost(rootUser, post);
if (noti != null)
notificationRepository.deleteById(post.getId());
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 06bb6da

Please sign in to comment.