Skip to content

Commit

Permalink
chore: yml ์ˆ˜์ •
Browse files Browse the repository at this point in the history
  • Loading branch information
shinheekim committed Jul 29, 2024
2 parents c56a42c + d97bc45 commit 6740a35
Show file tree
Hide file tree
Showing 21 changed files with 730 additions and 6 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Java CI/CD with Gradle and AWS CodeDeploy

on:
push:
branches:
- main

permissions:
contents: read

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '17'

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

- name: Grant execute permission for scripts
run: chmod +x ./scripts/*.sh

- name: Build with Gradle
run: ./gradlew clean build -x test

- name: Prepare artifacts for deployment
run: |
mkdir -p before-deploy
cp scripts/*.sh before-deploy/
cp appspec.yml before-deploy/
cp build/libs/*.jar before-deploy/
cd before-deploy && zip -r before-deploy *
cd ../ && mkdir -p deploy
mv before-deploy/before-deploy.zip deploy/reredeployfiles.zip
- name: Deploy to S3 (GitHub Artifacts)
uses: actions/upload-artifact@v4
with:
name: deploy
path: deploy

- name: AWS ์ž๊ฒฉ์ฆ๋ช… ์„ค์ •
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2

- name: S3์— ๋ฐฐํฌ
run: aws s3 cp deploy/reredeployfiles.zip s3://rerebucket/reredeployfiles.zip

- name: AWS CodeDeploy๋ฅผ ์‚ฌ์šฉํ•œ ๋ฐฐํฌ
run: |
aws deploy create-deployment \
--application-name rere-deploy \
--deployment-group-name rere-deploy-group \
--s3-location bucket=rerebucket,key=reredeployfiles.zip,bundleType=zip \
--region ap-northeast-2
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
<<<<<<< HEAD

implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
=======
// jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
//aws
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
>>>>>>> d97bc452c9da72e8ea20b5bb705e571f4bdf856d
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.skhu.likelion12thteam03be.category.api;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategorySaveReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategoryUpdateReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryListResDto;
import net.skhu.likelion12thteam03be.category.application.CategoryService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/categories")
public class CategoryController {

private final CategoryService categoryService;

@PostMapping
public ResponseEntity<String> categorySave(@RequestBody @Valid CategorySaveReqDto categorySaveReqDto) {
categoryService.categorySave(categorySaveReqDto);
return new ResponseEntity<>("Successful Category Save!", HttpStatus.CREATED);
}

@GetMapping()
public ResponseEntity<CategoryListResDto> categoryFindAll() {
CategoryListResDto categoryListResDto = categoryService.categoryFindAll();
return new ResponseEntity<>(categoryListResDto, HttpStatus.OK);
}

@PatchMapping("/{categoryId}")
public ResponseEntity<String> categoryUpdate(@PathVariable Long categoryId, @RequestBody @Valid CategoryUpdateReqDto categoryUpdateReqDto) {
categoryService.categoryUpdate(categoryId, categoryUpdateReqDto);
return new ResponseEntity<>("Successful Category Update! categoryId = " + categoryId, HttpStatus.OK);
}

@DeleteMapping("/{categoryId}")
public ResponseEntity<String> categoryDelete(@PathVariable Long categoryId) {
categoryService.categoryDelete(categoryId);
return new ResponseEntity<>("Successful Category Delete! categoryId = " + categoryId, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.skhu.likelion12thteam03be.category.api.dto.request;

public record CategorySaveReqDto(
String name
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.skhu.likelion12thteam03be.category.api.dto.request;

public record CategoryUpdateReqDto(
String name
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.skhu.likelion12thteam03be.category.api.dto.response;

import lombok.Builder;
import net.skhu.likelion12thteam03be.category.domain.Category;

@Builder
public record CategoryInfoResDto(
Long categoryId,
String name
) {
public static CategoryInfoResDto from(Category category) {
return CategoryInfoResDto.builder()
.name(category.getName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.skhu.likelion12thteam03be.category.api.dto.response;

import lombok.Builder;

import java.util.List;

@Builder
public record CategoryListResDto(
List<CategoryInfoResDto> categoryList
) {
public static CategoryListResDto from(List<CategoryInfoResDto> categoryList) {
return CategoryListResDto.builder()
.categoryList(categoryList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.skhu.likelion12thteam03be.category.application;

import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategorySaveReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategoryUpdateReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryInfoResDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryListResDto;
import net.skhu.likelion12thteam03be.category.domain.Category;
import net.skhu.likelion12thteam03be.category.domain.repository.CategoryRepository;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostInfoResDto;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostListResDto;
import net.skhu.likelion12thteam03be.post.domain.Post;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class CategoryService {
private final CategoryRepository categoryRepository;

@Transactional
public void categorySave(CategorySaveReqDto categorySaveReqDto) {
if (categoryRepository.existsByName(categorySaveReqDto.name())) {
throw new IllegalArgumentException("ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.");
}
Category category = Category.builder()
.name(categorySaveReqDto.name())
.build();

categoryRepository.save(category);
}

public CategoryListResDto categoryFindAll() {
List<Category> categories = categoryRepository.findAll();

List<CategoryInfoResDto> categoryInfoResDtoList = categories.stream()
.map(CategoryInfoResDto::from)
.toList();

return CategoryListResDto.from(categoryInfoResDtoList);
}

@Transactional
public void categoryUpdate(Long categoryId, CategoryUpdateReqDto categoryUpdateReqDto) {
Category category = categoryRepository.findById(categoryId).orElseThrow(
() -> new IllegalArgumentException("ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
);
category.update(categoryUpdateReqDto.name());
}

@Transactional
public void categoryDelete(Long categoryId) {
Category category = categoryRepository.findById(categoryId).orElseThrow(
() -> new IllegalArgumentException("ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
);
categoryRepository.deleteById(categoryId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.skhu.likelion12thteam03be.category.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.likelion12thteam03be.post.domain.Post;

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

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Category {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "category_id")
private Long categoryId;

private String name;

@JsonIgnore
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Post> postList = new ArrayList<>();

@Builder
public Category(String name) {
this.name = name;
}

public void update(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.skhu.likelion12thteam03be.category.domain.repository;

import net.skhu.likelion12thteam03be.category.domain.Category;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CategoryRepository extends JpaRepository<Category, Long> {
boolean existsByName(String name);
}
39 changes: 39 additions & 0 deletions src/main/java/net/skhu/likelion12thteam03be/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
package net.skhu.likelion12thteam03be.config;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class S3Config {
@Value("${cloud.aws.credentials.access-key}")
private String accessKey;
@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;
@Value("${cloud.aws.region.static}")
private String region;
// AmazonS3 ํด๋ผ์ด์–ธํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” Bean์„ ์ •์˜
@Bean
public AmazonS3 s3Builder() {
// AWS ์ž๊ฒฉ ์ฆ๋ช… ์ƒ์„ฑ
AWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
// AmazonS3 ํด๋ผ์ด์–ธํŠธ ์ƒ์„ฑ, ์ž๊ฒฉ ์ฆ๋ช… ๋ฐ region ์„ค์ •
return AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.withRegion(region)
.build();
}
}
*/
Loading

0 comments on commit 6740a35

Please sign in to comment.