Skip to content

Commit

Permalink
Merge pull request #45 from devocean-finut/develop
Browse files Browse the repository at this point in the history
Deploy v1
  • Loading branch information
LUCETE012 authored Nov 13, 2024
2 parents 3a70623 + ef28e57 commit 1a53ca9
Show file tree
Hide file tree
Showing 55 changed files with 1,646 additions and 480 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy to EC2

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.FINUT_SSH_KEY }}

- name: Deploy to EC2
env:
EC2_HOST: ${{ secrets.FINUT_EC2_HOST }}
EC2_USER: ${{ secrets.FINUT_EC2_USER }}
run: |
ssh -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST 'bash /home/ec2-user/app/deploy.sh'
29 changes: 28 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ plugins {
id 'io.spring.dependency-management' version '1.1.5'
}

jar {
manifest {
attributes(
'Main-Class': 'com.finut.finut_server.FinutServerApplication'
)
}
}


group = 'com.finut'
version = '0.0.1-SNAPSHOT'

Expand All @@ -28,16 +37,34 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' // ์Šค์›จ๊ฑฐ
implementation 'org.jsoup:jsoup:1.15.3' // ํฌ๋กค๋ง

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// Google Auth Library for OAuth 2.0
implementation 'com.google.auth:google-auth-library-oauth2-http:1.8.0'

// Google API Client Library for OAuth2
implementation 'com.google.apis:google-api-services-oauth2:v2-rev151-1.25.0'

// JSON Parsing (Gson)
implementation 'com.google.http-client:google-http-client-gson:1.41.6'

// mysql ์„ค์ •
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.mariadb.jdbc:mariadb-java-client'

//RSS ํˆด
implementation 'com.rometools:rome:1.15.0'

//MariaDB
implementation("org.mariadb.jdbc:mariadb-java-client")

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public static <T> ApiResponse<T> of(BaseCode code, T result){
public static <T> ApiResponse<T> onFailure(String code, String message, T data){
return new ApiResponse<>(true, code, message, data);
}

public String getData() {
return message;
}

public String getStatusCode() {
return code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public enum ErrorStatus implements BaseErrorCode {
ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "ARTICLE4001", "๊ฒŒ์‹œ๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค."),

// ํ€ด์ฆˆ ๊ด€๋ จ ์—๋Ÿฌ
INVALID_NUMBER(HttpStatus.BAD_REQUEST, "QUIZ400", "์œ ํšจํ•˜์ง€ ์•Š์€ ๊ฐ’์ž…๋‹ˆ๋‹ค.");
INVALID_NUMBER(HttpStatus.BAD_REQUEST, "QUIZ400", "์œ ํšจํ•˜์ง€ ์•Š์€ ๊ฐ’์ž…๋‹ˆ๋‹ค."),
NULL_DATA(HttpStatus.BAD_REQUEST, "QUIZ401", "๋ฐ์ดํ„ฐ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."),

// ์ถœ์„ ๊ด€๋ จ ์—๋Ÿฌ
NO_DATA_FOUND(HttpStatus.BAD_REQUEST, "ATTEND400", "๋ฐ์ดํ„ฐ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค");

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import com.finut.finut_server.apiPayload.exception.handler.CustomOAuth2AuthenticationSuccessHandler;
import com.finut.finut_server.config.auth.CustomOAuth2UserService;
import com.finut.finut_server.domain.user.UsersRepository;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
Expand Down Expand Up @@ -44,7 +46,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, CustomOAuth2Us
logout
.logoutSuccessUrl("/") // ์ž„์‹œ
)
.csrf(csrf -> csrf.ignoringRequestMatchers("/h2-console/**"))
.csrf(AbstractHttpConfigurer::disable) // post ์š”์ฒญ์„ ์œ„ํ•œ csrf disable
.headers(headers -> headers.frameOptions(frameOptions -> frameOptions.sameOrigin()));
return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@


import com.finut.finut_server.apiPayload.ApiResponse;
import com.finut.finut_server.apiPayload.code.ErrorReasonDTO;
import com.finut.finut_server.domain.product.Product;
import com.finut.finut_server.domain.purchases.Purchases;
import com.finut.finut_server.domain.user.Users;
import com.finut.finut_server.service.ConsumptionService;
import com.finut.finut_server.service.PurchasesService;
import com.finut.finut_server.service.UsersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

Expand All @@ -22,32 +31,72 @@ public class ConsumptionController {
private final ConsumptionService consumptionService;
private final PurchasesService purchasesService;

private UsersService usersService;

@Autowired
public ConsumptionController(ConsumptionService consumptionService, PurchasesService purchasesService) {
this.consumptionService = consumptionService;
this.purchasesService = purchasesService;
}
@Operation(summary = "์ „์ฒด ๋ฌผํ’ˆ ๋ณด๊ธฐ", description = "์ „์ฒด ๋ฌผํ’ˆ์„ ๋ณด๊ธฐ ์œ„ํ•œ api ์ž…๋‹ˆ๋‹ค")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = Product.class)))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@GetMapping("/products")
public ApiResponse<List<Product>> readAllProducts() {
return ApiResponse.onSuccess(ConsumptionService.getAllProducts());
}

