Skip to content

Commit

Permalink
Merge pull request #39 from GoogleEyes-ewha/develop
Browse files Browse the repository at this point in the history
develop 브랜치 → main 브랜치 병합
  • Loading branch information
Haewonny authored Feb 19, 2024
2 parents 90cc6c8 + 6339c8d commit 8a7b9ba
Show file tree
Hide file tree
Showing 74 changed files with 3,156 additions and 29 deletions.
106 changes: 83 additions & 23 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Java CI/CD with Gradle

on:
push:
branches: [ "main" ]
branches:
- main
- develop
pull_request:
branches:
- main
Expand Down Expand Up @@ -32,31 +34,89 @@ jobs:
echo "${{ secrets.APPLICATION }}" > ./application.yml
shell: bash

- name: Download keystore.p12
run: |
cd ./src/main/resources
touch ./keystore.p12
echo "${{ secrets.KEYSTORE }}" | base64 -d > ./keystore.p12
shell: bash

- name: google application credentials
run: |
cd ./src/main/resources
touch ./credentials.json
echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS}}" > ./credentials.json
shell: bash

- name: Set up environment
run: |
cd ./src/main/resources
echo "GOOGLE_APPLICATION_CREDENTIALS=./credentials.json" >> $GITHUB_ENV
env:
GOOGLE_APPLICATION_CREDENTIALS: ./credentials.json

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app .
docker tag app ${{ secrets.DOCKER_USERNAME }}/hearo:latest
docker push ${{ secrets.DOCKER_USERNAME }}/hearo:latest
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
# 도커 작업
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/hearo:latest
docker stop $(docker ps -a -q)
docker run -d --log-driver=syslog -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/hearo:latest
docker rm $(docker ps --filter 'status=exited' -a -q)
docker image prune -a -f
deploy-to-Server:
if: github.event_name == 'push'
name: Deploy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: make application.properties
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
shell: bash
- name: Download keystore.p12
run: |
cd ./src/main/resources
touch ./keystore.p12
echo "${{ secrets.KEYSTORE }}" | base64 -d > ./keystore.p12
- name: Set up environment
run: |
echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}" > credentials.json
env:
GOOGLE_APPLICATION_CREDENTIALS: ./credentials.json
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app .
docker tag app ${{ secrets.DOCKER_USERNAME }}/hearo:latest
docker push ${{ secrets.DOCKER_USERNAME }}/hearo:latest
- name: Deploy start
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
# 도커 작업
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/hearo:latest
docker stop $(docker ps -a -q)
docker run -d --log-driver=syslog -p 8080:8080 \
-v "$HOME/.config/gcloud/":/gcp/:ro \
-e GOOGLE_APPLICATION_CREDENTIALS=/gcp/application_default_credentials.json \
${{ secrets.DOCKER_USERNAME }}/hearo:latest
docker rm $(docker ps --filter 'status=exited' -a -q)
docker image prune -a -f
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM openjdk:17-jdk
ARG JAR_FILE=build/libs/hearo-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} /app.jar
COPY src/main/resources/keystore.p12 keystore.p12

ENTRYPOINT ["java","-jar","/app.jar"]
ENTRYPOINT ["java","-jar","/app.jar"]
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,24 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'

//docement AI
implementation platform('com.google.cloud:libraries-bom:26.31.0')
implementation 'com.google.cloud:google-cloud-document-ai'

}

