Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
edbbebe
⚒️refactoring : 폴더구조 변경
hwangjiyoung02 May 6, 2025
43ac8ea
✨feat : 마이페이지 조회, 수정
hwangjiyoung02 May 6, 2025
57f1292
✨feat : 마이페이지 조회, 수정
hwangjiyoung02 May 6, 2025
7d2914b
✨feat : logging aop추가
hwangjiyoung02 May 6, 2025
d86e05e
⚒️refactoring : 패키지 구조 변경
hwangjiyoung02 May 6, 2025
ae707ce
⚒️refactoring : 코드 간소화
hwangjiyoung02 May 6, 2025
9512d1a
⚒️refactoring : System.out.print 삭제, 안쓰는 코드 제거,타입 변경
hwangjiyoung02 May 6, 2025
4e4507f
🔥fix : update 오류 수정
hwangjiyoung02 May 6, 2025
5282fa0
🔥fix : mypage response 생성
hwangjiyoung02 May 6, 2025
cae468c
🔥fix : 로그아웃시 쿠키의 userId도 삭제
hwangjiyoung02 May 6, 2025
2d48a2b
⚒️rectoring : userId 예외처리 제거
hwangjiyoung02 May 6, 2025
9c2d706
🚀cicd : Dockerfile,docker-compose.yml수정, cicd yml생성
hwangjiyoung02 May 12, 2025
dfdf5c1
🚀cicd : Dockerfile,docker-compose.yml수정, cicd yml생성(2)
hwangjiyoung02 May 12, 2025
3aa2360
🚀cicd : Dockerfile,docker-compose.yml수정, cicd yml생성(3)
hwangjiyoung02 May 12, 2025
5c1db3b
🚀cicd : Dockerfile,docker-compose.yml수정, cicd yml생성(3)
hwangjiyoung02 May 12, 2025
564e00d
🚀cicd : Dockerfile,docker-compose.yml수정, cicd yml생성(4)
hwangjiyoung02 May 12, 2025
e694b13
🔥cicd : docker-compose 수정
hwangjiyoung02 May 12, 2025
a90c640
🔥cicd : docker hub에 이미지 push, pull로 변경
hwangjiyoung02 May 17, 2025
2bd4154
merge전 병합
hwangjiyoung02 May 17, 2025
ac5f951
🔥 fix: 충돌 오류 해결
hwangjiyoung02 May 17, 2025
0724d9f
Merge branch 'develop' into 황지영/deploy
hwangjiyoung02 May 17, 2025
e2d4072
🔥 fix: cd-dev.yml 코드 오류
hwangjiyoung02 May 17, 2025
9782c3c
Merge branch '황지영/deploy' of https://github.com/hwangjiyoung02/Blog-B…
hwangjiyoung02 May 17, 2025
fac993d
🔥 fix: cd-dev.yml 코드 오류
hwangjiyoung02 May 17, 2025
0878ee5
🔥 fix: cd-dev.yml 코드 오류
hwangjiyoung02 May 17, 2025
f179097
🔥 fix: 자바 버전 변경
hwangjiyoung02 May 17, 2025
f3efb1e
🔥 fix: docker-compose 실행로직 추가
hwangjiyoung02 May 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: leets-blog CD 파이프라인

on:
workflow_run:
workflows: ["leets-blog dev CI 파이프라인"]
types:
- completed

jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'develop' }}
runs-on: ubuntu-22.04

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

- name: 2. .env 생성
run: echo "${{ secrets.ENV }}" > .env

- name: 3. .env 파일 EC2에 전송
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: ".env"
target: "/home/ubuntu/app/docker/"

- name: 4. docker-compose.yml EC2에 전송
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: "./docker/docker-compose.yml"
target: "/home/ubuntu/app/docker/"

- name: 5. Docker Compose 실행
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
cd /home/ubuntu/app/docker/
sudo docker stop leets-blog-app || true
sudo docker rm leets-blog-app || true
sudo docker pull ${{secrets.DOCKER_USERNAME}}/leets-server:latest
sudo docker compose up -d
66 changes: 66 additions & 0 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: leets-blog dev CI 파이프라인

on:
push:
branches: [ "develop" ]

jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: write
checks: write
pull-requests: write

steps:
# 1. GitHub 레포지토리 Checkout
- name: Checkout Repository
uses: actions/checkout@v4

# 2. JDK 17 설치
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# 3. application.properties 생성
- name: application.properties 설정
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.properties