@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = Product.class)))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@Operation(summary = "๋ฌผํ’ˆ ์ƒ์„ธ ์ •๋ณด ๋ณด๊ธฐ", description = "๊ฐ ๋ฌผํ’ˆ์˜ ์ƒ์„ธ ์ •๋ณด๋ฅผ ๋ณด๊ธฐ ์œ„ํ•œ api ์ž…๋‹ˆ๋‹ค")
@GetMapping("/products/{productId}")
public ApiResponse<Optional<Product>> readProduct(@PathVariable Long productId) {
return ApiResponse.onSuccess(ConsumptionService.getProductInfo(productId));
}

@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Purchases.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@Operation(summary = "๋ฌผํ’ˆ ๊ตฌ๋งค", description = "๋ฌผํ’ˆ์„ ๊ตฌ๋งคํ•˜๊ธฐ ์œ„ํ•œ api ์ž…๋‹ˆ๋‹ค")
@GetMapping("/buy")
public ApiResponse<Purchases> buyProduct(@RequestParam Long userId, @RequestParam Long productId) {
return ApiResponse.onSuccess(PurchasesService.buyProduct(userId, productId));
public ApiResponse<Purchases> buyProduct(@RequestParam Long productId, HttpServletRequest request, HttpServletResponse response) {
Users user = usersService.getUserIdByToken(request, response);
return ApiResponse.onSuccess(PurchasesService.buyProduct(user.getId(), productId));
}

@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = Product.class)))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@Operation(summary = "๋‚ด ๋ฌผํ’ˆ ๋ณด๊ธฐ", description = "๊ตฌ๋งคํ•œ ๋ฌผํ’ˆ๋“ค์„ ๋ชจ๋‘ ์œ„ํ•œ api ์ž…๋‹ˆ๋‹ค")
@GetMapping("/my-purchases")
public ApiResponse<List<Product>> readMyPurchases(@RequestParam Long userId) {
return ApiResponse.onSuccess(PurchasesService.getMyProducts(userId));
public ApiResponse<List<Product>> readMyPurchases(HttpServletRequest request, HttpServletResponse response) {
Users user = usersService.getUserIdByToken(request, response);
return ApiResponse.onSuccess(PurchasesService.getMyProducts(user.getId()));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.finut.finut_server.controller;

import com.finut.finut_server.apiPayload.ApiResponse;
import com.finut.finut_server.apiPayload.code.ErrorReasonDTO;
import com.finut.finut_server.config.auth.dto.SessionUser;
import com.finut.finut_server.domain.user.UserResponseDTO;
import com.finut.finut_server.service.UsersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -34,6 +38,15 @@ public HomeController(HttpSession httpSession) {
@Autowired
private UsersService userService;

@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = UserResponseDTO.loginUserDTO.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@Operation(summary = "๋กœ๊ทธ์ธ ์„ฑ๊ณต", description = "๋กœ๊ทธ์ธ ์„ฑ๊ณต์‹œ ํ•ด๋‹น api์— ๋ฆฌ๋‹ค์ด๋ ‰์…˜ ๋˜์–ด ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค")
@GetMapping("/success")
@ResponseBody
Expand Down

This file was deleted.

101 changes: 101 additions & 0 deletions src/main/java/com/finut/finut_server/controller/QuestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.finut.finut_server.controller;

import com.finut.finut_server.apiPayload.ApiResponse;
import com.finut.finut_server.apiPayload.code.ErrorReasonDTO;
import com.finut.finut_server.domain.quest.Quest;
import com.finut.finut_server.domain.quest.QuestDTO;
import com.finut.finut_server.domain.questDone.QuestDone;
import com.finut.finut_server.domain.questQuiz.QuestQuiz;
import com.finut.finut_server.domain.questQuiz.QuestQuizRepository;
import com.finut.finut_server.domain.quiz.Quiz;
import com.finut.finut_server.domain.user.Users;
import com.finut.finut_server.domain.user.UsersRepository;
import com.finut.finut_server.service.LevelService;
import com.finut.finut_server.service.QuestQuizService;
import com.finut.finut_server.service.QuestService;
import com.finut.finut_server.service.UsersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/quest")
@Tag(name = "Quest Controller", description = "ํ€˜์ŠคํŠธ ๊ด€๋ จ api")
public class QuestController {
@Autowired
private UsersService usersService;

@Autowired
private QuestQuizService questQuizService;

@Autowired
private QuestService questService;

@Autowired
private LevelService levelService;

@Operation(summary = "์ „์ฒด ํ€˜์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ", description = "์ „์ฒด ํ€˜์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Quest.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "ํ€˜์ŠคํŠธ ๋‚ด์šฉ์„ ์ œ๋Œ€๋กœ ๊ฐ€์ง€๊ณ  ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@GetMapping("")
public ApiResponse<List<QuestDTO>> getQuests(){
List<QuestDTO> quests = questService.getAllQuests();
return ApiResponse.onSuccess(quests);
}


@Operation(summary = "ํ•ด๋‹น ํ€˜์ŠคํŠธ ํ€ด์ฆˆ๋“ค ๊ฐ€์ ธ์˜ค๊ธฐ", description = "ํ•ด๋‹น ํ€˜์ŠคํŠธ์˜ ํ€ด์ฆˆ์„ ๋ชจ๋‘ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = QuestQuiz.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "ํ€˜์ŠคํŠธ ํ€ด์ฆˆ ๋‚ด์šฉ์„ ์ œ๋Œ€๋กœ ๊ฐ€์ง€๊ณ ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@GetMapping("/{questId}")
public ApiResponse<List<QuestQuiz>> getQuestQuizes(@PathVariable Long questId){
List<QuestQuiz> questQuizzes = questQuizService.getQuestQuizzes(questId);
return ApiResponse.onSuccess(questQuizzes);
}



@Operation(summary = "ํ€˜์ŠคํŠธ ์„ฑ๊ณต", description = "ํ€˜์ŠคํŠธ ์„ฑ๊ณต์‹œ Level์„ ๋‹ค์Œ ๋ ˆ๋ฒจ์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = QuestDone.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ, ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ ๋ฐ”๋ž๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@GetMapping("/done-quest/{questId}")
public ApiResponse<Users> updateQuestDone(@PathVariable Long questId, HttpServletRequest request, HttpServletResponse response) {
Users user = usersService.getUserIdByToken(request, response);
questService.updateQuestDone(user, questId);
user = levelService.upgradeUserLevel(user.getId());
return ApiResponse.onSuccess(user);
}


}
Loading

0 comments on commit 1a53ca9

Please sign in to comment.