Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
package ita.tinybite.domain.chat.dto;

import ita.tinybite.domain.chat.entity.ChatRoom;
import ita.tinybite.domain.party.enums.PartyStatus;
import lombok.Builder;

@Builder
public record GroupChatRoomDetailResDto() {
public record GroupChatRoomDetailResDto(
Long groupChatRoomId,
Long partyId,
String partyTitle,
PartyStatus status,
int currentParticipantCnt,
int maxParticipantCnt,
String formattedPartyCnt
) {
public static GroupChatRoomDetailResDto of(ChatRoom groupChatRoom) {
return GroupChatRoomDetailResDto.builder()
.groupChatRoomId(groupChatRoom.getId())
.partyId(groupChatRoom.getParty().getId())
.partyTitle(groupChatRoom.getParty().getTitle())
.status(groupChatRoom.getParty().getStatus())
.currentParticipantCnt(groupChatRoom.getParty().getCurrentParticipants())
.maxParticipantCnt(groupChatRoom.getParty().getMaxParticipants())
.formattedPartyCnt(formatParticipantStatus(groupChatRoom.getParty().getCurrentParticipants(), groupChatRoom.getParty().getMaxParticipants()))
.build();
}

private static String formatParticipantStatus(int current, int max) {
return String.format("%d/%d명", current, max);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public static OneToOneChatRoomDetailResDto of(Party party, PartyParticipant part

switch(participantStatus) {
case PENDING -> {
if(type.equals(ParticipantType.PARTICIPANT)) {
if(type.equals(ParticipantType.HOST)) { // type = HOST
resDtoBuilder
.participantStatus(ParticipantStatus.REQUESTED)
.targetProfileImage(targetUser.getProfileImage())
.targetLocation(targetUser.getLocation());
} else { // type = HOST
} else { // type = PARTICIPANT
resDtoBuilder
.participantStatus(ParticipantStatus.PENDING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import ita.tinybite.domain.party.enums.ParticipantStatus;
import ita.tinybite.domain.party.repository.PartyParticipantRepository;
import ita.tinybite.domain.user.entity.User;
import ita.tinybite.global.exception.BusinessException;
import ita.tinybite.global.exception.errorcode.ChatRoomErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Limit;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -101,21 +103,21 @@ public List<GroupChatRoomResDto> getGroupRooms() {
public OneToOneChatRoomDetailResDto getOneToOneRoom(Long chatRoomId) {
User currentUser = securityProvider.getCurrentUser();
ChatRoom chatRoom = chatRoomRepository.findById(chatRoomId).orElseThrow();
PartyParticipant partyParticipant = partyParticipantRepository.findByOneToOneChatRoom(chatRoom).orElseThrow();

ChatRoom groupChatRoom = chatRoomRepository.findByPartyAndType(chatRoom.getParty(), ChatRoomType.GROUP).orElseGet(null);

User host = chatRoom.getParty().getHost();
host.getNickname();
if(!chatRoom.getType().equals(ChatRoomType.ONE_TO_ONE)) throw BusinessException.of(ChatRoomErrorCode.NOT_ONE_TO_ONE);

User targetUser = partyParticipant.getUser();
targetUser.getNickname();
PartyParticipant partyParticipant = partyParticipantRepository.findByOneToOneChatRoomAndStatus(chatRoom, ParticipantStatus.PENDING);

ChatRoom groupChatRoom = chatRoomRepository.findByPartyAndType(chatRoom.getParty(), ChatRoomType.GROUP).orElseGet(null);
return OneToOneChatRoomDetailResDto.of(chatRoom.getParty(), partyParticipant, currentUser, groupChatRoom);
}

public GroupChatRoomDetailResDto getGroupRoom(Long chatRoomId) {
return null;
ChatRoom chatRoom = chatRoomRepository.findById(chatRoomId).orElseThrow();

if(!chatRoom.getType().equals(ChatRoomType.GROUP)) throw BusinessException.of(ChatRoomErrorCode.NOT_GROUP);

return GroupChatRoomDetailResDto.of(chatRoom);
}

private static String getTimeAgo(LocalDateTime then) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ boolean existsByParty_IdAndUser_UserIdAndStatus(
ParticipantStatus status
);

@Query("SELECT pp FROM PartyParticipant pp WHERE pp.party.id = :partyId AND pp.user.id = :userId")
@Query("SELECT pp FROM PartyParticipant pp WHERE pp.party.id = :partyId AND pp.user.userId = :userId")
Optional<PartyParticipant> findByPartyIdAndUserId(@Param("partyId") Long partyId, @Param("userId") Long userId);

Optional<PartyParticipant> findByOneToOneChatRoom(ChatRoom oneToOneChatRoom);

PartyParticipant findByOneToOneChatRoomAndStatus(ChatRoom oneToOneChatRoom, ParticipantStatus status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ita.tinybite.global.exception.errorcode;

import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum ChatRoomErrorCode implements ErrorCode {

NOT_ONE_TO_ONE(HttpStatus.BAD_REQUEST, "NOT_ONE_TO_ONE", "일대일 채팅이 아닙니다."),
NOT_GROUP(HttpStatus.BAD_REQUEST, "NOT_GROUP", "그룹 채팅이 아닙니다."),

;

private final HttpStatus httpStatus;
private final String code;
private final String message;

ChatRoomErrorCode(HttpStatus httpStatus, String code, String message) {
this.httpStatus = httpStatus;
this.code = code;
this.message = message;
}
}