Skip to content

Commit

Permalink
[Refactor] Refactor 진행중 - Comment DB에 user 데이터 추가해야함.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sniij committed Jun 2, 2024
1 parent 93f3d4b commit a26f2a6
Show file tree
Hide file tree
Showing 44 changed files with 360 additions and 222 deletions.
125 changes: 63 additions & 62 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
name: Java CI with Gradle

on:
push:
branches: [ "123" ]

permissions:
contents: read

env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: dowajoyak.store
CODE_DEPLOY_APPLICATION_NAME: dowajoyak-CodeDeploy
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: dowajoyak-CodeDeploy-group

jobs:
build:
runs-on: ubuntu-latest
env:
working-directory: ./server

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Add permission
run: chmod +x gradlew
working-directory: ${{ env.working-directory }}

- name: Build with Gradle
run: ./gradlew clean build
working-directory: ${{ env.working-directory }}


# build한 후 프로젝트를 압축합니다.
- name: Make zip file
run: zip -r ./seb-main-project-009.zip .
shell: bash

# Access Key와 Secret Access Key를 통해 권한을 확인합니다.
# 아래 코드에 Access Key와 Secret Key를 직접 작성하지 않습니다.
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} # 등록한 Github Secret이 자동으로 불려옵니다.
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # 등록한 Github Secret이 자동으로 불려옵니다.
aws-region: ap-northeast-2

# 압축한 프로젝트를 S3로 전송합니다.
- name: Upload to AWS S3
run: aws s3 cp --region ap-northeast-2 ./seb-main-project-009.zip s3://$S3_BUCKET_NAME/seb-main-project-009.zip
# CodeDeploy에게 배포 명령을 내립니다.
- name: Code Deploy
run: >
aws deploy create-deployment --application-name $CODE_DEPLOY_APPLICATION_NAME
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name $CODE_DEPLOY_DEPLOYMENT_GROUP_NAME
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=seb-main-project-009.zip
#
#name: Java CI with Gradle
#
#on:
# push:
# branches: [ "123" ]
#
#permissions:
# contents: read
#
#env:
# AWS_REGION: ap-northeast-2
# S3_BUCKET_NAME: dowajoyak.store
# CODE_DEPLOY_APPLICATION_NAME: dowajoyak-CodeDeploy
# CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: dowajoyak-CodeDeploy-group
#
#jobs:
# build:
# runs-on: ubuntu-latest
# env:
# working-directory: ./server
#
# steps:
# - uses: actions/checkout@v3
# - name: Set up JDK 11
# uses: actions/setup-java@v3
# with:
# java-version: '11'
# distribution: 'temurin'
#
# - name: Add permission
# run: chmod +x gradlew
# working-directory: ${{ env.working-directory }}
#
# - name: Build with Gradle
# run: ./gradlew clean build
# working-directory: ${{ env.working-directory }}
#
#
# # build한 후 프로젝트를 압축합니다.
# - name: Make zip file
# run: zip -r ./seb-main-project-009.zip .
# shell: bash
#
# # Access Key와 Secret Access Key를 통해 권한을 확인합니다.
# # 아래 코드에 Access Key와 Secret Key를 직접 작성하지 않습니다.
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} # 등록한 Github Secret이 자동으로 불려옵니다.
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # 등록한 Github Secret이 자동으로 불려옵니다.
# aws-region: ap-northeast-2
#
# # 압축한 프로젝트를 S3로 전송합니다.
# - name: Upload to AWS S3
# run: aws s3 cp --region ap-northeast-2 ./seb-main-project-009.zip s3://$S3_BUCKET_NAME/seb-main-project-009.zip
# # CodeDeploy에게 배포 명령을 내립니다.
# - name: Code Deploy
# run: >
# aws deploy create-deployment --application-name $CODE_DEPLOY_APPLICATION_NAME
# --deployment-config-name CodeDeployDefault.AllAtOnce
# --deployment-group-name $CODE_DEPLOY_DEPLOYMENT_GROUP_NAME
# --s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=seb-main-project-009.zip
17 changes: 9 additions & 8 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

group = 'com.codestates'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
sourceCompatibility = '17'

