Skip to content

Commit

Permalink
Merge pull request #113 from tukcomCD2024/feat/#105-debate-complete
Browse files Browse the repository at this point in the history
Feat/#105 debate complete
  • Loading branch information
yeonjy authored May 14, 2024
2 parents 87893c6 + bb5b422 commit 7ac88e2
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -22,7 +23,7 @@ public interface DebateApi {
summary = "토론방 생성",
description = "주제가 선택된 토론방을 생성합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"debate_room"}
tags = {"토론방"}
)
@ApiResponse(
responseCode = "201",
Expand All @@ -34,23 +35,23 @@ public interface DebateApi {
summary = "토론방 전체 조회",
description = "회원의 토론방을 페이지로 나누어 조회합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"debate_room"}
tags = {"토론방"}
)
@ApiResponse(
responseCode = "200",
description = "OK"
description = "요청에 성공하였습니다."
)
List<DebateRoomResponse> getDebateRooms(Pageable pageable);

@Operation(
summary = "토론방 삭제",
description = "토론방을 삭제합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"debate_room"}
tags = {"토론방"}
)
@ApiResponse(
responseCode = "204",
description = "No Content"
description = "토론방 삭제에 성공하였으며, 응답값은 없습니다."
)
void deleteDebateRoom(@Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true)
Long roomId
Expand All @@ -60,7 +61,7 @@ void deleteDebateRoom(@Parameter(in = ParameterIn.PATH, description = "토론방
summary = "[인간] 토론 메세지 저장",
description = "사용자가 보낸 토론 메세지를 저장합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"debate_message"}
tags = {"토론 메세지"}
)
@ApiResponse(
responseCode = "201",
Expand All @@ -77,7 +78,7 @@ void saveHumanDebateMessage(
summary = "[AI] 토론 메세지 저장",
description = "ChatGPT OPENAI가 보낸 토론 메세지를 저장합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"debate_message"}
tags = {"토론 메세지"}
)
@ApiResponse(
responseCode = "201",
Expand All @@ -90,15 +91,36 @@ void saveAIDebateMessage(
@RequestBody DebateMessageRequest request
);

@Operation(
summary = "토론 종료",
description = "토론을 종료합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"토론방"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "204",
description = "요청에 성공하였으며 응답값은 없습니다."
),
@ApiResponse(
responseCode = "404",
description = "토론방을 찾지 못했습니다."
)
})
void finishDebate(
@Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true)
Long roomId
);

@Operation(
summary = "토론 메세지 조회",
description = "토론방의 토론 메세지 이력을 조회합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"debate_message"}
tags = {"토론 메세지"}
)
@ApiResponse(
responseCode = "200",
description = "OK"
description = "요청에 성공하였습니다."
)
List<DebateMessageResponse> getDebateMessages(
@Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true)
Expand All @@ -109,19 +131,42 @@ List<DebateMessageResponse> getDebateMessages(
summary = "토론 요약",
description = "토론방의 토론 메세지들을 요약합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"debate_message"}
tags = {"토론방"}
)
@ApiResponse(
responseCode = "200",
description = "OK"
@ApiResponses(value = {
@ApiResponse(
responseCode = "201",
description = "토론 요약이 성공하였습니다."
),
@ApiResponse(
responseCode = "404",
description = "토론방을 찾지 못했습니다."
)
})
DebateSummaryResponse summarizeDebate(
@Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true)
Long roomId
);

@Operation(
summary = "토론 요약 조회",
description = "토론 요약 내용을 조회합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"토론방"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "요청에 성공하였습니다."
),
@ApiResponse(
responseCode = "404",
description = "토론방을 찾지 못했습니다."
)
})
DebateSummaryResponse getSummarizedDebate(
@Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true)
Long roomId
);





}
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,30 @@ public void saveAIDebateMessage(@PathVariable final Long roomId, @RequestBody fi
debateMessageService.saveAIDebateMessage(roomId, request);
}

@ResponseStatus(HttpStatus.OK)
@ResponseStatus(HttpStatus.NO_CONTENT)
@PatchMapping("/{roomId}")
public void finishDebate(@PathVariable final Long roomId) {
debateRoomService.closeDebate(roomId);
}

@ResponseStatus(HttpStatus.CREATED)
@GetMapping("/{roomId}")
@Override
public List<DebateMessageResponse> getDebateMessages(@PathVariable final Long roomId) {
return debateMessageService.getDebateMessages(roomId);
}

@ResponseStatus(HttpStatus.OK)
@PostMapping("/summary/{roomId}")
@Override
public DebateSummaryResponse summarizeDebate(@PathVariable final Long roomId) {
return debateRoomService.summaryDebate(roomId);
}

@ResponseStatus(HttpStatus.OK)
@GetMapping("/summary/{roomId}")
@Override
public DebateSummaryResponse getSummarizedDebate(@PathVariable final Long roomId) {
return debateRoomService.summaryDebate(roomId);
return debateRoomService.getSummarizedDebate(roomId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
public class DebateRoomResponse {
private Long id;
private String topic;
private Boolean isClosed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest;
import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse;
import com.rollthedice.backend.domain.debate.entity.DebateRoom;
import com.rollthedice.backend.domain.debate.exception.DebateRoomNotFoundException;
import com.rollthedice.backend.domain.debate.mapper.DebateRoomMapper;
import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository;
Expand Down Expand Up @@ -48,15 +49,28 @@ public void deleteDebateRoom(Long roomId) {

@Transactional
public DebateSummaryResponse summaryDebate(final Long roomId) {
DebateRoom room = debateRoomRepository.findById(roomId).orElseThrow(DebateRoomNotFoundException::new);
StringBuilder sb = debateMessageService.getAllMessages(roomId);
String summary = clovaSummary.summaryDebate(sb.toString());
debateRoomRepository.findById(roomId).orElseThrow(DebateRoomNotFoundException::new)
.updateSummary(summary);
room.updateSummary(summary);

return DebateSummaryResponse.builder()
.roomId(roomId)
.summary(summary)
.summary(room.getSummary())
.build();
}

public DebateSummaryResponse getSummarizedDebate(final Long roomId) {
DebateRoom room = debateRoomRepository.findById(roomId).orElseThrow(DebateRoomNotFoundException::new);
return DebateSummaryResponse.builder()
.roomId(roomId)
.summary(room.getSummary())
.build();
}

@Transactional
public void closeDebate(final Long roomId) {
DebateRoom room = debateRoomRepository.findById(roomId).orElseThrow(DebateRoomNotFoundException::new);
room.closeDebate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
@RequiredArgsConstructor
@Service
public class MemberService {
private final AuthService authService;
private final RefreshTokenService refreshTokenService;
private final JwtService jwtService;
private final HttpServletRequest request;
private final HttpServletResponse response;
private final AuthService authService;;
private final MemberRepository memberRepository;


Expand Down

0 comments on commit 7ac88e2

Please sign in to comment.