-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
730 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/net/skhu/likelion12thteam03be/category/api/CategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/net/skhu/likelion12thteam03be/category/api/dto/request/CategorySaveReqDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
...ain/java/net/skhu/likelion12thteam03be/category/api/dto/request/CategoryUpdateReqDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
16 changes: 16 additions & 0 deletions
16
...main/java/net/skhu/likelion12thteam03be/category/api/dto/response/CategoryInfoResDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...main/java/net/skhu/likelion12thteam03be/category/api/dto/response/CategoryListResDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/net/skhu/likelion12thteam03be/category/application/CategoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/net/skhu/likelion12thteam03be/category/domain/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ain/java/net/skhu/likelion12thteam03be/category/domain/repository/CategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
src/main/java/net/skhu/likelion12thteam03be/config/S3Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
*/ |
Oops, something went wrong.