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

Feature: 결승진출자 조회 버튼 분리 #20

Merged
merged 14 commits into from
May 31, 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
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Feature Issue Template
about: Feature 브랜치 생성 전 작성해주세요
title: "[Feature]"
labels: ''
assignees: ''

---

## 🪶 추가할 기능 설명


## ✅ 작업 내용

- [ ] 구현 내용 1
- [ ] 구현 내용 2

## 스크린샷 (선택)

## 🔗 참고한 링크 (선택)

## ETC
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/fix-issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Fix Issue Template
about: Fix 브랜치 생성 전 작성해주세요
title: "[Fix]"
labels: ''
assignees: ''

---

## ⚠️ 발생한 에러


## 에러가 발생한 상황

**Given** :
**When** :
**Then** :

## ✅ 수정한 내용

- [ ] 수정 내용 1
- [ ] 수정 내용 2



## 📡 예상 결과

## 🔗 참고한 자료
9 changes: 9 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 연관된 이슈

이슈링크(url):


## ✅ 작업 내용


## 🗣 ️리뷰 요구 사항
15 changes: 14 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
CODE_DEPLOY_APP_NAME: cotato-deploy
DEPLOYMENT_GROUP_NAME: cotato-deploy-group
RESOURCE_PATH: ./src/main/resources/application-prod.yml
BASE_RESOURCE_PATH: ./src/main/resources/application.yml

jobs:
build:
Expand All @@ -36,6 +37,13 @@ jobs:
spring.jpa.hibernate.ddl-auto: ${{ secrets.DDL_AUTO }}
spring.mail.username: ${{ secrets.SENDER_EMAIL }}
spring.mail.password: ${{ secrets.SENDER_PASSWORD }}

# application-yml을 세팅한다.
- name: Set up Base Yaml File
uses: microsoft/variable-substitution@v1
with:
files: ${{ env.BASE_RESOURCE_PATH }}
env:
jwt.secretKey: ${{ secrets.JWT_SECRET_KEY}}
cloud.aws.s3.bucket: ${{ secrets.S3_BUCKET_NAME }}
cloud.aws.credentials.accessKey: ${{ secrets.S3_ACCESS_KEY }}
Expand All @@ -51,7 +59,12 @@ jobs:

# [3] 프로젝트 빌드
- name: Build with Gradle Wrapper
run: ./gradlew prodJar
run: ./gradlew build

