Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…TTHON_TEAM_32_BE into develope
  • Loading branch information
Sirius506775 committed Mar 23, 2024
2 parents 1ab55d3 + cb8e3e3 commit deb5f43
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 56 deletions.
103 changes: 59 additions & 44 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,57 +47,72 @@ jobs:
- name: Build with Gradle
run: ./gradlew build -x test

- name: Prepare keystore
run: echo "${{ secrets.KEYSTORE }}" > keystore.p12

- name: Move keystore file to Docker build context
run: mv keystore.p12 src/main/resources/

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to NCP Container Registry
uses: docker/login-action@v2
# Record test results as comments in PR
- name: Write test results in comments to Pull Request
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
files: '**/build/test-results/test/TEST-*.xml'

- name: Build and Push Docker Image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:latest
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:latest
cache-to: type=inline
secrets: |
GIT_AUTH_TOKEN=${{ secrets.GIT_TOKEN }}
- name: Connect to Server and Pull from Container Registry
uses: appleboy/[email protected]
# If a test fails, write a check comment to the failed code line
- name: If a test fails, write a check comment to the failed code line
uses: mikepenz/action-junit-report@v3
if: always()
with:
host: ${{ secrets.NCP_SERVER_IP }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
port: ${{ secrets.NCP_SERVER_PORT }}
script: |
echo "${{ secrets.NCP_SECRET_KEY }}" | docker login -u ${{ secrets.NCP_ACCESS_KEY }} --password-stdin ${{ secrets.NCP_CONTAINER_REGISTRY }}
report_paths: '**/build/test-results/test/TEST-*.xml'
token: ${{ github.token }}

# - name: Prepare keystore
# run: echo "${{ secrets.KEYSTORE }}" > keystore.p12

# - name: Move keystore file to Docker build context
# run: mv keystore.p12 src/main/resources/

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2

# - name: Login to NCP Container Registry
# uses: docker/login-action@v2
# with:
# registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
# username: ${{ secrets.NCP_ACCESS_KEY }}
# password: ${{ secrets.NCP_SECRET_KEY }}

# - name: Build and Push Docker Image
# uses: docker/build-push-action@v3
# with:
# context: .
# file: ./Dockerfile
# push: true
# tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:latest
# cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:latest
# cache-to: type=inline
# secrets: |
# GIT_AUTH_TOKEN=${{ secrets.GIT_TOKEN }}

# - name: Connect to Server and Pull from Container Registry
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.NCP_SERVER_IP }}
# username: ${{ secrets.NCP_SERVER_USERNAME }}
# password: ${{ secrets.NCP_SERVER_PASSWORD }}
# port: ${{ secrets.NCP_SERVER_PORT }}
# script: |
# echo "${{ secrets.NCP_SECRET_KEY }}" | docker login -u ${{ secrets.NCP_ACCESS_KEY }} --password-stdin ${{ secrets.NCP_CONTAINER_REGISTRY }}

