Skip to content

Commit

Permalink
[#66]Refactor: 서버 코드 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
redhi committed Apr 30, 2022
1 parent af17aa4 commit 3106122
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 71 deletions.
1 change: 0 additions & 1 deletion backend/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public class MyPageResponseSearch {
private MyPageUser user;
private List<MyPageTransaction> likeTransaction=new ArrayList<>();
private List<MyPageTransaction> writeTransaction=new ArrayList<>();
private List<MyPageFreeContent> freeContent=new ArrayList<>();




}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,16 +17,21 @@ 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;
this.nickname=nickname;
this.reliability=reliability;
this.is_mine=is_mine;
this.status=status;
this.profile_url=profile_url;
this.user_status=user_status;

}
}
}
62 changes: 50 additions & 12 deletions backend/src/main/java/moviegoods/movie/service/ChatRoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,34 @@ 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());

Optional<Transaction> relatedTransaction = transactionRepository.findById(requestDto.getTransaction_id());
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;
Expand All @@ -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;
}
}
Expand All @@ -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();
Expand All @@ -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;
}
Expand All @@ -137,6 +169,7 @@ public List<DirectMessageListResponseDto> 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;
Expand All @@ -146,7 +179,8 @@ public List<DirectMessageListResponseDto> 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<Chat_Room_Join> list = em.createQuery(searchJpql, Chat_Room_Join.class).getResultList();
Expand Down Expand Up @@ -175,6 +209,10 @@ public List<DirectMessageListResponseDto> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

@RequiredArgsConstructor
@Service
@Slf4j
public class MainService {
private final EntityManager em;
private final LikeBasketsService likeBasketsService;
Expand Down Expand Up @@ -71,8 +72,12 @@ public List<MainDailyCommunityResponseDto> 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;
}
Expand Down
Loading

0 comments on commit 3106122

Please sign in to comment.