# [3] - 1 생성된 jar 파일 이름 변경
- name: Rename JAR file
run: mv build/libs/*.jar build/libs/csquiz-prod-0.0.1-SNAPSHOT.jar
shell: bash

# [4] Zip 파일 만들기
- name: Make Zip File
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ on:
env:
PROJECT_NAME: COTATO-BE-TEST
BUCKET_NAME: cotato-ci-cd-bucket-test
CODE_DEPLOY_APP_NAME: cotato-deploy-test
CODE_DEPLOY_APP_NAME: cotato-deploy
DEPLOYMENT_GROUP_NAME: cotato-deploy-group-test
RESOURCE_PATH: ./src/main/resources/application-stage.yml
BASE_RESOURCE_PATH: ./src/main/resources/application.yml

jobs:
build:
Expand All @@ -25,6 +26,7 @@ jobs:
distribution: 'zulu'

# [1] Set up Yaml File
# application-stage.yml을 세팅한다.
- name: Set up Yaml File
uses: microsoft/variable-substitution@v1
with:
Expand All @@ -36,6 +38,13 @@ jobs:
spring.jpa.hibernate.ddl-auto: ${{ secrets.TEST_DDL_AUTO }}
spring.mail.username: ${{ secrets.SENDER_EMAIL }}
spring.mail.password: ${{ secrets.SENDER_PASSWORD }}

# application.yml을 세팅한다.
- name: Set up Base Yaml File
uses: microsoft/variable-substitution@v1
with:
files: ${{ env.BASE_RESOURCE_PATH }}
env:
jwt.secretKey: ${{ secrets.JWT_SECRET_KEY}}
cloud.aws.s3.bucket: ${{ secrets.S3_BUCKET_NAME }}
cloud.aws.credentials.accessKey: ${{ secrets.S3_ACCESS_KEY }}
Expand All @@ -51,7 +60,12 @@ jobs:

# [3] 프로젝트 빌드
- name: Build with Gradle Wrapper
run: ./gradlew stageJar
run: ./gradlew build

# [3] - 1 생성된 jar 파일 이름 변경
- name: Rename JAR file
run: mv build/libs/*.jar build/libs/csquiz-stage-0.0.1-SNAPSHOT.jar
shell: bash

# [4] Zip 파일 만들기
- name: Make Zip File
Expand Down
1 change: 1 addition & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ files:
- source: /
destination: /home/ubuntu/backend/CS-Quiz-BE
overwrite: yes
file_exists_behavior: OVERWRITE

permissions:
- object: /
Expand Down
10 changes: 0 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,3 @@ tasks.named('test') {
jar {
enabled = false
}

task stageJar(type: Jar) {
archiveBaseName.set("${project.name}-stage")
from sourceSets.main.output
}

task prodJar(type: Jar) {
archiveBaseName.set("${project.name}-prod")
from sourceSets.main.output
}
11 changes: 10 additions & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

# Git이 디렉토리를 안전한 디렉토리로 인식하도록 설정
git config --global --add safe.directory /home/ubuntu/backend/CS-Quiz-BE

# .git repo가 존재하는 곳으로 이동
cd /home/ubuntu/backend/CS-Quiz-BE || { echo "Failed to change directory to git root"; exit 1; }

# 현재 브랜치 이름 가져오기
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

Expand All @@ -11,16 +17,19 @@ if [ "$CURRENT_BRANCH" == "main" ]; then
PROFILE="prod"
DIRECTORY="production"
PORT=8080
echo "현재 브랜치: '$CURRENT_BRANCH'"
elif [ "$CURRENT_BRANCH" == "release" ]; then
PROFILE="stage"
DIRECTORY="release"
PORT=8082
echo "현재 브랜치: '$CURRENT_BRANCH'"
else
echo "현재 브랜치: '$CURRENT_BRANCH'"
echo "지원되지 않는 브랜치입니다: $CURRENT_BRANCH" >&2
exit 1
fi

JAR_PATH="/home/ubuntu/backend/$PROJECT_NAME/build/libs/*$PROFILE.jar"
JAR_PATH="/home/ubuntu/backend/$PROJECT_NAME/build/libs/*$PROFILE*.jar"
DEPLOY_PATH=/home/ubuntu/backend/$DIRECTORY/$PROJECT_NAME/ #jar 파일이 복사되고 실행될 경로
DEPLOY_LOG_PATH="/home/ubuntu/backend/$DIRECTORY/log/deploy/$PROJECT_NAME/deploy_$(date +%Y%m%d).log"
DEPLOY_ERR_LOG_PATH="/home/ubuntu/backend/$DIRECTORY/log/deploy/$PROJECT_NAME/deploy_err_$(date +%Y%m%d).log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.cotato.csquiz.api.education.dto.WinnerInfoResponse;
import org.cotato.csquiz.api.quiz.dto.KingMemberInfo;
import org.cotato.csquiz.domain.education.service.EducationService;
import org.cotato.csquiz.domain.education.service.KingMemberService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -30,6 +31,7 @@
public class EducationController {

private final EducationService educationService;
private final KingMemberService kingMemberService;

@GetMapping
public ResponseEntity<List<AllEducationResponse>> findEducationListByGeneration(
Expand Down Expand Up @@ -60,15 +62,29 @@ public ResponseEntity<EducationIdOfQuizResponse> findEducationId(@RequestParam("
return ResponseEntity.ok().body(educationService.findEducationIdOfQuizId(quizId));
}

@GetMapping("/result/kings")
@GetMapping("/kings")
public ResponseEntity<List<KingMemberInfo>> findFinalKingMembers(@RequestParam("educationId") Long educationId) {
log.info("[{} 교육 결승진출자 조회 컨트롤러]", educationId);
return ResponseEntity.ok().body(educationService.findKingMemberInfo(educationId));
return ResponseEntity.ok().body(kingMemberService.findKingMemberInfo(educationId));
}

@GetMapping("/result/winner")
@PostMapping("/kings")
public ResponseEntity<Void> calculateKingMembers(@RequestParam("educationId") Long educationId) {
log.info("[{} 교육 결승진출자 계산하기]", educationId);
kingMemberService.saveKingMember(educationId);
return ResponseEntity.noContent().build();
}

@GetMapping("/winner")
public ResponseEntity<WinnerInfoResponse> findWinner(@RequestParam("educationId") Long educationId) {
log.info("[{} 교육 우승자 조회 컨트롤러]", educationId);
return ResponseEntity.ok().body(educationService.findWinner(educationId));
return ResponseEntity.ok().body(kingMemberService.findWinner(educationId));
}

@PostMapping("/winner")
public ResponseEntity<Void> calculateWinner(@RequestParam("educationId") Long educationId) {
log.info("[{} 교육 우승자 계산]", educationId);
kingMemberService.calculateWinner(educationId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -68,4 +69,19 @@ public ResponseEntity<Void> stopAllQuiz(@RequestBody @Valid EducationCloseReques
public ResponseEntity<SocketTokenDto> makeSocketToken(@RequestHeader("Authorization") String authorizationHeader) {
return ResponseEntity.ok(socketService.createSocketToken(authorizationHeader));
}


@PostMapping("/kings")
public ResponseEntity<Void> sendKingCommand(@RequestParam("educationId") Long educationId) {
log.info("[{} 교육 결승진출자 재전송하기]", educationId);
socketService.sendKingCommand(educationId);
return ResponseEntity.noContent().build();
}

@PostMapping("/winner")
public ResponseEntity<Void> sendWinnerCommand(@RequestParam("educationId") Long educationId) {
log.info("[{} 교육 결승진출자 재전송하기]", educationId);
socketService.sendWinnerCommand(educationId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.cotato.csquiz.api.socket.dto;

import org.cotato.csquiz.domain.education.entity.Education;

public record EducationResultResponse(
String command,
Long educationId
) {
public static EducationResultResponse of(String command, Long educationId) {
return new EducationResultResponse(command, educationId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ public record QuizStopResponse(
String command,
Long quizId
) {
public static QuizStopResponse from(String command, Long quizId) {
public static final String STOP_COMMAND = "stop";

public static QuizStopResponse from(Long quizId) {
return new QuizStopResponse(
command,
STOP_COMMAND,
quizId
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/cotato/csquiz/common/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ public enum ErrorCode {

SUBJECT_INVALID(HttpStatus.BAD_REQUEST, "E-000", "교육 주제는 NULL이거나 비어있을 수 없습니다."),

KING_MEMBER_EXIST(HttpStatus.CONFLICT, "K-301", "이미 킹킹 멤버가 존재합니다"),

ALREADY_REPLY_CORRECT(HttpStatus.BAD_REQUEST, "R-301", "해당 사용자는 이미 정답 처리되었습니다."),

LAST_QUIZ_SCORER_NOT_EXIST(HttpStatus.CONFLICT, "W-201", "아직 마지막 문제 득점자가 없습니다"),
WINNER_EXIST(HttpStatus.CONFLICT, "W-301", "이미 우승자가 존재합니다"),
// 500 오류 -> 서버측에서 처리가 실패한 부분들
WEBSOCKET_SEND_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "S-001", "소캣 메세지 전송 실패"),
IMAGE_PROCESSING_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "S-002", "이미지 처리에 실패했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import org.cotato.csquiz.api.socket.dto.CsQuizStopResponse;
import org.cotato.csquiz.api.socket.dto.EducationResultResponse;
import org.cotato.csquiz.api.socket.dto.QuizStartResponse;
import org.cotato.csquiz.api.socket.dto.QuizStatusResponse;
import org.cotato.csquiz.api.socket.dto.QuizStopResponse;
Expand Down Expand Up @@ -118,14 +119,23 @@ public void startQuiz(Long quizId) {
}

public void stopQuiz(Quiz quiz) {
String command = "";
if (quiz.getNumber() == 9) {
command = KING_COMMAND;
QuizStopResponse response = QuizStopResponse.from(quiz.getId());
for (WebSocketSession clientSession : CLIENTS.values()) {
sendMessage(clientSession, response);
}
if (quiz.getNumber() == 10) {
command = WINNER_COMMAND;
}

public void sendKingMemberCommand(Long educationId) {
EducationResultResponse response = EducationResultResponse.of(KING_COMMAND, educationId);

for (WebSocketSession clientSession : CLIENTS.values()) {
sendMessage(clientSession, response);
}
QuizStopResponse response = QuizStopResponse.from(command, quiz.getId());
}

public void sendWinnerCommand(Long educationId) {
EducationResultResponse response = EducationResultResponse.of(WINNER_COMMAND, educationId);

for (WebSocketSession clientSession : CLIENTS.values()) {
sendMessage(clientSession, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

public interface KingMemberRepository extends JpaRepository<KingMember, Long> {
List<KingMember> findAllByEducation(Education education);

boolean existsByEducation(Education education);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cotato.csquiz.domain.education.repository;

import org.cotato.csquiz.domain.education.entity.Education;
import org.cotato.csquiz.domain.education.entity.Quiz;
import org.cotato.csquiz.domain.education.enums.QuizStatus;
import java.util.List;
Expand Down Expand Up @@ -29,4 +30,8 @@ public interface QuizRepository extends JpaRepository<Quiz, Long> {
@Modifying
@Query("select q from Quiz q where q.education.id in :educationIds")
List<Quiz> findAllByEducationIdsInQuery(@Param("educationIds") List<Long> educationIds);

Optional<Quiz> findByEducationIdAndNumber(Long educationId, Integer i);

Optional<Quiz> findFirstByEducationOrderByNumberDesc(Education education);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

public interface WinnerRepository extends JpaRepository<Winner, Long> {
Optional<Winner> findByEducation(Education education);

boolean existsByEducation(Education education);
}
Loading
Loading