-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Week10' into LINE-SMS-메시징-API-구현
- Loading branch information
Showing
34 changed files
with
1,036 additions
and
50 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,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 |
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
61 changes: 61 additions & 0 deletions
61
src/main/java/dbdr/controller/AdminGuardiansController.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 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(); | ||
} | ||
} |
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,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(); | ||
} | ||
} |
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 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); | ||
} | ||
} |
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,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(); | ||
} | ||
} |
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,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; | ||
} | ||
} |
Oops, something went wrong.