# 4. Gradle Wrapper 실행 권한 부여
- name: Gradle Wrapper 권한 부여
run: chmod +x gradlew

# 4-1. Gradle 캐싱 설정
- name: Gradle 캐싱
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}

# 5. Gradle 빌드
- name: Gradle 빌드
run: ./gradlew clean build

# 6. DockerHub 로그인
- name: DockerHub 로그인
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}

# 7. Docker 이미지 Build & Push
- name: Docker 이미지 Build & Push
uses: docker/build-push-action@v5
with:
context: .
dockerfile: Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/leets-server:latest
49 changes: 49 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

name: leets-blog 테스트 CI 파이프라인

### develop으로 PR 올릴 때, 테스트 코드를 실행하여, 체크하는 로직을 수행한다.

on:
pull_request:
branches: ["develop"]

jobs:
#1. Test 용
test:
runs-on: ubuntu-22.04
permissions:
contents: write
checks: write
pull-requests: write

steps:
# 1. repository checkout
- uses: actions/checkout@v4

# 2. jdk 환경 설치
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# 2. gradle 환경 설치
- name: Gradle Wrapper 권한 부여
run: chmod +x gradlew

# 4. gradle 환경 설치
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

# 5. 빌드
- name: Build with Gradle Wrapper
run: ./gradlew build -x test


# 6. JUnit 테스트 결과 게시
# - name: Test 결과 출력
# uses: EnricoMi/publish-unit-test-result-action@v2
# if: always()
# with:
# junit_files: '**/build/test-results/test/TEST-*.xml'
# github_token: ${{ secrets.GITHUB_TOKEN }}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 1. JDK 이미지를 베이스로 설정
FROM eclipse-temurin:17-jdk

# 2. 작업 디렉토리 설정
WORKDIR /app

# 3. jar 파일 복사
ARG JAR_FILE=build/libs/blog-0.0.1-SNAPSHOT.jar

COPY ${JAR_FILE} app.jar

# 4. 실행
ENTRYPOINT ["java", "-jar", "app.jar"]
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(17)
}
}

Expand All @@ -34,6 +34,9 @@ dependencies {
// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

//aop
implementation 'org.springframework.boot:spring-boot-starter-aop'
}