latest_tag=$(docker pull --quiet ${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:latest | grep -oP "(?<=digest: ).*")
# latest_tag=$(docker pull --quiet ${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:latest | grep -oP "(?<=digest: ).*")

echo "-----------------Latest tag found: ${{ secrets.LATEST_TAG }}"
# echo "-----------------Latest tag found: ${{ secrets.LATEST_TAG }}"

container_id=$(docker ps -aq)
# container_id=$(docker ps -aq)

if [ ! -z "$container_id" ]; then
docker stop $container_id
docker rm $container_id
fi
# if [ ! -z "$container_id" ]; then
# docker stop $container_id
# docker rm $container_id
# fi

docker run -d -p 443:443
${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:${{ secrets.LATEST_TAG }}
# docker run -d -p 443:443
# ${{ secrets.NCP_CONTAINER_REGISTRY }}/balpyo-server:${{ secrets.LATEST_TAG }}


docker image prune -f
# docker image prune -f
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

compileOnly 'org.projectlombok:lombok:1.18.4'
annotationProcessor 'org.projectlombok:lombok:1.18.4'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
Expand All @@ -34,7 +36,6 @@ dependencies {


implementation(platform("software.amazon.awssdk:bom:2.21.1"))

implementation 'com.amazonaws:aws-java-sdk-polly:1.12.681'
// implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.2'
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/site/balpyo/common/dto/ErrorEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
@AllArgsConstructor
public enum ErrorEnum {

//6000 - Sript 계열 에러
SCRIPT_NOT_FOUND("6001", "저장된 스크립트가 없습니다."),
SCRIPT_DETAIL_NOT_FOUND("6002", "해당 조건의 스크립트가 없습니다."),
//7000 - Guest 계열에러
GUEST_NOT_FOUND("7001", "존재하지 않는 게스트입니다."),

//8000 - GPT 계열에러
GPT_GENERATION_ERROR("8001", "GPT 스크립트 생성 실패."),
GPT_API_KEY_MISSING("8002", "GPT API 키 누락."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ResponseEntity<CommonResponse> generateUniqueIdentifier(){
}

@GetMapping("/uid")
public ResponseEntity<CommonResponse> verifyUID( @RequestHeader(value = "UID", required = false) String uid){
public ResponseEntity<CommonResponse> verifyUID(@RequestHeader(value = "UID", required = false) String uid){
if(CommonUtils.isAnyParameterNullOrBlank(uid))return CommonResponse.error(ErrorEnum.BALPYO_UID_KEY_MISSING);
return guestService.verifyUID(uid);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/site/balpyo/guest/dto/UIDResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class UIDResponse {

private String uid;


}
2 changes: 2 additions & 0 deletions src/main/java/site/balpyo/guest/entity/GuestEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public class GuestEntity {
@OneToMany(mappedBy = "guestEntity", cascade = CascadeType.ALL)
private List<ScriptEntity> scriptEntities;

private Integer coin;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,23 @@ public class EveryScriptController {
public ResponseEntity<CommonResponse> saveScript(@RequestBody ScriptRequest scriptRequest,
@RequestHeader(value = "UID", required = false) String uid){

if(CommonUtils.isAnyParameterNullOrBlank(uid))return CommonResponse.error(ErrorEnum.BALPYO_UID_KEY_MISSING);
return scriptService.saveScript(scriptRequest,uid);
if(CommonUtils.isAnyParameterNullOrBlank(uid)) return CommonResponse.error(ErrorEnum.BALPYO_UID_KEY_MISSING);
return scriptService.saveScript(scriptRequest, uid);
}

@GetMapping("/script/all")
public ResponseEntity<CommonResponse> getAllScript(@RequestHeader(value = "UID", required = false) String uid) {

if (CommonUtils.isAnyParameterNullOrBlank(uid)) return CommonResponse.error(ErrorEnum.BALPYO_UID_KEY_MISSING);
return scriptService.getAllScript(uid);
}

@GetMapping("/script/detail/{scriptId}")
public ResponseEntity<CommonResponse> getDetailScript(@RequestHeader(value = "UID", required = false) String uid,
@PathVariable Long scriptId) {

if (CommonUtils.isAnyParameterNullOrBlank(uid)) return CommonResponse.error(ErrorEnum.BALPYO_UID_KEY_MISSING);
return scriptService.getDetailScript(uid,scriptId);
}

}
11 changes: 7 additions & 4 deletions src/main/java/site/balpyo/script/dto/ScriptResponse.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package site.balpyo.script.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.*;

@Data
@Getter
@Setter
@Builder
@AllArgsConstructor
public class ScriptResponse {


private Long scriptId;
private String script;
private String gptId;
private String uid;
private String title;
private Integer secTime;

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package site.balpyo.script.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import site.balpyo.script.entity.ScriptEntity;

import java.util.Optional;

public interface ScriptRepository extends JpaRepository<ScriptEntity, Long> {
@Query("SELECT s FROM ScriptEntity s WHERE s.guestEntity.uid = :uid AND s.script_id = :scriptId")
Optional<ScriptEntity> findScriptByGuestUidAndScriptId(@Param("uid") String uid, @Param("scriptId") Long scriptId);

}
50 changes: 49 additions & 1 deletion src/main/java/site/balpyo/script/service/ScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import site.balpyo.ai.repository.AIGenerateLogRepository;
import site.balpyo.ai.repository.GPTInfoRepository;
import site.balpyo.common.dto.CommonResponse;
import site.balpyo.common.dto.ErrorEnum;
import site.balpyo.guest.entity.GuestEntity;
import site.balpyo.guest.repository.GuestRepository;
import site.balpyo.script.dto.ScriptRequest;
import site.balpyo.script.dto.ScriptResponse;
import site.balpyo.script.entity.ScriptEntity;
import site.balpyo.script.repository.ScriptRepository;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -58,8 +61,53 @@ public ResponseEntity<CommonResponse> saveScript(ScriptRequest scriptRequest, St

scriptRepository.save(scriptEntity);

ScriptResponse scriptResponse = new ScriptResponse(scriptRequest.getScript(), scriptRequest.getGptId(),uid,scriptRequest.getTitle(),scriptRequest.getSecTime());
ScriptResponse scriptResponse = new ScriptResponse(null,scriptRequest.getScript(), scriptRequest.getGptId(),uid,scriptRequest.getTitle(),scriptRequest.getSecTime());

return CommonResponse.success(scriptResponse);
}

public ResponseEntity<CommonResponse> getAllScript(String uid) {
Optional<GuestEntity> guestEntity = guestRepository.findById(uid);

if(guestEntity.isEmpty())return CommonResponse.error(ErrorEnum.GUEST_NOT_FOUND);
if(guestEntity.get().getScriptEntities().isEmpty())return CommonResponse.error(ErrorEnum.SCRIPT_NOT_FOUND);

List<ScriptEntity> scriptEntities = guestEntity.get().getScriptEntities();

List<ScriptResponse> scriptResponses = new ArrayList<>();
for(ScriptEntity scriptEntity: scriptEntities){
ScriptResponse scriptResponse = ScriptResponse.builder()
.scriptId(scriptEntity.getScript_id())
.uid(uid)
.title(scriptEntity.getTitle())
.secTime(scriptEntity.getSecTime())
.build();

scriptResponses.add(scriptResponse);
}

return CommonResponse.success(scriptResponses);

}

public ResponseEntity<CommonResponse> getDetailScript(String uid, Long scriptId) {
Optional<ScriptEntity> optionalScriptEntity = scriptRepository.findScriptByGuestUidAndScriptId(uid,scriptId);

if(optionalScriptEntity.isEmpty())return CommonResponse.error(ErrorEnum.SCRIPT_DETAIL_NOT_FOUND);

ScriptEntity scriptEntity = optionalScriptEntity.get();

ScriptResponse scriptResponse = ScriptResponse
.builder()
.scriptId(scriptEntity.getScript_id())
.secTime(scriptEntity.getSecTime())
.uid(scriptEntity.getGuestEntity().getUid())
.title(scriptEntity.getTitle())
.script(scriptEntity.getScript())
.build();

return CommonResponse.success(scriptResponse);


}
}

0 comments on commit deb5f43

Please sign in to comment.