Skip to content

Commit

Permalink
Merge pull request #97 from hufscheer/chore/#94-rest-docs
Browse files Browse the repository at this point in the history
[CHORE] Rest Docs 의존성 추가 및 세팅 #94
  • Loading branch information
Jin409 authored Jan 23, 2024
2 parents 5affc03 + 09d90d4 commit 1448317
Show file tree
Hide file tree
Showing 20 changed files with 2,540 additions and 56 deletions.
37 changes: 34 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.1.4'
id 'io.spring.dependency-management' version '1.1.3'
id "org.asciidoctor.jvm.convert" version '3.3.2'
}

configurations {
asciidoctorExt
}

group = 'com.sports'
Expand Down Expand Up @@ -56,12 +61,38 @@ dependencies {
testImplementation "org.testcontainers:testcontainers:1.19.3"
testImplementation "org.testcontainers:junit-jupiter:1.19.3"
testImplementation "org.testcontainers:mysql:1.19.3"

// rest docs
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
}

tasks.named('test') {
ext {
snippetsDir = file('build/generated-snippets')
}

test {
outputs.dir snippetsDir
useJUnitPlatform()
}

jar {
enabled = false
asciidoctor {
configurations 'asciidoctorExt'
inputs.dir snippetsDir
dependsOn test
}

tasks.register('copyDocument', Copy) { // 8
dependsOn asciidoctor

from file("build/docs/asciidoc")
into file("src/main/resources/static/docs")
}

asciidoctor.doFirst {
delete file('src/main/resources/static/docs')
}

bootJar {
dependsOn copyDocument
}
65 changes: 65 additions & 0 deletions src/docs/asciidoc/api.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
= 훕치치 관객 서버 API 문서
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 2
:sectlinks:

== 응원톡 API

=== 응원톡 저장

operation::cheer-talk-controller-test/응원톡을_저장한다[snippets='http-request,request-fields,http-response']

=== 응원톡 조회

operation::cheer-talk-query-controller-test/응원톡을_조회한다[snippets='http-request,query-parameters,path-parameters,http-response,response-fields']

== 게임 API

=== 게임 상세 조회

operation::game-query-controller-test/게임을_상세_조회한다[snippets='http-request,path-parameters,http-response,response-fields']

=== 게임 영상 조회

operation::game-query-controller-test/게임_영상_id를_조회한다[snippets='http-request,path-parameters,http-response,response-fields']

=== 게임 목록 조회

operation::game-query-controller-test/게임_목록을_조회한다[snippets='http-request,query-parameters,http-response,response-fields']

=== 게임 응원 횟수 조회

operation::game-query-controller-test/응원_횟수를_조회한다[snippets='http-request,path-parameters,http-response,response-fields']

=== 게임 라인업 조회

operation::game-query-controller-test/라인업을_조회한다[snippets='http-request,path-parameters,http-response,response-fields']

== 응원 횟수 API

=== 응원 횟수 업데이트

operation::game-controller-test/응원_횟수를_업데이트한다[snippets='http-request,request-fields,http-response']

== 신고 API

=== 응원톡 신고

operation::report-controller-test/응원톡을_신고한다[snippets='http-request,request-fields,http-response']

== 리그 API

=== 리그 전체 조회

operation::league-query-controller-test/리그_전체를_조회한다[snippets='http-request,http-response,response-fields']

=== 리그에 해당하는 스포츠 종목 조회

operation::league-query-controller-test/리그의_해당하는_스포츠_전체를_조회한다[snippets='http-request,path-parameters,http-response,response-fields']

== 타임라인 API
=== 게임의 타임라인 조회
operation::timeline-query-controller-test/타임라인을_조회한다[snippets='http-request,path-parameters,http-response,response-fields']
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.sports.server.query.application;

import com.sports.server.command.cheertalk.domain.CheerTalk;
import com.sports.server.query.repository.CheerTalkDynamicRepository;
import com.sports.server.query.dto.response.CommentResponse;
import com.sports.server.common.dto.PageRequestDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sports.server.query.dto.response.CheerTalkResponse;
import com.sports.server.query.repository.CheerTalkDynamicRepository;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
Expand All @@ -19,17 +18,17 @@ public class CheerTalkQueryService {

private final CheerTalkDynamicRepository cheerTalkDynamicRepository;

public List<CommentResponse> getCommentsByGameId(final Long gameId, final PageRequestDto pageRequest) {
public List<CheerTalkResponse> getCheerTalksByGameId(final Long gameId, final PageRequestDto pageRequest) {
List<CheerTalk> cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime(
gameId, pageRequest.cursor(), pageRequest.size()
);

List<Long> gameTeamIds = getOrderedGameTeamIds(cheerTalks);

List<CommentResponse> responses = cheerTalks.stream()
.map(comment -> new CommentResponse(
comment,
getOrderOfGameTeamId(comment.getGameTeamId(), gameTeamIds)
List<CheerTalkResponse> responses = cheerTalks.stream()
.map(cheerTalk -> new CheerTalkResponse(
cheerTalk,
getOrderOfGameTeamId(cheerTalk.getGameTeamId(), gameTeamIds)
))
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package com.sports.server.query.dto.response;

import com.sports.server.command.cheertalk.domain.CheerTalk;

import java.time.LocalDateTime;

public record CommentResponse(
Long commentId,
public record CheerTalkResponse(
Long cheerTalkId,
String content,
Long gameTeamId,
LocalDateTime createdAt,
Boolean isBlocked,
int order
) {
public CommentResponse(CheerTalk cheerTalk, final int order) {
public CheerTalkResponse(CheerTalk cheerTalk, final int order) {
this(
cheerTalk.getId(),
checkCommentBlocked(cheerTalk),
checkCheerTalkIsBlocked(cheerTalk),
cheerTalk.getGameTeamId(),
cheerTalk.getCreatedAt(),
cheerTalk.isBlocked(),
order
);
}

private static String checkCommentBlocked(CheerTalk cheerTalk) {
private static String checkCheerTalkIsBlocked(CheerTalk cheerTalk) {
if (cheerTalk.isBlocked()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.sports.server.command.cheertalk.domain.CheerTalk;
import com.sports.server.command.cheertalk.domain.CheerTalkCreateEvent;
import com.sports.server.query.dto.response.CommentResponse;
import com.sports.server.query.dto.response.CheerTalkResponse;
import com.sports.server.common.application.EntityUtils;
import com.sports.server.query.application.GameTeamServiceUtils;
import com.sports.server.command.game.domain.Game;
Expand Down Expand Up @@ -33,7 +33,7 @@ public void handle(CheerTalkCreateEvent event) {

messagingTemplate.convertAndSend(
DESTINATION + game.getId(),
new CommentResponse(cheerTalk,
new CheerTalkResponse(cheerTalk,
gameTeamServiceUtils.calculateOrderOfGameTeam(game, cheerTalk.getGameTeamId()))
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package com.sports.server.query.presentation;

import com.sports.server.query.dto.response.CommentResponse;
import com.sports.server.common.dto.PageRequestDto;
import com.sports.server.query.application.CheerTalkQueryService;
import com.sports.server.query.dto.response.CheerTalkResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class CheerTalkQueryController {

private final CheerTalkQueryService cheerTalkQueryService;

@GetMapping("games/{gameId}/cheer-talks")
public ResponseEntity<List<CommentResponse>> getAllComments(@PathVariable final Long gameId,
@ModelAttribute final PageRequestDto pageRequest) {
public ResponseEntity<List<CheerTalkResponse>> getAllCheerTalks(@PathVariable final Long gameId,
@ModelAttribute final PageRequestDto pageRequest) {

return ResponseEntity.ok(cheerTalkQueryService.getCommentsByGameId(gameId, pageRequest));
return ResponseEntity.ok(cheerTalkQueryService.getCheerTalksByGameId(gameId, pageRequest));
}
}
Loading

0 comments on commit 1448317

Please sign in to comment.