Skip to content

Commit

Permalink
커피챗 메세지 기능 개발 (#65)
Browse files Browse the repository at this point in the history
* feat(coffeechat) : 커피챗 시간 안맞는 선택 추가

* feat(coffeechat) : 커피챗 요청에 응답할 때 메세지 추가
  • Loading branch information
Woongbin06 authored Feb 5, 2024
1 parent 2148c9b commit 15aa43a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void updateToUser(User toUser) {
this.toUser = toUser;
}

public void updateState(State state) {
public void updateState(State state, String message) {
this.state = state;
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum State {
PENDING,
ACCEPT,
REJECT
REJECT,
TIME
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,31 @@ public void create(
@PutMapping("/{chat-id}/accept")
@ResponseStatus(HttpStatus.NO_CONTENT)
@LoginRequired
public void accept(@PathVariable(name = "chat-id") Long coffeeChatId) {
commandCoffeeChatService.accept(authRepository.getCurrentUser(), coffeeChatId);
public void accept(
@PathVariable(name = "chat-id") Long coffeeChatId,
@RequestBody CoffeeChatRequest request
) {
commandCoffeeChatService.accept(authRepository.getCurrentUser(), coffeeChatId, request.message());
}

@PutMapping("/{chat-id}/reject")
@ResponseStatus(HttpStatus.NO_CONTENT)
@LoginRequired
public void reject(@PathVariable(name = "chat-id") Long coffeeChatId) {
commandCoffeeChatService.reject(authRepository.getCurrentUser(), coffeeChatId);
public void reject(
@PathVariable(name = "chat-id") Long coffeeChatId,
@RequestBody CoffeeChatRequest request
) {
commandCoffeeChatService.reject(authRepository.getCurrentUser(), coffeeChatId, request.message());
}

@PutMapping("/{chat-id}/time")
@ResponseStatus(HttpStatus.NO_CONTENT)
@LoginRequired
public void timeNotRight(
@PathVariable(name = "chat-id") Long coffeeChatId,
@RequestBody CoffeeChatRequest request
) {
commandCoffeeChatService.timeNotRight(authRepository.getCurrentUser(), coffeeChatId, request.message());
}

@GetMapping("/my/pending/receive")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.sickgyun.server.coffeechat.service;

import static com.sickgyun.server.coffeechat.domain.value.State.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sickgyun.server.coffeechat.domain.CoffeeChat;
import com.sickgyun.server.coffeechat.domain.value.State;
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatCreator;
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatReader;
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatUpdater;
Expand All @@ -31,17 +32,24 @@ public void create(CoffeeChat coffeeChat, Long toUserId) {
coffeeChatCreator.create(coffeeChat);
}

public void accept(User user, Long coffeeChatId) {
public void accept(User user, Long coffeeChatId, String message) {
CoffeeChat coffeeChat = coffeeChatReader.read(coffeeChatId);
coffeeChatValidator.shouldBeSameUser(user, coffeeChat.getToUser());
coffeeChatValidator.shouldBePending(coffeeChat);
coffeeChatUpdater.updateState(coffeeChat, ACCEPT, message);
}

public void reject(User user, Long coffeeChatId, String message) {
CoffeeChat coffeeChat = coffeeChatReader.read(coffeeChatId);
coffeeChatValidator.shouldBeSameUser(user, coffeeChat.getToUser());
coffeeChatValidator.shouldBePending(coffeeChat);
coffeeChatUpdater.updateState(coffeeChat, State.ACCEPT);
coffeeChatUpdater.updateState(coffeeChat, REJECT, message);
}

public void reject(User user, Long coffeeChatId) {
public void timeNotRight(User user, Long coffeeChatId, String message) {
CoffeeChat coffeeChat = coffeeChatReader.read(coffeeChatId);
coffeeChatValidator.shouldBeSameUser(user, coffeeChat.getToUser());
coffeeChatValidator.shouldBePending(coffeeChat);
coffeeChatUpdater.updateState(coffeeChat, State.REJECT);
coffeeChatUpdater.updateState(coffeeChat, TIME, message);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.sickgyun.server.coffeechat.service;

import static com.sickgyun.server.coffeechat.domain.value.State.*;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sickgyun.server.coffeechat.domain.CoffeeChat;
import com.sickgyun.server.coffeechat.domain.value.State;
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatReader;
import com.sickgyun.server.user.domain.User;

Expand All @@ -20,18 +21,18 @@ public class QueryCoffeeChatService {
private final CoffeeChatReader coffeeChatReader;

public List<CoffeeChat> getPendingByToUser(User user) {
return coffeeChatReader.readByToUser(user, List.of(State.PENDING));
return coffeeChatReader.readByToUser(user, List.of(PENDING));
}

public List<CoffeeChat> getNotPendingByToUser(User user) {
return coffeeChatReader.readByToUser(user, List.of(State.ACCEPT, State.REJECT));
return coffeeChatReader.readByToUser(user, List.of(ACCEPT, REJECT, TIME));
}

public List<CoffeeChat> getPendingByFromUser(User user) {
return coffeeChatReader.readByFromUser(user, List.of(State.PENDING));
return coffeeChatReader.readByFromUser(user, List.of(PENDING));
}

public List<CoffeeChat> getNotPendingByFromUser(User user) {
return coffeeChatReader.readByFromUser(user, List.of(State.ACCEPT, State.REJECT));
return coffeeChatReader.readByFromUser(user, List.of(ACCEPT, REJECT, TIME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@RequiredArgsConstructor
public class CoffeeChatUpdater {

public void updateState(CoffeeChat coffeeChat, State state) {
coffeeChat.updateState(state);
public void updateState(CoffeeChat coffeeChat, State state, String message) {
coffeeChat.updateState(state, message);
}
}

0 comments on commit 15aa43a

Please sign in to comment.