From 3106122f38f9c2e10620d328573a4d3174c02012 Mon Sep 17 00:00:00 2001 From: redhi Date: Sat, 30 Apr 2022 16:45:02 +0900 Subject: [PATCH] =?UTF-8?q?[#66]Refactor:=20=EC=84=9C=EB=B2=84=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/README.md | 1 - .../DirectMessageCreateRoomResponseDto.java | 17 ++++- .../main/MainDailyCommunityResponseDto.java | 6 ++ .../domain/dto/mypage/MyPageFreeContent.java | 24 ------- .../dto/mypage/MyPageResponseSearch.java | 3 +- .../domain/dto/mypage/MyPageTransaction.java | 10 ++- .../movie/service/ChatRoomService.java | 62 +++++++++++++++---- .../movie/service/GeneralBoardService.java | 5 ++ .../service/InformationShareService.java | 6 ++ .../moviegoods/movie/service/MainService.java | 7 ++- .../movie/service/MyPageService.java | 54 ++++++++-------- 11 files changed, 124 insertions(+), 71 deletions(-) delete mode 100644 backend/README.md delete mode 100644 backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageFreeContent.java diff --git a/backend/README.md b/backend/README.md deleted file mode 100644 index f41c0fa..0000000 --- a/backend/README.md +++ /dev/null @@ -1 +0,0 @@ -# collector \ No newline at end of file diff --git a/backend/src/main/java/moviegoods/movie/domain/dto/directMessage/DirectMessageCreateRoomResponseDto.java b/backend/src/main/java/moviegoods/movie/domain/dto/directMessage/DirectMessageCreateRoomResponseDto.java index 8fbff95..3a959ec 100644 --- a/backend/src/main/java/moviegoods/movie/domain/dto/directMessage/DirectMessageCreateRoomResponseDto.java +++ b/backend/src/main/java/moviegoods/movie/domain/dto/directMessage/DirectMessageCreateRoomResponseDto.java @@ -3,6 +3,9 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import moviegoods.movie.domain.entity.User.UserStatus; + +import java.time.LocalDateTime; @Data @NoArgsConstructor @@ -11,6 +14,14 @@ public class DirectMessageCreateRoomResponseDto { private boolean result; private Long chat_room_id; - private Long user_id; - private Long writer_id; -} + private Long not_mine_id; + private String not_mine_nickname; + private String not_mine_profile_url; + private Long not_mine_reliability; + private UserStatus user_status; + private UserStatus not_mine_user_status; + private Long transaction_id; + private Boolean is_complete; + private String recent_message; + private LocalDateTime recent_message_date; +} \ No newline at end of file diff --git a/backend/src/main/java/moviegoods/movie/domain/dto/main/MainDailyCommunityResponseDto.java b/backend/src/main/java/moviegoods/movie/domain/dto/main/MainDailyCommunityResponseDto.java index d74f099..d5ef8b9 100644 --- a/backend/src/main/java/moviegoods/movie/domain/dto/main/MainDailyCommunityResponseDto.java +++ b/backend/src/main/java/moviegoods/movie/domain/dto/main/MainDailyCommunityResponseDto.java @@ -4,11 +4,17 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; + @Data @NoArgsConstructor @AllArgsConstructor public class MainDailyCommunityResponseDto { private Long post_id; private String title; + private String content; + private Long views; + private Long comments_num; + private LocalDateTime written_date; } diff --git a/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageFreeContent.java b/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageFreeContent.java deleted file mode 100644 index 057b048..0000000 --- a/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageFreeContent.java +++ /dev/null @@ -1,24 +0,0 @@ -package moviegoods.movie.domain.dto.mypage; - -import lombok.Data; - -import java.time.LocalDateTime; - - -@Data -public class MyPageFreeContent { - - Long post_id; - String title; - LocalDateTime written_date; - String category; - String content; - - public MyPageFreeContent(Long post_id, String title, LocalDateTime written_date, String category, String content){ - this.category=category; - this.post_id=post_id; - this.title=title; - this.written_date=written_date; - this.content=content; - } -} \ No newline at end of file diff --git a/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageResponseSearch.java b/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageResponseSearch.java index 1cb6da3..1f2d929 100644 --- a/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageResponseSearch.java +++ b/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageResponseSearch.java @@ -17,9 +17,8 @@ public class MyPageResponseSearch { private MyPageUser user; private List likeTransaction=new ArrayList<>(); private List writeTransaction=new ArrayList<>(); - private List freeContent=new ArrayList<>(); -} \ No newline at end of file +} diff --git a/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageTransaction.java b/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageTransaction.java index 0e92f5c..a7adc92 100644 --- a/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageTransaction.java +++ b/backend/src/main/java/moviegoods/movie/domain/dto/mypage/MyPageTransaction.java @@ -3,6 +3,7 @@ import lombok.Data; import moviegoods.movie.domain.entity.Transaction.Status; +import moviegoods.movie.domain.entity.User.UserStatus; import java.time.LocalDateTime; @@ -16,9 +17,12 @@ public class MyPageTransaction { Long reliability; Boolean is_mine; Status status; + UserStatus user_status; + String profile_url; - public MyPageTransaction(Long transaction_id, String content, LocalDateTime written_date,String nickname,Long reliability,Boolean is_mine,Status status){ + + public MyPageTransaction(Long transaction_id, String content, LocalDateTime written_date,String nickname,Long reliability,Boolean is_mine,Status status,String profile_url,UserStatus user_status){ this.transaction_id=transaction_id; this.content=content; this.written_date=written_date; @@ -26,6 +30,8 @@ public MyPageTransaction(Long transaction_id, String content, LocalDateTime writ this.reliability=reliability; this.is_mine=is_mine; this.status=status; + this.profile_url=profile_url; + this.user_status=user_status; } -} +} \ No newline at end of file diff --git a/backend/src/main/java/moviegoods/movie/service/ChatRoomService.java b/backend/src/main/java/moviegoods/movie/service/ChatRoomService.java index 0c2c75a..d397a73 100644 --- a/backend/src/main/java/moviegoods/movie/service/ChatRoomService.java +++ b/backend/src/main/java/moviegoods/movie/service/ChatRoomService.java @@ -38,11 +38,15 @@ public DirectMessageCreateRoomResponseDto createRoom(User loginUser, DirectMessa if (loginUser == null) { DirectMessageCreateRoomResponseDto responseDto = - new DirectMessageCreateRoomResponseDto(false, null, null, null); + new DirectMessageCreateRoomResponseDto(false, null, null, null, null, null, null, null, null, null, null, null); return responseDto; - } + //------------------------- + String recent_message = null; + LocalDateTime recent_message_date = null; + //------------------------- Long user_id = loginUser.getUser_id(); + UserStatus user_status = loginUser.getUser_status(); log.info("transaction_id={}", requestDto.getTransaction_id()); @@ -50,7 +54,18 @@ public DirectMessageCreateRoomResponseDto createRoom(User loginUser, DirectMessa if(relatedTransaction.isPresent()) { Transaction transaction = relatedTransaction.get(); Long transaction_id = transaction.getTransaction_id(); - Long writer_id = transaction.getUser().getUser_id(); + Boolean is_complete = false; + Status transaction_status = transaction.getStatus(); + if(transaction_status.equals(Status.마감)) { + is_complete = true; + } + User notMineUser = transaction.getUser(); + Long not_mine_id = notMineUser.getUser_id(); + String not_mine_nickname = notMineUser.getNickname(); + String not_mine_profile_url = notMineUser.getProfile_url(); + Long not_mine_reliability = notMineUser.getReliability(); + UserStatus not_mine_user_status = notMineUser.getUser_status(); + //중복 확인 boolean ifExistUserId = false; @@ -68,7 +83,7 @@ public DirectMessageCreateRoomResponseDto createRoom(User loginUser, DirectMessa if(exist_user_id == user_id) { ifExistUserId = true; } - if(exist_user_id == writer_id) { + if(exist_user_id == not_mine_id) { ifExixtWriterId = true; } } @@ -80,22 +95,31 @@ else if(ifExistUserId && ifExixtWriterId) { } //중복일때 - if(ifExistUserId && ifExixtWriterId) { + if(ifExistUserId && ifExixtWriterId && (exist_chat_room_id != null)) { DirectMessageCreateRoomResponseDto responseDto = new DirectMessageCreateRoomResponseDto(true, exist_chat_room_id, - user_id, - writer_id); + not_mine_id, + not_mine_nickname, + not_mine_profile_url, + not_mine_reliability, + user_status, + not_mine_user_status, + transaction_id, + is_complete, + recent_message, + recent_message_date); return responseDto; } //중복이 아닐때 User user = userRepository.getById(user_id); - User writerUser = userRepository.getById(writer_id); + User writerUser = userRepository.getById(not_mine_id); Chat_Room chat_room = new Chat_Room(); chat_room.setTransaction(transaction); + chat_room.setCreate_date(LocalDateTime.now()); Chat_Room savedMessageRoom = chatRoomRepository.save(chat_room); Chat_Room_Join chat_room_join = new Chat_Room_Join(); @@ -115,15 +139,23 @@ else if(ifExistUserId && ifExixtWriterId) { DirectMessageCreateRoomResponseDto responseDto = new DirectMessageCreateRoomResponseDto(true, savedMessageRoom.getChat_room_id(), - user.getUser_id(), - writer_id); + not_mine_id, + not_mine_nickname, + not_mine_profile_url, + not_mine_reliability, + user_status, + not_mine_user_status, + transaction_id, + is_complete, + recent_message, + recent_message_date); return responseDto; } else { DirectMessageCreateRoomResponseDto responseDto = - new DirectMessageCreateRoomResponseDto(false, null, null, null); + new DirectMessageCreateRoomResponseDto(false, null, null, null, null, null, null, null, null, null, null, null); return responseDto; } @@ -137,6 +169,7 @@ public List findMessageRooms(User loginUser, Long for (Chat_Room_Join chat_room_join : chat_room_joins) { Chat_Room chat_room = chat_room_join.getChat_room(); Long chat_room_id = chat_room.getChat_room_id(); + LocalDateTime create_date = chat_room.getCreate_date(); //DM창 생성시간 Long not_mine_id = null; String not_mine_nickname = null; @@ -146,7 +179,8 @@ public List findMessageRooms(User loginUser, Long Long transaction_id = null; Boolean is_complete = false; String recent_message = null; - LocalDateTime recent_message_date = LocalDateTime.of(2019, 11, 12, 12, 32,22,3333); +// LocalDateTime recent_message_date = LocalDateTime.of(2019, 11, 12, 12, 32,22,3333); + LocalDateTime recent_message_date = null; String searchJpql = "select c from chat_room_join c where c.chat_room = '" + chat_room_id + "'"; List list = em.createQuery(searchJpql, Chat_Room_Join.class).getResultList(); @@ -175,6 +209,10 @@ public List findMessageRooms(User loginUser, Long recent_message = message.getContent_detail().getContent(); recent_message_date = message.getContent_detail().getWritten_date(); } + else { + //메시지가 없으면 방 생성날짜로 + recent_message_date = create_date; + } roomsList.add(new DirectMessageListResponseDto( chat_room_id, diff --git a/backend/src/main/java/moviegoods/movie/service/GeneralBoardService.java b/backend/src/main/java/moviegoods/movie/service/GeneralBoardService.java index 0b995cf..e88c9cd 100644 --- a/backend/src/main/java/moviegoods/movie/service/GeneralBoardService.java +++ b/backend/src/main/java/moviegoods/movie/service/GeneralBoardService.java @@ -191,6 +191,11 @@ public ResultResponseDto saveComment(User loginUser, GeneralBoardCommentRequestD Comment saveEntity = Comment.builder().post(post).user(loginUser).content_detail(content_detail).build(); commentRepository.save(saveEntity); + if(post.getViews()>0){ + post.setViews(post.getViews()-1); + postRepository.save(post); + } + resultResponseDto.setResult(true); return resultResponseDto; diff --git a/backend/src/main/java/moviegoods/movie/service/InformationShareService.java b/backend/src/main/java/moviegoods/movie/service/InformationShareService.java index fde92f1..27d513a 100644 --- a/backend/src/main/java/moviegoods/movie/service/InformationShareService.java +++ b/backend/src/main/java/moviegoods/movie/service/InformationShareService.java @@ -379,6 +379,11 @@ public ResultResponseDto saveComment(User loginUser, InformationShareRequestSave commentRepository.save(saveEntity); + if(post.getViews()>0){ + post.setViews(post.getViews()-1); + postRepository.save(post); + } + resultResponseDto.setResult(true); return resultResponseDto; @@ -406,6 +411,7 @@ public Boolean deleteComment(User loginUser, InformationShareRequestDeleteCommen } Long comment_id=isrdc.getComment_id(); + commentRepository.deleteById(comment_id); Boolean result=commentRepository.existsById(comment_id); return result; diff --git a/backend/src/main/java/moviegoods/movie/service/MainService.java b/backend/src/main/java/moviegoods/movie/service/MainService.java index eba756c..efec7a8 100644 --- a/backend/src/main/java/moviegoods/movie/service/MainService.java +++ b/backend/src/main/java/moviegoods/movie/service/MainService.java @@ -21,6 +21,7 @@ @RequiredArgsConstructor @Service +@Slf4j public class MainService { private final EntityManager em; private final LikeBasketsService likeBasketsService; @@ -71,8 +72,12 @@ public List dailyCommunity(MainDailyCommunityRequ for (Post post : postList) { Long post_id = post.getPost_id(); String title = post.getTitle(); + String content = post.getContent_detail().getContent(); + Long views = post.getViews(); + Long comments_num = Long.valueOf(post.getComments().size()); + LocalDateTime written_date = post.getContent_detail().getWritten_date(); - searchList.add(new MainDailyCommunityResponseDto(post_id, title)); + searchList.add(new MainDailyCommunityResponseDto(post_id, title,content,views,comments_num,written_date)); } return searchList; } diff --git a/backend/src/main/java/moviegoods/movie/service/MyPageService.java b/backend/src/main/java/moviegoods/movie/service/MyPageService.java index 902f1a3..6ad245d 100644 --- a/backend/src/main/java/moviegoods/movie/service/MyPageService.java +++ b/backend/src/main/java/moviegoods/movie/service/MyPageService.java @@ -61,8 +61,8 @@ public MyPageResponseSearch search(User loginUser,MyPageRequestSearch mprs){ } - //작성한 정보공유글 - List row1= em.createQuery("select p.post_id, p.title, c.written_date , p.category, c.content from post p join p.content_detail c left join p.user u where u.user_id =:user_id and p.category='정보공유' order by c.written_date DESC").setParameter("user_id",user_id).getResultList(); + //작성한 글 + List row1= em.createQuery("select p.post_id, p.title, c.written_date , p.category, c.content from post p join p.content_detail c left join p.user u where u.user_id =:user_id order by c.written_date DESC").setParameter("user_id",user_id).getResultList(); for (Object[] objects : row1) { @@ -75,23 +75,9 @@ public MyPageResponseSearch search(User loginUser,MyPageRequestSearch mprs){ myPageResponseSearch.getContent().add(new MyPageContent(post_id,title,written_date,category,content)); } - //작성한 자유게시판글 - List row7= em.createQuery("select p.post_id, p.title, c.written_date , p.category, c.content from post p join p.content_detail c left join p.user u where u.user_id =:user_id and p.category='자유' order by c.written_date DESC").setParameter("user_id",user_id).getResultList(); - - - for (Object[] objects : row7) { - Long post_id=(Long)objects[0]; - String title=(String)objects[1]; - LocalDateTime written_date=(LocalDateTime)objects[2]; - String category=(String)objects[3]; - String content=(String)objects[4]; - - myPageResponseSearch.getFreeContent().add(new MyPageFreeContent(post_id,title,written_date,category,content)); - } - - - List row2= em.createQuery("select t.transaction_id , c.content , c.written_date , u.nickname ,u.reliability,u.user_id,t.status from transaction t join t.content_detail c left join t.user u where u.user_id =:user_id order by c.written_date DESC").setParameter("user_id",user_id).getResultList(); + //작성한 대리구매글 + List row2= em.createQuery("select t.transaction_id , c.content , c.written_date , u.nickname ,u.reliability,u.user_id,t.status, u.profile_url,u.user_status from transaction t join t.content_detail c left join t.user u where u.user_id =:user_id order by c.written_date DESC").setParameter("user_id",user_id).getResultList(); for (Object[] objects : row2) { @@ -107,32 +93,39 @@ public MyPageResponseSearch search(User loginUser,MyPageRequestSearch mprs){ } Status status=(Status)objects[6]; + String profile_url=(String)objects[7]; + UserStatus user_status=(UserStatus)objects[8]; - myPageResponseSearch.getWriteTransaction().add(new MyPageTransaction(transaction_id,content,written_date,nickname,reliability,is_mine,status)); + myPageResponseSearch.getWriteTransaction().add(new MyPageTransaction(transaction_id,content,written_date,nickname,reliability,is_mine,status,profile_url,user_status)); } - List row3= em.createQuery("select t.transaction_id ,u.nickname,u.reliability,u.user_id from like_basket b join b.user u left join b.transaction t where u.user_id =:user_id ").setParameter("user_id",user_id).getResultList(); + //좋아요한 대리구매글 + List row3= em.createQuery("select t.transaction_id ,u.nickname,u.reliability,u.user_id, u.profile_url, u.user_status from like_basket b join b.user u left join b.transaction t where u.user_id =:user_id order by t.transaction_id DESC").setParameter("user_id",user_id).getResultList(); for (Object[] objects : row3) { Boolean is_mine=false; Long transaction_id=(Long)objects[0]; String nickname=(String)objects[1]; Long reliability=(Long)objects[2]; Long user_id2=(Long)objects[3]; + String profile_url=(String)objects[4]; + UserStatus user_status=(UserStatus)objects[5]; if(user_id==user_id2){ is_mine=true; } - List row4= em.createQuery("select c.content, c.written_date ,t.status from transaction t join t.content_detail c where t.transaction_id =:transaction_id").setParameter("transaction_id",transaction_id).getResultList(); + List row4= em.createQuery("select c.content, c.written_date ,t.status from transaction t join t.content_detail c where t.transaction_id =:transaction_id ").setParameter("transaction_id",transaction_id).getResultList(); if(row4.size()!=0){ Object[] result4=row4.get(0); String content=(String)result4[0]; LocalDateTime written_date=(LocalDateTime)result4[1]; Status status=(Status)result4[2]; - myPageResponseSearch.getLikeTransaction().add(new MyPageTransaction(transaction_id,content,written_date,nickname,reliability,is_mine,status)); + myPageResponseSearch.getLikeTransaction().add(new MyPageTransaction(transaction_id,content,written_date,nickname,reliability,is_mine,status,profile_url,user_status)); } } - List row5= em.createQuery("select e.event_id, e.title, e.thumbnail_url, e.start_date, e.end_date from like_basket b join b.event e left join b.user u where u.user_id=:user_id").setParameter("user_id",user_id).getResultList(); + //좋아요한 이벤트 + + List row5= em.createQuery("select e.event_id, e.title, e.thumbnail_url, e.start_date, e.end_date from like_basket b join b.event e left join b.user u where u.user_id=:user_id order by b.like_basket_id DESC").setParameter("user_id",user_id).getResultList(); for (Object[] objects : row5) { Long event_id=(Long)objects[0]; String event_title=(String)objects[1]; @@ -189,12 +182,20 @@ public Boolean withdrawal(User loginUser,MyPageRequestWithdrawal mrwd){ user_id = loginUser.getUser_id(); } - UserStatus newStatus=탈퇴; + String basicUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlx2rvqRVwn6S5uXPkHl856CcYvV2z8bUMyw&usqp=CAU"; User user=userRepository.findById(user_id).get(); - user.setUser_status(newStatus); + user.setUser_status(탈퇴); + user.setEmail("0"); + user.setNickname("0"); + user.setPassword("0"); + user.setProfile_url(basicUrl); + + userRepository.save(user); - if(userRepository.findById(user_id).get().getUser_status()==newStatus){ + + + if(userRepository.findById(user_id).get().getUser_status()== 탈퇴){ check=true; } return check; @@ -220,4 +221,5 @@ public Result nicknameDuplicate(MyPageRequestNicknameDuplicateDto mpnd){ } + } \ No newline at end of file