bootJar{
// jar file name 변경
Expand Down Expand Up @@ -35,29 +35,25 @@ dependencies {

// AWS paramStore 사용 Spring boot 버전 호환 상세 : https://spring.io/projects/spring-cloud

implementation "org.springframework.cloud:spring-cloud-starter-aws-parameter-store-config:2.2.6.RELEASE"
implementation "io.awspring.cloud:spring-cloud-starter-aws-parameter-store-config:2.3.0"
//implementation "org.springframework.cloud:spring-cloud-starter-aws-parameter-store-config:2.2.6.RELEASE"
//implementation "io.awspring.cloud:spring-cloud-starter-aws-parameter-store-config:2.3.0"
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'


implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
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'
runtimeOnly 'mysql:mysql-connector-java:8.0.28'


implementation 'org.mapstruct:mapstruct:1.5.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final'

//security
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'com.google.code.gson:gson'
implementation 'org.springframework.boot:spring-boot-starter-mail'

// JWT 기능을 위한 jjwt 라이브러리
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
Expand All @@ -71,6 +67,11 @@ dependencies {

implementation 'org.json:json:20230227'


implementation 'org.mongodb:mongodb-driver-core'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

implementation 'com.amazonaws.serverless:aws-serverless-java-container-springboot2:1.9.4'
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

@SpringBootApplication
@EnableMongoRepositories
public class SebMainProject009Application {

public static void main(String[] args) {



SpringApplication.run(SebMainProject009Application.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import io.jsonwebtoken.Jws;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.codestates.sebmainproject009.auth.jwt.JwtTokenizer;
import com.codestates.sebmainproject009.auth.utils.CustomAuthorityUtils;
import com.codestates.sebmainproject009.user.service.UserService;
import com.codestates.sebmainproject009.user.entity.User;
import com.codestates.sebmainproject009.user.service.UserService;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ public String extractTokenFromHeader(String authorizationHeader){
return null;
}

public Long extractUserIdFromToken(String requestToken){
public String extractUserIdFromToken(String requestToken){
if(requestToken!=null) {
Jws<Claims> claims =
getClaims(requestToken, encodeBase64SecretKey(secretKey));
String userIdString = claims.getBody().get("userId").toString();

if(userIdString!=null){
try{
return Long.parseLong(userIdString);
return userIdString;
} catch (NumberFormatException e){
throw new IllegalArgumentException(e.getMessage());
}
Expand Down Expand Up @@ -177,9 +177,9 @@ public String getToken(String authorizationHeader) {
return token;
}

public Long getUserId(String token) {
public String getUserId(String token) {

Long userId;
String userId;

if (token != null) {
userId = extractUserIdFromToken(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import com.codestates.sebmainproject009.user.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@Getter
@Setter
public class CommentPostDto {
private Long userId;
private Long commuId;
private String userId;
private String commuId;
@NotBlank
private String comment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Getter
@Setter
public class CommentResponseDto {
private Long commentId;
private String commentId;
private String comment;
private String displayName;
private LocalDateTime createAt = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,34 @@

import com.codestates.sebmainproject009.commu.entity.Commu;
import com.codestates.sebmainproject009.user.entity.User;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

@Entity
@Document("comment")
@Getter
@Setter
public class Comment {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long commentId;
private String objectId;

private String commentId;

@Column
private String comment;

@Column
private String displayName;

@Column
private LocalDateTime createAt = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();

@ManyToOne
@JoinColumn(name = "commuId")
@JsonIgnore
private Commu commu;

@ManyToOne
@JsonIgnore
@JoinColumn(name = "userId")
private String commuId;

private User user;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.codestates.sebmainproject009.comment.dto.CommentPostDto;
import com.codestates.sebmainproject009.comment.dto.CommentResponseDto;
import com.codestates.sebmainproject009.comment.entity.Comment;
import com.codestates.sebmainproject009.commu.dto.CommuResponsesDto;
import com.codestates.sebmainproject009.commu.entity.Commu;
import org.mapstruct.Mapper;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.codestates.sebmainproject009.comment.repository;

import com.codestates.sebmainproject009.comment.entity.Comment;


public interface CommentCustomRepository {
Comment findByCommentId(String id);

void deleteByCommentId(String id);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.codestates.sebmainproject009.comment.repository;

import com.codestates.sebmainproject009.comment.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {
public interface CommentRepository extends MongoRepository<Comment, String>, CommentCustomRepository{
}
Loading

0 comments on commit a26f2a6

Please sign in to comment.