Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 57 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Post_CI/CI

on:
push:
branches:
- kkb
jobs:
cicd-deploy:
runs-on: ubuntu-latest
steps:
- name: Github Repository내 파일들 checkout(불러오기) 수행
uses: actions/checkout@v4

# JDK 17 버전 설치
- name: JDK 17 버전 설치
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: application.properties 동적 생성
run : |
echo "${{secrets.APPLICATION_PRO }}" > ./src/main/resources/application.properties

- name: 단위 테스트 및 빌드
run: |
chmod +x ./gradlew
./gradlew clean build
- name: 관리상 빌드된 결과물의 이름을 변경 처리
run: |
mv ./build/libs/*SNAPSHOT.jar ./run.jar
ls

- name: EC2에 jar파일 업로드
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
source: run.jar
target: /home/ubuntu/server/demo

- name : SSH로 EC2에 접속후 서버가동
uses: appleboy/ssh-action@v1.2.0

with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
script_stop: true
script: |
rm -rf /home/ubuntu/server/web
mkdir /home/ubuntu/server/web
mv /home/ubuntu/server/demo/run.jar /home/ubuntu/server/web/run.jar
cd /home/ubuntu/server/web
sudo fuser -k -n tcp 8080 || true
nohup java -jar run.jar > ./output.log 2>&1 &
rm -rf /home/ubuntu/server/demo
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
application.properties

### STS ###
.apt_generated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.example.minipro2_post.dto.CommentDto;
import com.example.minipro2_post.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

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

/**
Expand Down Expand Up @@ -55,8 +57,20 @@ public ResponseEntity<String> createComment(
.bodyToMono(Long.class);
Long uid = webClient.block(); // 동기 처리

// List<Long> gid = new ArrayList<>();
// GID 확인
Mono<List<Long>> webClient_2 = webClientBuilder.baseUrl("http://localhost:8083").build()
.get()
.uri(uriBuilder -> uriBuilder.path("/user/groupCheck")
.queryParam("email", email).build())
.retrieve()
.bodyToMono(new ParameterizedTypeReference<List<Object>>() {}) // List<Object>로 먼저 받아서
.map(list -> list.stream()
.map(obj -> ((Number) obj).longValue()) // Object → Number → Long 변환
.toList());

commentService.addComment(commentDto, pid,uid);
List<Long> gid = webClient_2.block();
commentService.addComment(commentDto, pid,uid,gid);
return ResponseEntity.ok("댓글 저장완료");
}
// 댓글 수정 진행
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import com.example.minipro2_post.repository.PostRepository;
import com.example.minipro2_post.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

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

Expand All @@ -27,6 +31,9 @@ public class SearchController {
@Autowired
private PostRepository postRepository;

@Autowired
private WebClient.Builder webClientBuilder;


// 메인 페이지 테스트
@GetMapping
Expand Down Expand Up @@ -55,6 +62,36 @@ public ResponseEntity<?> search(@RequestBody HashMap<String, Object> map) {

List<PostDto> postDtoList = null;

// Mono<List> webClient = webClientBuilder.baseUrl("http://localhost:8083").build()
// .get()
// .uri(uriBuilder -> uriBuilder.path("/user/checkemail")
// .queryParam("email",email).build())
// .retrieve()
// .bodyToMono(List.class);
// List<Long> result = webClient.block();

// System.out.println(result);

// Mono<List> webClient = webClientBuilder.baseUrl("http://localhost:8083").build()
// .get()
// .uri(uriBuilder -> uriBuilder.path("/user/checkemail")
// .queryParam("email",email).build())
// .retrieve()
// .bodyToMono(List.class);
// List<Long> result = webClient.block();

// System.out.println(result);

// Mono<List> webClient = webClientBuilder.baseUrl("http://localhost:8083").build()
// .get()
// .uri(uriBuilder -> uriBuilder.path("/user/checkemail")
// .queryParam("email",email).build())
// .retrieve()
// .bodyToMono(List.class);
// List<Long> result = webClient.block();

// System.out.println(result);

try {
if("tag".equals(type)) {
postDtoList = searchService.searchByTag(searchString);
Expand All @@ -67,6 +104,15 @@ public ResponseEntity<?> search(@RequestBody HashMap<String, Object> map) {
} catch (Exception e) {
return ResponseEntity.ok("해당 이메일을 가진 사용자가 없습니다.");
}
List<Long> postIds = new ArrayList<>();
for (PostEntity postEntity1 : postEntity) {
if (!postEntity1.getGid().equals(0)) {
postIds.add(postEntity1.getGid());
}
}
for (int i = postIds.size() - 1; i >= 0; i--) {
postEntity.remove(postIds.get(i));
}

if (postDtoList == null || postDtoList.isEmpty()) {
return ResponseEntity.ok("검색 결과가 없습니다");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public interface CommentRepository extends JpaRepository<CommentEntity, Long> {
List<CommentEntity> findByPid(PostEntity post);

List<CommentEntity> findByUid(PostEntity post);

// 특정 사용자가 작성한 모든 댓글 삭제
@Modifying
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface PostRepository extends JpaRepository<PostEntity, Long> {

List<PostEntity> findByUid(Long uid);


// uid로 게시글 삭제
@Modifying
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ public class CommentService {
private CommentEventPublisher commentEventPublisher;

// 댓글 추가
public void addComment(CommentDto commentDto, Long pid, Long uid) {
public void addComment(CommentDto commentDto, Long pid, Long uid, List<Long> gids) {
Optional<PostEntity> postEntity = postRepository.findById(pid);

if (postEntity.isPresent()) {
Boolean gidCheck = false;
// public 확인
if (postEntity.get().getGid() ==0L) gidCheck = true;

for (Long gid:gids) {
if (gid == postEntity.get().getGid()) gidCheck = true;
}
System.out.println(postEntity.isPresent()+" / "+postEntity.get().getGid() +" / "+gids);
if (postEntity.isPresent() && gidCheck ) {
CommentEntity commentEntity = CommentEntity.builder()
.pid(postEntity.get())
.uid(commentDto.getUid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ else if(!postDto.getType().equals("public")
&&!postDto.getType().equals("groupOnly")) {
throw new RuntimeException("게시글 타입이 옳지 않거나 공백입니다.");
}

PostEntity postEntity = PostEntity.builder()
.uid(result)
.type(postDto.getType())
.gid(postDto.getGid() != null ? postDto.getGid() : 0L)
.gid(postDto.getType().equals("public") ? 0L : postDto.getGid())
.date(postDto.getDate() != null ? postDto.getDate() : LocalDateTime.now())
.content(postDto.getContent())
.youLike(postDto.getLike() != null ? postDto.getLike() : 0L)
Expand Down
Empty file added src/main/resources/1
Empty file.
38 changes: 0 additions & 38 deletions src/main/resources/application.properties

This file was deleted.

Loading