tasks.named('test') {
Expand Down
15 changes: 14 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
services:
### 키키하이 도커 이미지
spring:
image: kikihi/leets-server:latest
container_name: leets-blog-app
ports:
- "8080:8080"
depends_on:
- mysql

# mysql 이미지
mysql:
image: mysql:8.0
container_name: leets-blog-mysql
Expand All @@ -10,5 +20,8 @@ services:
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
volumes:
- ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./mysql/init.sql:/docker-entrypoint-initdb.d/01-init.sql
- ./mysql/schema.sql:/docker-entrypoint-initdb.d/02-schema.sql
- ./mysql/valid.sql:/docker-entrypoint-initdb.d/03-valid.sql

command: --default-authentication-plugin=mysql_native_password
2 changes: 0 additions & 2 deletions docker/mysql/data/auto.cnf

This file was deleted.

Empty file removed docker/mysql/data/binlog.index
Empty file.
1 change: 1 addition & 0 deletions docker/sql/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE USER IF NOT EXISTS 'leets'@'%' IDENTIFIED BY 'leets';
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.blog.domain.comment.controller.dto;
package com.blog.domain.comment.controller;


import com.blog.domain.comment.controller.dto.request.CommentRequest;
import com.blog.domain.comment.controller.dto.request.CommentUpdatedRequest;
import com.blog.domain.comment.controller.request.CommentRequest;
import com.blog.domain.comment.controller.request.CommentUpdatedRequest;
import com.blog.domain.comment.service.CommentService;
import com.blog.domain.post.service.PostService;
import com.blog.global.response.ApiResponse;
import com.blog.global.security.aop.GetUserId;
import jakarta.validation.Valid;
Expand All @@ -23,22 +22,22 @@ public CommentController(CommentService commentService) {

// 댓글 등록
@PostMapping
public ApiResponse<String> registerComment(@GetUserId long userId, @Valid @RequestBody CommentRequest request) {
public ApiResponse<String> registerComment(@GetUserId Long userId, @Valid @RequestBody CommentRequest request) {
commentService.registerComment(request, userId);
return ApiResponse.ok("정상적으로 등록되었습니다.");
}

//댓글 수정
@PutMapping("/{commentId}")
public ApiResponse<String> updateComment(@GetUserId long userId, @PathVariable long commentId, @Valid @RequestBody CommentUpdatedRequest request) {
public ApiResponse<String> updateComment(@GetUserId Long userId, @PathVariable long commentId, @Valid @RequestBody CommentUpdatedRequest request) {
commentService.updateComment(userId, commentId, request);
return ApiResponse.ok("정상적으로 수정되었습니다.");

}

//댓글 삭제
@DeleteMapping("/{commentId}")
public ApiResponse<String> deleteComment(@GetUserId long userId, @PathVariable long commentId) {
public ApiResponse<String> deleteComment(@GetUserId Long userId, @PathVariable long commentId) {
commentService.deleteComment(userId, commentId);
return ApiResponse.ok("정상적으로 삭제되었습니다.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.blog.domain.comment.controller.dto.request;
package com.blog.domain.comment.controller.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.blog.domain.comment.controller.dto.request;
package com.blog.domain.comment.controller.request;

import jakarta.validation.constraints.NotBlank;

public record CommentUpdatedRequest(
@NotBlank(message = "댓글 내용은 비어 있을 수 없습니다.")
String content)
{}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.blog.domain.comment.controller.dto.response;
package com.blog.domain.comment.controller.response;

import com.blog.domain.comment.domain.Comment;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/blog/domain/comment/domain/Comment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blog.domain.comment.domain;

import com.blog.domain.comment.controller.dto.request.CommentRequest;
import com.blog.domain.comment.controller.request.CommentRequest;
import com.blog.global.common.BaseDomain;

import java.time.LocalDateTime;
Expand Down
32 changes: 12 additions & 20 deletions src/main/java/com/blog/domain/comment/service/CommentService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.blog.domain.comment.service;

import com.blog.domain.comment.controller.dto.request.CommentRequest;
import com.blog.domain.comment.controller.dto.request.CommentUpdatedRequest;
import com.blog.domain.comment.controller.dto.response.CommentResponse;
import com.blog.domain.comment.controller.request.CommentRequest;
import com.blog.domain.comment.controller.request.CommentUpdatedRequest;
import com.blog.domain.comment.controller.response.CommentResponse;
import com.blog.domain.comment.domain.Comment;
import com.blog.domain.comment.repository.CommentRepository;
import com.blog.domain.post.domain.Post;
import com.blog.domain.post.repository.PostRepository;
import com.blog.domain.user.domain.User;
import com.blog.domain.user.repository.UserRepository;
Expand Down Expand Up @@ -36,39 +35,31 @@ public CommentService(CommentRepository commentRepository, UserRepository userRe
// 댓글 등록
@Transactional
public void registerComment(@Valid CommentRequest request, Long userId) {
Post post = postRepository.findById(request.postId())
postRepository.findById(request.postId())
.orElseThrow(() -> new CustomException(POST_NOT_FOUND));

// 댓글 생성 및 저장
Comment comment = Comment.of(userId, request);
commentRepository.save(comment);

postRepository.incrementCommentCount(request.postId());
System.out.println(post.getCommentCount());
}

// 댓글 수정
@Transactional
public void updateComment(Long userId, Long commentId, CommentUpdatedRequest request) {
Comment comment = getCommentsByCommentId(commentId);
validateCommentOwner(comment, userId);
Comment comment = getAuthorizedComment(userId, commentId);
comment.updateContent(request.content());
commentRepository.update(comment);
}

// 댓글 삭제
@Transactional
public void deleteComment(Long userId, Long commentId) {
Comment comment = getCommentsByCommentId(commentId);
validateCommentOwner(comment, userId);

int count = commentRepository.deleteByCommentId(commentId); // 이름 수정
Long postId = comment.getPostId(); // postId 가져오기

postRepository.decreaseCommentCount(postId, count);
Comment comment = getAuthorizedComment(userId, commentId);
int count = commentRepository.deleteByCommentId(commentId);
postRepository.decreaseCommentCount(comment.getPostId(), count);
}


// 모든 댓글 삭제
@Transactional
public void deleteAllCommentsByPostId(Long postId) {
Expand All @@ -92,12 +83,13 @@ public List<CommentResponse> getAllCommentsByPostId(Long postId) {
.toList();
}

private void validateCommentOwner(Comment comment, Long userId) {
// 댓글 조회 + 권한 검증 메서드 추가
private Comment getAuthorizedComment(Long userId, Long commentId) {
Comment comment = getCommentsByCommentId(commentId);
if (!comment.getUserId().equals(userId)) {
throw new CustomException(ACCESS_DENY);
}
return comment;
}



}
Loading