Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 대여날짜 수정 api 구현 #96

Merged
merged 1 commit into from
Dec 24, 2024
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
Expand Up @@ -56,4 +56,11 @@ public BaseResponse<List<ViewChatInfoResponse>> getChatList(@RequestParam(requir
String userId = MDC.get(JWTUtil.MDC_USER_ID).toString();
return new BaseResponse<>(chatService.getChatList(beforeTimestamp, userId));
}

@Operation(summary = "대여 날짜 변경", description = "대여 날짜 변경 API")
@PatchMapping("/{channelId}/date")
public BaseResponse<String> changeDate(@PathVariable(value = "channelId") String channelId, @RequestBody ChatRequest.changeDate request) {
String userId = MDC.get(JWTUtil.MDC_USER_ID).toString();
return new BaseResponse<>(chatService.changeDate(userId, channelId, request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public static class borrowInfo {
private LocalDate endedAt;
private String postId;
}

@Getter
@Setter
@Builder
public static class changeDate {
private LocalDate startedAt;
private LocalDate endedAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import site.billbill.apiserver.api.chat.dto.request.ChatRequest;
import site.billbill.apiserver.api.chat.dto.request.ChatRequest.changeDate;
import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChannelInfoResponse;
import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChatInfoResponse;

Expand All @@ -13,4 +14,6 @@ public interface ChatService {
String startChannel(ChatRequest.borrowInfo request, String userId);

List<ViewChatInfoResponse> getChatList(String beforeTimestamp, String userId);

String changeDate(String userId, String channelId, changeDate request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import org.springframework.transaction.annotation.Transactional;
import site.billbill.apiserver.api.chat.converter.ChatConverter;
import site.billbill.apiserver.api.chat.dto.request.ChatRequest;
import site.billbill.apiserver.api.chat.dto.request.ChatRequest.borrowInfo;
import site.billbill.apiserver.api.chat.dto.request.ChatRequest.changeDate;
import site.billbill.apiserver.api.chat.dto.request.WebhookRequest.ChatInfo;
import site.billbill.apiserver.api.chat.dto.request.WebhookRequest.ChatInfoList;
import site.billbill.apiserver.api.chat.dto.response.ChatResponse;
import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChannelInfoResponse;
import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChatInfoResponse;
import site.billbill.apiserver.common.enums.exception.ErrorCode;
import site.billbill.apiserver.common.utils.ULID.ULIDUtil;
Expand All @@ -36,6 +39,7 @@ public class ChatServiceImpl implements ChatService {
private final ItemsBorrowRepository itemsBorrowRepository;
private final WebhookServiceImpl webhookService;

@Override
@Transactional
public String leaveChatChannel(String channelId, String userId) {
ChatChannelJpaEntity chatChannel = chatRepository.findById(channelId)
Expand All @@ -49,8 +53,9 @@ public String leaveChatChannel(String channelId, String userId) {
return "success";
}

@Override
@Transactional
public String startChannel(ChatRequest.borrowInfo request, String userId) {
public String startChannel(borrowInfo request, String userId) {
ItemsJpaEntity item = itemsRepository.findById(request.getPostId())
.orElseThrow(() -> new CustomException(ErrorCode.NotFound, "게시물을 찾을 수 없습니다.", HttpStatus.NOT_FOUND));
UserJpaEntity contact = userRepository.findById(userId)
Expand All @@ -68,7 +73,8 @@ public String startChannel(ChatRequest.borrowInfo request, String userId) {
return chatChannel.get(0).getChannelId();
}

public ChatResponse.ViewChannelInfoResponse getInfoChannel(String channelId, String userId) {
@Override
public ViewChannelInfoResponse getInfoChannel(String channelId, String userId) {
ChatChannelJpaEntity chatChannel = chatRepository.findById(channelId)
.orElseThrow(() -> new CustomException(ErrorCode.NotFound, "채널을 찾을 수 없습니다.", HttpStatus.NOT_FOUND));
userRepository.findById(userId)
Expand All @@ -92,6 +98,7 @@ public ChatResponse.ViewChannelInfoResponse getInfoChannel(String channelId, Str
return ChatConverter.toViewChannelInfo(chatChannel, opponent, item, totalPrice, status, userId);
}

@Override
public List<ViewChatInfoResponse> getChatList(String beforeTimestamp, String userId) {
userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorCode.NotFound, "회원을 찾을 수 없습니다.", HttpStatus.NOT_FOUND));
Expand All @@ -116,4 +123,25 @@ public List<ViewChatInfoResponse> getChatList(String beforeTimestamp, String use
return ChatConverter.toViewChatInfo(chatInfo, userId, opponent, chatChannel.getItem());
}).collect(Collectors.toList());
}

@Override
@Transactional
public String changeDate(String userId, String channelId, changeDate request) {
userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorCode.NotFound, "회원을 찾을 수 없습니다.", HttpStatus.NOT_FOUND));

ChatChannelJpaEntity chatChannel = chatRepository.findById(channelId)
.orElseThrow(() -> new CustomException(ErrorCode.NotFound, "채널을 찾을 수 없습니다.", HttpStatus.NOT_FOUND));

boolean isExist = false;
if (chatChannel.getOwner().getUserId().equals(userId) || chatChannel.getContact().getUserId().equals(userId)) {
isExist = true;
}
if (!isExist) {
throw new CustomException(ErrorCode.BadRequest, "채팅방 참여자가 아닙니다.", HttpStatus.BAD_REQUEST);
}

chatChannel.ChangeDate(request.getStartedAt(), request.getEndedAt());
return "success";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public UserJpaEntity getOpponent(String userId) {
}
return contact;
}

public void ChangeDate(LocalDate startedAt, LocalDate endedAt) {
this.startedAt = startedAt;
this.endedAt = endedAt;
}
}
Loading