tasks.named('test') {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/gdsc/hearo/HearoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.web.filter.HiddenHttpMethodFilter;

@EnableJpaAuditing
@SpringBootApplication
public class HearoApplication {

public static void main(String[] args) {
SpringApplication.run(HearoApplication.class, args);
}

public static void main(String[] args) {

SpringApplication.run(HearoApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.gdsc.hearo.domain.item.controller;

import com.gdsc.hearo.domain.item.dto.*;
import com.gdsc.hearo.domain.item.service.ItemService;
import com.gdsc.hearo.global.common.BaseResponse;
import com.gdsc.hearo.global.common.BaseResponseStatus;
import com.gdsc.hearo.global.security.CustomUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/item")
public class ItemController {

private final ItemService itemService;


@Autowired
public ItemController(ItemService itemService){
this.itemService = itemService;
}

/*@GetMapping("/{categoryId}")
public ResponseEntity<BaseResponse<Map<String, Object>>> getItemByCategory(@PathVariable(name = "categoryId") Long categoryId) {
BaseResponse<Map<String, Object>> response;
try {
List<CategoryResponseDto> itemList = itemService.getItemByCategory(categoryId);
Map<String, Object> result = new HashMap<>();
if (itemList.isEmpty()) {
response = new BaseResponse<>(BaseResponseStatus.NO_CONTENT, null);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(response);
}
result.put("itemCount", itemList.size());
result.put("itemList", itemList);
response = new BaseResponse<>(BaseResponseStatus.SUCCESS, result);
return ResponseEntity.ok(response);
} catch (Exception e) {
// 기타 예외에 대한 기본 처리
response = new BaseResponse<>(BaseResponseStatus.INTERNAL_SERVER_ERROR, null);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}*/
@GetMapping("/category/{categoryId}")
public ResponseEntity<BaseResponse<CategoryResponseDto>> getItemByCategory(@PathVariable(name = "categoryId") Long categoryId) {
BaseResponse<CategoryResponseDto> response;

try {
List<ItemDto> itemList = itemService.getItemByCategory(categoryId);
CategoryResponseDto result = CategoryResponseDto.builder()
.itemCount(itemList.size())
.list(itemList)
.build();

if (itemList.isEmpty()) {
response = new BaseResponse<>(BaseResponseStatus.NO_CONTENT, null);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(response);
}

response = new BaseResponse<>(BaseResponseStatus.SUCCESS,result);
return ResponseEntity.ok(response);

} catch (Exception e) {
// 기타 예외에 따른 기본 처리
response = new BaseResponse<>(BaseResponseStatus.INTERNAL_SERVER_ERROR, null);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}


@GetMapping
public ResponseEntity<BaseResponse<SearchResponseDto>> getItemByKeyword(
@RequestParam(name = "keyword") String keyword) {
BaseResponse<SearchResponseDto> response;

try {
List<ItemDto> itemList = itemService.getItemByKeyword(keyword);
SearchResponseDto result = SearchResponseDto.builder()
.keyword(keyword)
.itemCount(itemList.size())
.list(itemList)
.build();

if (itemList.isEmpty()) {
response = new BaseResponse<>(BaseResponseStatus.NO_CONTENT, null);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(response);
}

response = new BaseResponse<>(BaseResponseStatus.SUCCESS, result);
return ResponseEntity.ok(response);

} catch (Exception e) {
// Handle exceptions
response = new BaseResponse<>(BaseResponseStatus.INTERNAL_SERVER_ERROR, null);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}

@GetMapping("/{itemId}")
public ResponseEntity<BaseResponse<ItemDetailResponseDto>> getItemDetailById(
@PathVariable(name = "itemId") Long itemId,
@AuthenticationPrincipal CustomUserDetails userDetails) {
BaseResponse<ItemDetailResponseDto> response;

try {
Long userId = userDetails != null? userDetails.getMember().getMemberId():null;
ItemDetailResponseDto itemDetailResponse = itemService.getItemDetailById(itemId,userId);

response = new BaseResponse<>(BaseResponseStatus.SUCCESS, itemDetailResponse);
return ResponseEntity.ok(response);

}catch (Exception e) {
// Handle exceptions
response = new BaseResponse<>(BaseResponseStatus.INTERNAL_SERVER_ERROR, null);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.gdsc.hearo.domain.item.controller;

import com.gdsc.hearo.domain.item.dto.ItemTtsFileResponseDto;
import com.gdsc.hearo.domain.item.dto.ItemTtsRequestDto;
import com.gdsc.hearo.domain.item.dto.ItemTtsResponseDto;
import com.gdsc.hearo.domain.item.service.ItemTtsService;
import com.gdsc.hearo.domain.review.dto.ReviewTTSDto;
import com.gdsc.hearo.global.common.BaseException;
import com.gdsc.hearo.global.common.BaseResponse;
import com.gdsc.hearo.global.common.BaseResponseStatus;
import com.gdsc.hearo.global.common.VoiceType;
import com.gdsc.hearo.global.security.CustomUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemTtsController {

private final ItemTtsService itemTtsService;

@Autowired
public ItemTtsController(ItemTtsService itemTtsService){
this.itemTtsService = itemTtsService;
}

//[post]상품 음성 파일 저장
@PostMapping("/tts/{itemId}")
public BaseResponse<?> postItemTTSFile(@AuthenticationPrincipal CustomUserDetails user, @PathVariable(name="itemId") Long itemId, @RequestBody ItemTtsRequestDto request) {
try {
if (user != null) { // 로그인 한 경우
// 서비스를 호출하여 음성 파일 저장
ItemTtsResponseDto result = itemTtsService.saveItemTTS(user, itemId, request);

return new BaseResponse<>(BaseResponseStatus.SUCCESS, result);

} else { // 로그인하지 않은 경우
ItemTtsResponseDto result = itemTtsService.saveItemTTS(null, itemId, request);

return new BaseResponse<>(BaseResponseStatus.SUCCESS, "음성 파일이 저장되었습니다.");
}
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

// 상품 음성 파일 조회
@GetMapping("/tts/{itemId}")
public BaseResponse<ItemTtsFileResponseDto> getItemTts(@AuthenticationPrincipal CustomUserDetails user,
@PathVariable(name = "itemId") Long itemId) {

try{
if (user != null) { // 로그인 한 경우
ItemTtsFileResponseDto result = itemTtsService.getItemTts(user, itemId);
return new BaseResponse<>(BaseResponseStatus.SUCCESS, result);
}
else{
ItemTtsFileResponseDto result = itemTtsService.getItemTts(null,itemId);
return new BaseResponse<>(BaseResponseStatus.SUCCESS, result);
}
}catch(Exception e){
e.printStackTrace();
return null; // 예외처리 이상함..
}
}
}
Loading

0 comments on commit 8a7b9ba

Please sign in to comment.