Skip to content

Commit

Permalink
Merge branch 'Week10' into LINE-SMS-메시징-API-구현
Browse files Browse the repository at this point in the history
  • Loading branch information
pykido authored Nov 14, 2024
2 parents 54eabed + 185665f commit 1775146
Show file tree
Hide file tree
Showing 34 changed files with 1,036 additions and 50 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Java CI and Deploy to AWS EC2

on:
push:
branches: [ "Week10" ]
pull_request:
branches: [ "Week10" ]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

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

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582

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

deploy:
runs-on: ubuntu-latest
needs: build
environment: production
permissions:
contents: read

steps:
- uses: actions/checkout@v4

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

- name: Decode and save .pem file
env:
EC2_SSH_KEY_BASE64: ${{ secrets.EC2_SSH_KEY_BASE64 }}
run: |
echo "$EC2_SSH_KEY_BASE64" | base64 -d > ec2-key.pem
chmod 600 ec2-key.pem
- name: Upload JAR to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
run: |
scp -i ec2-key.pem -o StrictHostKeyChecking=no ./build/libs/your-app.jar $EC2_USER@$EC2_HOST:~/app/your-app.jar
- name: Restart Application on EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
run: |
ssh -i ec2-key.pem -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << 'EOF'
# 현재 실행 중인 Java 프로세스 종료
echo "현재 실행 중인 Java 프로세스 종료 중..."
pkill -f 'java' || echo "종료할 Java 프로세스 없음"
# 새로운 애플리케이션 실행
JAR_FILE="dbdr-0.0.1-SNAPSHOT.jar"
echo "새로운 애플리케이션을 실행합니다: $JAR_FILE"
nohup java -jar ~/app/$JAR_FILE --server.port=8080 > ~/app/app.log 2>&1 &
# 실행 확인
sleep 10
echo "새로 실행된 Java 프로세스:"
pgrep -f 'java'
EOF
43 changes: 2 additions & 41 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ dependencies {
// 데이터베이스
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.33' // MySQL 의존성 추가 (MySQL JDBC 드라이버)
runtimeOnly 'com.h2database:h2'

// 보안
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
//implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
//implementation 'org.springframework.boot:spring-boot-starter-security'

// JWT 라이브러리 추가
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
Expand All @@ -46,49 +45,11 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// SpringDoc OpenAPI (Swagger UI 포함)
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'

// 테스트 라이브러리
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'com.h2database:h2' // H2는 테스트 환경에서 주로 사용

// Line-messaging-api 라이브러리
implementation 'com.linecorp.bot:line-bot-spring-boot:4.7.0'


// MapStruct
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'

//POI
implementation 'org.apache.poi:poi-ooxml:5.3.0'
implementation 'org.apache.commons:commons-compress:1.27.1'

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// Amazon SQS
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.1")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sqs'

// CoolSMS
implementation 'net.nurigo:sdk:4.3.0'

// AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// Naver Clova OCR API
implementation 'org.springframework.boot:spring-boot-starter-webflux' // WebClient 사용을 위한 라이브러리

// Health check
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(JavaCompile) {
options.compilerArgs += ['-parameters']
}
61 changes: 61 additions & 0 deletions src/main/java/dbdr/controller/AdminGuardiansController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package dbdr.controller;

import dbdr.dto.request.GuardiansRequest;
import dbdr.dto.response.GuardiansResponse;
import dbdr.service.GuardiansService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/admin/guardians")
@RequiredArgsConstructor
public class AdminGuardiansController {

private final GuardiansService guardiansService;

@GetMapping
public ResponseEntity<List<GuardiansResponse>> showAllGuardians() {
List<GuardiansResponse> guardiansResponseList = guardiansService.getAllGuardians();
return ResponseEntity.ok(guardiansResponseList);
}

@GetMapping("/{guardianId}")
public ResponseEntity<GuardiansResponse> showOneGuardian(
@PathVariable("guardianId") Long guardianId) {
GuardiansResponse guardiansResponse = guardiansService.getGuardianById(guardianId);
return ResponseEntity.ok(guardiansResponse);
}

@PostMapping
public ResponseEntity<GuardiansResponse> addGuardian(
@Valid @RequestBody GuardiansRequest guardiansRequest) {
GuardiansResponse guardiansResponse = guardiansService.addGuardian(guardiansRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(guardiansResponse);
}

@PutMapping("/{guardianId}/update")
public ResponseEntity<GuardiansResponse> updateGuardianAuth(
@PathVariable("guardianId") Long guardianId,
@Valid @RequestBody GuardiansRequest guardiansRequest) {
GuardiansResponse guardiansResponse = guardiansService.updateGuardianById(guardianId,
guardiansRequest);
return ResponseEntity.ok(guardiansResponse);
}

@PutMapping("/{guardianId}/delete")
public ResponseEntity<Void> deleteGuardianAuth(
@PathVariable("guardianId") Long guardianId) {
guardiansService.deleteGuardianById(guardianId);
return ResponseEntity.noContent().build();
}
}
59 changes: 59 additions & 0 deletions src/main/java/dbdr/controller/CareworkerController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dbdr.controller;

import dbdr.dto.request.CareworkerRequestDTO;
import dbdr.dto.response.CareworkerResponseDTO;
import dbdr.service.CareworkerService;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/v1/careworkers")
public class CareworkerController {

private final CareworkerService careworkerService;

public CareworkerController(CareworkerService careworkerService) {
this.careworkerService = careworkerService;
}

@GetMapping
public ResponseEntity<List<CareworkerResponseDTO>> getAllCareworkers(
@RequestParam(value = "institutionId", required = false) Long institutionId) {
List<CareworkerResponseDTO> careworkers;
if (institutionId != null) {
careworkers = careworkerService.getCareworkersByInstitution(institutionId);
} else {
careworkers = careworkerService.getAllCareworkers();
}
return ResponseEntity.ok(careworkers);
}

@GetMapping("/{id}")
public ResponseEntity<CareworkerResponseDTO> getCareworkerById(@PathVariable Long id) {
CareworkerResponseDTO careworker = careworkerService.getCareworkerById(id);
return ResponseEntity.ok(careworker);
}

@PostMapping
public ResponseEntity<CareworkerResponseDTO> createCareworker(@Valid @RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO newCareworker = careworkerService.createCareworker(careworkerDTO);
return ResponseEntity.created(URI.create("/v1/careworkers/" + newCareworker.getId()))
.body(newCareworker);
}

@PutMapping("/{id}")
public ResponseEntity<CareworkerResponseDTO> updateCareworker(@PathVariable Long id, @Valid @RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO updatedCareworker = careworkerService.updateCareworker(id, careworkerDTO);
return ResponseEntity.ok(updatedCareworker);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteCareworker(@PathVariable Long id) {
careworkerService.deleteCareworker(id);
return ResponseEntity.noContent().build();
}
}
38 changes: 38 additions & 0 deletions src/main/java/dbdr/controller/GuardiansController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dbdr.controller;

import dbdr.dto.request.GuardiansRequest;
import dbdr.dto.response.GuardiansResponse;
import dbdr.service.GuardiansService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/guardians")
@RequiredArgsConstructor
public class GuardiansController {

private final GuardiansService guardiansService;

@GetMapping("/{guardianId}")
public ResponseEntity<GuardiansResponse> showGuardianInfo(
@PathVariable("guardianId") Long guardianId) {
GuardiansResponse guardiansResponse = guardiansService.getGuardianById(guardianId);
return ResponseEntity.ok(guardiansResponse);
}

@PutMapping("/{guardianId}")
public ResponseEntity<GuardiansResponse> updateGuardianInfo(
@PathVariable("guardianId") Long guardianId,
@Valid @RequestBody GuardiansRequest guardiansRequest) {
GuardiansResponse guardiansResponse = guardiansService.updateGuardianById(guardianId,
guardiansRequest);
return ResponseEntity.ok(guardiansResponse);
}
}
53 changes: 53 additions & 0 deletions src/main/java/dbdr/controller/RecipientController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dbdr.controller;

import dbdr.dto.request.RecipientRequestDTO;
import dbdr.dto.response.RecipientResponseDTO;
import dbdr.service.RecipientService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/v1/recipients")
public class RecipientController {

private final RecipientService recipientService;

public RecipientController(RecipientService recipientService) {
this.recipientService = recipientService;
}

@GetMapping
public ResponseEntity<List<RecipientResponseDTO>> getAllRecipients() {
List<RecipientResponseDTO> recipients = recipientService.getAllRecipients();
return ResponseEntity.ok(recipients);
}

@GetMapping("/{id}")
public ResponseEntity<RecipientResponseDTO> getRecipientById(@PathVariable Long id) {
RecipientResponseDTO recipient = recipientService.getRecipientById(id);
return ResponseEntity.ok(recipient);
}

@PostMapping
public ResponseEntity<RecipientResponseDTO> createRecipient(@Valid @RequestBody RecipientRequestDTO recipientDTO) {
RecipientResponseDTO newRecipient = recipientService.createRecipient(recipientDTO);
return ResponseEntity.created(URI.create("/v1/recipients/" + newRecipient.getId()))
.body(newRecipient);
}

@PutMapping("/{id}")
public ResponseEntity<RecipientResponseDTO> updateRecipient(@PathVariable Long id, @RequestBody RecipientRequestDTO recipientDTO) {
RecipientResponseDTO updatedRecipient = recipientService.updateRecipient(id, recipientDTO);
return ResponseEntity.ok(updatedRecipient);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteRecipient(@PathVariable Long id) {
recipientService.deleteRecipient(id);
return ResponseEntity.noContent().build();
}
}
40 changes: 40 additions & 0 deletions src/main/java/dbdr/domain/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dbdr.domain;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import lombok.Getter;
import org.hibernate.annotations.ColumnDefault;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(updatable = false, nullable = false)
@CreatedDate
private LocalDateTime createdAt;

@Column(nullable = true)
@LastModifiedDate
private LocalDateTime updateAt;

@Column(nullable = false)
@ColumnDefault("true")
private boolean isActive = true;

public void deactivate() {
this.isActive = false;
}
}
Loading

0 comments on commit 1775146

Please sign in to comment.