Skip to content

Commit

Permalink
Merge pull request #255 from Geek-sasaeng/tomas
Browse files Browse the repository at this point in the history
#254 refactor: DeliveryParty 상세조회res 에 partyChatRoomId 필드 값 추가
  • Loading branch information
xhaktmchl authored Dec 8, 2022
2 parents 85b8338 + 33ffa43 commit fd91f66
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public enum BaseResponseStatus {
NOT_EXIST_USER(false,2204,"존재하지 않는 회원 id 입니다."),
BLANK_KEYWORD(false,2205,"검색어를 입력해주세요"),
NOT_EXIST_ANNOUNCEMENT(false, 2206, "존재하지 않는 공지사항입니다."),
NOT_EXISTS_CHATTING_ROOM(false,2207,"채팅방이 존재하지 않습니다."),
NOT_EXISTS_CHAT_ROOM(false,2207,"채팅방이 존재하지 않습니다."),
NOT_EXISTS_PARTYCHATROOM_MEMBER(false,2208,"채팅방 멤버가 존재하지 않습니다."),
ALREADY_PARTICIPATE_CHATROOM(false, 2209, "이미 채팅방에 참여하고 있습니다."),
NOT_EXISTS_CHAT(false,2210,"채팅이 존재하지 않습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DeliveryPartyChatController {
@PostMapping
public BaseResponse<PartyChatRoomRes> createPartyChatRoom(HttpServletRequest request, @RequestBody @Validated PostPartyChatRoomReq dto){
JwtInfo jwtInfo = (JwtInfo) request.getAttribute("jwtInfo");
PartyChatRoomRes res = deliveryPartyChatService.createChatRoom(jwtInfo.getUserId(), dto.getTitle(), dto.getAccountNumber(), dto.getBank(), dto.getCategory(), dto.getMaxMatching());
PartyChatRoomRes res = deliveryPartyChatService.createChatRoom(jwtInfo.getUserId(), dto.getTitle(), dto.getAccountNumber(), dto.getBank(), dto.getCategory(), dto.getMaxMatching(), dto.getDeliveryPartyId());
return new BaseResponse<>(res);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/shop/geeksasang/domain/chat/PartyChatRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public class PartyChatRoom extends ChatRoom{
private String category;
private Boolean isFinish;
private Integer maxMatching;
private int deliveryPartyId;

public PartyChatRoom(String title, List<Chat> chats, List<PartyChatRoomMember> participants, String accountNumber,
String bank, String category, Boolean isFinish, Integer maxMatching, PartyChatRoomMember chief) {
String bank, String category, Boolean isFinish, Integer maxMatching, PartyChatRoomMember chief, int deliveryPartyId) {
super();
this.title = title;
this.chats = chats;
Expand All @@ -43,6 +44,7 @@ public PartyChatRoom(String title, List<Chat> chats, List<PartyChatRoomMember> p
this.isFinish = isFinish;
this.maxMatching = maxMatching;
this.chief = chief;
this.deliveryPartyId = deliveryPartyId;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ public class PostPartyChatRoomReq {
@ApiModelProperty(example = "4")
@ApiParam(value = "매칭 최대 인원", required = true)
private Integer maxMatching;

@ApiModelProperty(example = "1", value = "배달파티 ID", required = true)
private int deliveryPartyId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.Setter;
import shop.geeksasang.config.status.BelongStatus;
import shop.geeksasang.config.status.MatchingStatus;
import shop.geeksasang.domain.chat.PartyChatRoom;
import shop.geeksasang.domain.deliveryparty.DeliveryParty;


Expand Down Expand Up @@ -81,9 +82,11 @@ public class GetDeliveryPartyDetailRes {
@ApiModelProperty(example = "Y", value = "사용자가 파티멤버에 속해있는지 여부. 속해있으면 Y, 아니면 N")
private BelongStatus belongStatus;

@ApiModelProperty(value = "배달 파티 채팅방 ID", example = "637fa741bba4cf6c34bc13ef")
private String partyChatRoomId;

//빌더
static public GetDeliveryPartyDetailRes toDto(DeliveryParty deliveryParty, boolean authorStatus, BelongStatus belongStatus){
static public GetDeliveryPartyDetailRes toDto(DeliveryParty deliveryParty, boolean authorStatus, BelongStatus belongStatus, PartyChatRoom partyChatRoom){

return GetDeliveryPartyDetailRes.builder()
.id(deliveryParty.getId())
Expand All @@ -106,13 +109,14 @@ static public GetDeliveryPartyDetailRes toDto(DeliveryParty deliveryParty, boole
.dormitory(deliveryParty.getDormitory().getId())
.uuid(deliveryParty.getUuid())
.belongStatus(belongStatus)
.partyChatRoomId(partyChatRoom.getId())
.build();
}

@Builder
public GetDeliveryPartyDetailRes(int id, String chief, int chiefId, String chiefProfileImgUrl, String foodCategory, boolean hashTag, String title, String content,
LocalDateTime orderTime, int currentMatching, int maxMatching, MatchingStatus matchingStatus, String updatedAt, Double latitude,
Double longitude, String storeUrl, boolean authorStatus, int dormitory, String uuid, BelongStatus belongStatus) {
Double longitude, String storeUrl, boolean authorStatus, int dormitory, String uuid, BelongStatus belongStatus, String partyChatRoomId) {
this.id = id;
this.chief = chief;
this.chiefId = chiefId;
Expand All @@ -133,5 +137,6 @@ public GetDeliveryPartyDetailRes(int id, String chief, int chiefId, String chief
this.dormitory = dormitory;
this.uuid = uuid;
this.belongStatus = belongStatus;
this.partyChatRoomId = partyChatRoomId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import shop.geeksasang.domain.chat.ChatRoom;
import shop.geeksasang.domain.chat.PartyChatRoom;
Expand All @@ -17,4 +18,7 @@ public interface PartyChatRoomRepository extends MongoRepository<PartyChatRoom,

@Query("{ chief: ?0, 'status' : 'ACTIVE'}")
Optional<PartyChatRoom> findPartyChatRoomByChiefId(ObjectId chiefId);

@Query("{'deliveryPartyId' : :#{#deliveryPartyId}, 'status' : 'ACTIVE'}")
Optional<PartyChatRoom> findByDeliveryPartyId(@Param("deliveryPartyId") int deliveryPartyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public class DeliveryPartyChatService {
private static final String PAGING_STANDARD = "createdAt";

@Transactional(readOnly = false)
public PartyChatRoomRes createChatRoom(int memberId, String title, String accountNumber, String bank, String category, Integer maxMatching){
public PartyChatRoomRes createChatRoom(int memberId, String title, String accountNumber, String bank, String category, Integer maxMatching, int deliveryPartyId){

Member member = memberRepository.findMemberById(memberId)
.orElseThrow(() -> new BaseException(NOT_EXIST_USER));
String email = member.getEmail().getAddress();
List<Chat> chats = new ArrayList<>();
List<PartyChatRoomMember> participants = new ArrayList<>();
PartyChatRoomMember chief = new PartyChatRoomMember(LocalDateTime.now(), false, memberId);
PartyChatRoom chatRoom = new PartyChatRoom(title, chats, participants, accountNumber, bank, category, false, maxMatching, chief);
PartyChatRoom chatRoom = new PartyChatRoom(title, chats, participants, accountNumber, bank, category, false, maxMatching, chief, deliveryPartyId);
chatRoom.addParticipants(chief);

partyChatRoomRepository.save(chatRoom); //초기 생성
Expand All @@ -90,7 +90,7 @@ public PartyChatRoomRes createChatRoom(int memberId, String title, String accoun
public void createChat(int memberId, String email, String chatRoomId, String content, Boolean isSystemMessage, String profileImgUrl, String chatType, String chatId, Boolean isImageMessage) {

PartyChatRoom partyChatRoom = partyChatRoomRepository.findByPartyChatRoomId(new ObjectId(chatRoomId))
.orElseThrow(() -> new BaseException(NOT_EXISTS_CHATTING_ROOM));
.orElseThrow(() -> new BaseException(NOT_EXISTS_CHAT_ROOM));

PartyChatRoomMember partyChatRoomMember = partyChatRoomMemberRepository
.findByMemberIdAndChatRoomId(memberId, new ObjectId(partyChatRoom.getId()))
Expand Down Expand Up @@ -125,7 +125,7 @@ public void createChat(int memberId, String email, String chatRoomId, String con
public void createChatImage(int memberId, String email, String chatRoomId, String content, Boolean isSystemMessage, String profileImgUrl, String chatType, String chatId, List<MultipartFile> images, Boolean isImageMessage) {

PartyChatRoom partyChatRoom = partyChatRoomRepository.findByPartyChatRoomId(new ObjectId(chatRoomId))
.orElseThrow(() -> new BaseException(NOT_EXISTS_CHATTING_ROOM));
.orElseThrow(() -> new BaseException(NOT_EXISTS_CHAT_ROOM));

PartyChatRoomMember partyChatRoomMember = partyChatRoomMemberRepository
.findByMemberIdAndChatRoomId(memberId, new ObjectId(chatRoomId))
Expand Down Expand Up @@ -181,7 +181,7 @@ public PartyChatRoomMemberRes joinPartyChatRoom(int memberId, String chatRoomId,
String profileImgUrl = member.getProfileImgUrl();

PartyChatRoom partyChatRoom = partyChatRoomRepository.findByPartyChatRoomId(new ObjectId(chatRoomId))
.orElseThrow(() -> new BaseException(NOT_EXISTS_CHATTING_ROOM));
.orElseThrow(() -> new BaseException(NOT_EXISTS_CHAT_ROOM));

//Validation 기존의 멤버인지 예외 처리
if(partyChatRoom.getParticipants().stream().anyMatch(participant -> participant.getMemberId() == memberId)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import shop.geeksasang.config.type.OrderTimeCategoryType;
import shop.geeksasang.config.exception.BaseException;
import shop.geeksasang.config.exception.response.BaseResponseStatus;
import shop.geeksasang.domain.chat.PartyChatRoom;
import shop.geeksasang.domain.deliveryparty.DeliveryParty;
import shop.geeksasang.domain.deliveryparty.DeliveryPartyMember;
import shop.geeksasang.domain.deliveryparty.FoodCategory;
Expand All @@ -30,6 +31,7 @@
import shop.geeksasang.dto.login.JwtInfo;
import shop.geeksasang.repository.*;
import shop.geeksasang.repository.block.BlockRepository;
import shop.geeksasang.repository.chat.PartyChatRoomRepository;
import shop.geeksasang.repository.deliveryparty.DeliveryPartyMemberRepository;
import shop.geeksasang.repository.deliveryparty.query.DeliveryPartyQueryRepository;
import shop.geeksasang.repository.deliveryparty.DeliveryPartyRepository;
Expand Down Expand Up @@ -60,6 +62,7 @@ public class DeliveryPartyService {
private final HashTagRepository hashTagRepository;
private final DeliveryPartyQueryRepository deliveryPartyQueryRepository;
private final BlockRepository blockRepository;
private final PartyChatRoomRepository partyChatRoomRepository;

private static final int PAGING_SIZE = 10;
private static final String PAGING_STANDARD = "orderTime";
Expand Down Expand Up @@ -191,7 +194,10 @@ public GetDeliveryPartyDetailRes getDeliveryPartyDetailById(int partyId, int mem
belongStatus = BelongStatus.Y;
}

GetDeliveryPartyDetailRes getDeliveryPartyDetailRes = GetDeliveryPartyDetailRes.toDto(deliveryParty, authorStatus, belongStatus);
PartyChatRoom partyChatRoom = partyChatRoomRepository.findByDeliveryPartyId(partyId)
.orElseThrow(() -> new BaseException(NOT_EXISTS_CHAT_ROOM));

GetDeliveryPartyDetailRes getDeliveryPartyDetailRes = GetDeliveryPartyDetailRes.toDto(deliveryParty, authorStatus, belongStatus, partyChatRoom);
return getDeliveryPartyDetailRes;
}

Expand Down

0 comments on commit fd91f66

Please sign in to comment.