Skip to content

Commit

Permalink
REFACTOR: 게시글조회/전체채팅조회 날짜 포맷
Browse files Browse the repository at this point in the history
  • Loading branch information
givesilverstick committed Aug 18, 2023
1 parent fe97bd8 commit 4151bcc
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.wonderwoman.chatting.request.ChatRoomStatusRequest;
import com.example.wonderwoman.chatting.response.ChatMessageDto;
import com.example.wonderwoman.chatting.response.ChatRoomInfoResponse;
import com.example.wonderwoman.chatting.response.ChatRoomListDto;
import com.example.wonderwoman.chatting.service.ChatService;
import com.example.wonderwoman.chatting.service.ResponseService;
import com.example.wonderwoman.common.dto.NormalResponseDto;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class ChatRoomController {

//사용자별 전체 방 조회(요청, 출동 상관 없음) -> 완챝
@GetMapping("/rooms")
public ListResult<ChatRoomInfoResponse> rooms(@CurrentUser Member member) {
public ListResult<ChatRoomListDto> rooms(@CurrentUser Member member) {
return responseService.getListResult(chatService.findAllRoom(member));
}

Expand Down Expand Up @@ -64,7 +65,7 @@ public ResponseEntity<ChatRoomInfoResponse> createRoom(@CurrentUser Member membe
@PostMapping("/room/status")
public ResponseEntity<ChatRoomInfoResponse> updateRoomStatus(@CurrentUser Member member, @RequestBody ChatRoomStatusRequest request) {
chatService.updatePostStatus(request.getChatRoomId(), request.getStatus());

return ResponseEntity.ok(chatService.findRoomById(member, request.getChatRoomId()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.example.wonderwoman.chatting.response;

import com.example.wonderwoman.delivery.entity.Building;
import com.example.wonderwoman.chatting.entity.ChatRoom;
import com.example.wonderwoman.delivery.entity.PostStatus;
import com.example.wonderwoman.delivery.entity.SanitarySize;
import com.example.wonderwoman.member.entity.Member;
import com.example.wonderwoman.member.entity.School;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.format.DateTimeFormatter;
import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ChatRoomListDto {

private String id;

private Long userId;

private String userNickName;

private String userImg;

private PostStatus postStatus;

private School school;

private List<Building> building;

private SanitarySize sanitarySize;

private int sanitaryNum;

private String createdAt;

private String updatedAt;

private String lastMessage;

private boolean isWriter;

public static ChatRoomListDto of(ChatRoom chatRoom, Member member, boolean isWriter) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 M월 d일 HH:mm");
String createdAtString = chatRoom.getJoinedAt().format(formatter);
String updatedAtString = chatRoom.getUpdatedAt().format(formatter);

return ChatRoomListDto.builder()
.id(chatRoom.getId())
.userId(member.getId())
.userNickName(member.getNickname())
.userImg(member.getImgUrl())
.postStatus(chatRoom.getDeliveryPost().getPostStatus())
.school(chatRoom.getDeliveryPost().getSchool())
.building(chatRoom.getDeliveryPost().getBuilding())
.sanitarySize(chatRoom.getDeliveryPost().getSanitarySize())
.sanitaryNum(chatRoom.getDeliveryPost().getSanitaryNum())
.createdAt(createdAtString)
.updatedAt(updatedAtString)
.lastMessage(chatRoom.getLastMessage())
.isWriter(isWriter)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.wonderwoman.chatting.repository.ChatRoomRepository;
import com.example.wonderwoman.chatting.response.ChatMessageDto;
import com.example.wonderwoman.chatting.response.ChatRoomInfoResponse;
import com.example.wonderwoman.chatting.response.ChatRoomListDto;
import com.example.wonderwoman.delivery.entity.DeliveryPost;
import com.example.wonderwoman.delivery.entity.PostStatus;
import com.example.wonderwoman.delivery.entity.ReqType;
Expand Down Expand Up @@ -57,19 +58,19 @@ private void init() {
}

//채팅방 리스트 조회
public List<ChatRoomInfoResponse> findAllRoom(Member member) {
public List<ChatRoomListDto> findAllRoom(Member member) {
return chatRoomRepository.findChatRoomsByMember(member.getId())
.stream()
.sorted(Comparator.comparing(ChatRoom::getUpdatedAt))
.map(o -> {
if (o.getCaller().getId() == member.getId()) {
if (o.getDeliveryPost().isWrittenPost(member))
return ChatRoomInfoResponse.of(o, o.getHelper(), true);
return ChatRoomInfoResponse.of(o, o.getHelper(), false);
return ChatRoomListDto.of(o, o.getHelper(), true);
return ChatRoomListDto.of(o, o.getHelper(), false);
} else {
if (o.getDeliveryPost().isWrittenPost(member))
return ChatRoomInfoResponse.of(o, o.getCaller(), true);
return ChatRoomInfoResponse.of(o, o.getCaller(), false);
return ChatRoomListDto.of(o, o.getCaller(), true);
return ChatRoomListDto.of(o, o.getCaller(), false);
}
})
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DeliveryResponseDto {
private boolean isWritten;

public static DeliveryResponseDto of(DeliveryPost deliveryPost, boolean isWritten) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 M월 d일 HH:mm");
String createdAtString = deliveryPost.getJoinedAt().format(formatter);

return DeliveryResponseDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ public Slice<DeliveryResponseDto> getAllDeliveryPosts(Member member,
}



// 게시글 상태 조회
public PostStatus findPostStatus(Member member, String postId) {
DeliveryPost deliveryPost = deliveryPostRepository.findByIdAndMember(Long.valueOf(postId), member)
.orElseThrow(() -> new RuntimeException("해당하는 게시글을 찾을 수 없습니다."));
return deliveryPost.getStatus();
}

}

0 comments on commit 4151bcc

Please sign in to comment.