Skip to content

Commit

Permalink
Merge pull request #27 from WonderWoman-Team/chatting/givesilverstick
Browse files Browse the repository at this point in the history
[FEAT] 게시글 상태 '취소' 추가
  • Loading branch information
xloyeon authored Aug 19, 2023
2 parents 4940e43 + 681af89 commit f8ff196
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.example.wonderwoman.chatting.service.ChatService;
import com.example.wonderwoman.chatting.service.ResponseService;
import com.example.wonderwoman.common.dto.NormalResponseDto;
import com.example.wonderwoman.delivery.entity.PostStatus;
import com.example.wonderwoman.delivery.service.DeliveryService;
import com.example.wonderwoman.login.CurrentUser;
import com.example.wonderwoman.member.entity.Member;
import com.example.wonderwoman.member.repository.MemberRepository;
Expand All @@ -28,6 +30,7 @@ public class ChatRoomController {

private static final Logger logger = LoggerFactory.getLogger(ChatRoomController.class);
private final ChatService chatService;
private final DeliveryService deliveryService;
private final ResponseService responseService;
private final MemberRepository memberRepository;
private final ChatRoomRepository chatRoomRepository;
Expand Down Expand Up @@ -64,8 +67,17 @@ 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());

// chatService.updatePostStatus(request.getChatRoomId(), request.getStatus());
PostStatus postStatus = deliveryService.findPostStatus(member, request.getPostId());
System.out.println(postStatus);
if (PostStatus.NONE.equals(postStatus)) {
System.out.println("채팅방 존재하지 않을 때");
chatService.updatePostStatusWithCancellationByPostId(request.getPostId(), request.getStatus());
} else {
System.out.println("채팅방 존재할 때");
chatService.updatePostStatus(request.getChatRoomId(), request.getStatus());
return ResponseEntity.ok(chatService.findRoomById(member, request.getChatRoomId()));
}
return ResponseEntity.ok(chatService.findRoomById(member, request.getChatRoomId()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
@Builder
public class ChatRoomStatusRequest {
private String chatRoomId;

private String postId;
private PostStatus status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ public void updatePostStatus(String chatRoomId, PostStatus postStatus) {
deliveryPostRepository.save(deliveryPost);
}

@Transactional
public void updatePostStatusWithCancellationByPostId(String postId, PostStatus postStatus) {
DeliveryPost deliveryPost = deliveryPostRepository.findById(postId)
.orElseThrow(() -> new WonderException(ErrorCode.ARTICLE_NOT_FOUND));

// 이미 '없음' 상태인 경우에는 게시글 상태를 postStatus로 변경
if (deliveryPost.getPostStatus() == PostStatus.NONE) {
deliveryPost.updatePostStatus(postStatus);
deliveryPostRepository.save(deliveryPost);
} else {
throw new WonderException(ErrorCode.INVALID_POST_STATUS_CHANGE);
}
}



//채팅방 삭제(퇴장)
@Transactional
public void deleteById(Member member, String chatRoomId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public DeliveryPost(School school, List<Building> building, PostStatus postStatu
this.postComment = postComment;
this.member = member;


}
public PostStatus getStatus() {
return postStatus;
}

public boolean isWrittenPost(Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@RequiredArgsConstructor
public enum PostStatus {
NONE("없음"),
CANCEL("취소"),
CHATTING("채팅중"),
IN_PROGRESS("진행중"),
DONE("완료");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
import com.example.wonderwoman.delivery.entity.ReqType;
import com.example.wonderwoman.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;


@Repository
public interface DeliveryPostRepository extends JpaRepository<DeliveryPost, Long> {

// 게시글 유형에 따른 게시물 조회
List<DeliveryPost> findByPostReqType(ReqType postReqType);

Optional<DeliveryPost> findByIdAndMember(Long id, Member member);
@Query("select c from DeliveryPost c where c.id=:id")
Optional<DeliveryPost> findById(@Param("id") String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.wonderwoman.delivery.entity.Building;
import com.example.wonderwoman.delivery.entity.DeliveryPost;
import com.example.wonderwoman.delivery.entity.PostStatus;
import com.example.wonderwoman.delivery.entity.SanitarySize;
import com.example.wonderwoman.delivery.repository.DeliveryPostRepository;
import com.example.wonderwoman.delivery.repository.DeliveryRepositoryImpl;
Expand Down Expand Up @@ -62,6 +63,11 @@ public Slice<DeliveryResponseDto> getAllDeliveryPosts(Member member,
return deliveryRepositoryImpl.getSliceOfDelivery(member, reqType, school, buildings, sanitarySizes, lastId, pageable);
}


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

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public enum ErrorCode {
ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "글을 찾지 못했습니다.", "존재하는 글인지 확인해주세요."),
FORBIDDEN_CHATROOM(HttpStatus.FORBIDDEN, "채팅방에 접근 권한이 없습니다.", "채팅방에 참여하는 회원인지 확인해주세요."),
ARTICLE_CAN_NOT_DELETE(HttpStatus.FORBIDDEN, "이미 진행중인 글입니다.", "어떠한 상태도 없는 글인지 확인해주세요."),
BUILDING_NOT_MATCH(HttpStatus.BAD_REQUEST, "건물이 학교와 매칭되지 않습니다.", "건물을 올바르게 선택해주세요.");
BUILDING_NOT_MATCH(HttpStatus.BAD_REQUEST, "건물이 학교와 매칭되지 않습니다.", "건물을 올바르게 선택해주세요."),
INVALID_POST_STATUS_CHANGE(HttpStatus.BAD_REQUEST, "현재 딜리버리 상태에서는 상태 변경이 불가능합니다.", "딜리버리 상태가 '없음'인 경우에만 취소 가능합니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down

0 comments on commit f8ff196

Please sign in to comment.