-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from KUSITMS-DEVOCEAN/feature/getProject
getProject Api 구현
- Loading branch information
Showing
16 changed files
with
325 additions
and
6 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,50 @@ | ||
# github repository Actions 페이지에 나타낼 이름 | ||
name: devocean A CI with Gradle | ||
|
||
# event trigger | ||
# main, develop 브랜치에 pr 생성시 실행되는 트리거 | ||
on: | ||
# pr 생성시 CI까지만 진행 | ||
pull_request: | ||
branches: [ "main", "develop" ] | ||
|
||
|
||
# permissions: write-all | ||
|
||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
## jdk setting | ||
- uses: actions/checkout@v3 | ||
- name: 🐧Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
## gradle caching | ||
- name: 🐧Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: 🐧application.yml 파일을 생성 합니다. | ||
run: | | ||
cd ./src/main/resources | ||
touch ./application.yml | ||
echo "${{ secrets.PROPERTIES }}" > ./application.yml | ||
shell: bash | ||
|
||
- name: 🐧gradle build를 위한 권한을 부여합니다. | ||
run: chmod +x gradlew | ||
|
||
- name: 🐧gradle build 중입니다. | ||
run: ./gradlew build | ||
shell: bash # ci는 여기까지 |
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,68 @@ | ||
# github repository Actions 페이지에 나타낼 이름.. | ||
name: devocean A CI/CD with Gradle | ||
|
||
# event trigger | ||
# main, develop 브랜치에 push 시실행되는 트리거 | ||
on: | ||
# 푸시했을 때 ci/cd | ||
push: | ||
branches: [ "main", "develop" ] | ||
|
||
# permissions: write-all | ||
|
||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
## jdk setting | ||
- uses: actions/checkout@v3 | ||
- name: 🐧Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
## gradle caching | ||
- name: 🐧Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: 🐧gradle build를 위한 권한을 부여합니다. | ||
run: chmod +x gradlew | ||
|
||
- name: 🐧gradle build 중입니다. | ||
run: ./gradlew build | ||
shell: bash # ci는 여기까지 | ||
|
||
- name: 🐧docker image build 후 docker hub에 push합니다. | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} . | ||
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} | ||
## deploy to production | ||
- name: docker hub에서 pull 후 deploy합니다. | ||
uses: appleboy/ssh-action@master | ||
with: | ||
username: ${{ secrets.EC2_USERNAME }} | ||
host: ${{ secrets.EC2_HOST }} | ||
key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}:latest | ||
sudo docker stop $(sudo docker ps -q) 2>/dev/null || true | ||
sudo docker run --rm -d --network='host' -p 80:8080 --name ${{ secrets.DOCKER_IMAGE }} \ | ||
-e RDB_HOST=${{ secrets.RDB_HOST }} \ | ||
-e RDB_PORT=${{ secrets.RDB_PORT }} \ | ||
-e RDB_SCHEMA=${{ secrets.RDB_SCHEMA }} \ | ||
-e RDB_USER=${{ secrets.RDB_USER }} \ | ||
-e RDB_PASSWORD=${{ secrets.RDB_PASSWORD }} \ | ||
${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}:latest | ||
sudo docker system prune -f |
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,41 @@ | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
# Default ignored files | ||
/shelf/ | ||
/workspace.xml | ||
# Editor-based HTTP Client requests | ||
/httpRequests/ | ||
# Datasource local storage ignored files | ||
/dataSources/ | ||
/dataSources.local.xml |
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
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,16 @@ | ||
package com.paws.devocean.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("*") // 허용할 출처 : 특정 도메인만 받을 수 있음 | ||
.allowedMethods("GET", "POST") // 허용할 HTTP method | ||
.allowCredentials(true); // 쿠키 인증 요청 허용 | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/paws/devocean/controller/ProjectController.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,25 @@ | ||
package com.paws.devocean.controller; | ||
|
||
import com.paws.devocean.dto.ProjectDetailResponse; | ||
import com.paws.devocean.dto.ProjectListResponse; | ||
import com.paws.devocean.service.ProjectService; | ||
import com.paws.devocean.vo.Type; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/projects") | ||
public class ProjectController { | ||
private final ProjectService projectService; | ||
|
||
@GetMapping | ||
public ProjectListResponse getProjects(@RequestParam Type type) { | ||
return projectService.getProject(type); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ProjectDetailResponse getProject(@PathVariable Long id) { | ||
return projectService.getProjectById(id); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/paws/devocean/dto/ProjectDetailResponse.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,10 @@ | ||
package com.paws.devocean.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ProjectDetailResponse( | ||
String title, | ||
String content | ||
) { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/paws/devocean/dto/ProjectListResponse.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,11 @@ | ||
package com.paws.devocean.dto; | ||
|
||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
|
||
@Builder | ||
public record ProjectListResponse ( | ||
List<ProjectResponse> projects | ||
){} | ||
|
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,10 @@ | ||
package com.paws.devocean.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ProjectResponse( | ||
String title, | ||
String thumbnail, | ||
Long project_id | ||
){} |
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,30 @@ | ||
package com.paws.devocean.entity; | ||
|
||
import com.paws.devocean.vo.Type; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor | ||
public class Project { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String thumbnail; | ||
|
||
@Column(nullable = false) | ||
private String title; | ||
|
||
@Column(columnDefinition = "TEXT", nullable = false) | ||
private String content; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private Type type; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/paws/devocean/repository/ProjectRepository.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,11 @@ | ||
package com.paws.devocean.repository; | ||
|
||
import com.paws.devocean.entity.Project; | ||
import com.paws.devocean.vo.Type; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface ProjectRepository extends JpaRepository<Project, Long> { | ||
List<Project> findAllByType(Type type); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/paws/devocean/service/ProjectService.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,38 @@ | ||
package com.paws.devocean.service; | ||
|
||
import com.paws.devocean.dto.ProjectDetailResponse; | ||
import com.paws.devocean.dto.ProjectListResponse; | ||
import com.paws.devocean.dto.ProjectResponse; | ||
import com.paws.devocean.entity.Project; | ||
import com.paws.devocean.repository.ProjectRepository; | ||
import com.paws.devocean.vo.Type; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class ProjectService { | ||
private final ProjectRepository projectRepository; | ||
|
||
public ProjectListResponse getProject(Type type) { | ||
return new ProjectListResponse( | ||
projectRepository.findAllByType(type).stream() | ||
.map(project -> ProjectResponse.builder() | ||
.thumbnail(project.getThumbnail()) | ||
.title(project.getTitle()) | ||
.project_id(project.getId()) | ||
.build()) | ||
.toList() | ||
); | ||
} | ||
|
||
public ProjectDetailResponse getProjectById(Long projectId) { | ||
Project project = projectRepository.findById(projectId).orElseThrow(); | ||
return ProjectDetailResponse.builder() | ||
.title(project.getTitle()) | ||
.content(project.getContent()) | ||
.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,6 @@ | ||
package com.paws.devocean.vo; | ||
|
||
public enum Type { | ||
DEVOCEAN_YOUNG, | ||
OPEN_LAB | ||
} |
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
spring: | ||
profiles: | ||
active: | ||
- prod | ||
datasource: | ||
url: jdbc:mysql://${RDB_HOST}:${RDB_PORT}/${RDB_SCHEMA}?serverTimezone=Asia/Seoul&characterEncoding=utf8 | ||
username: ${RDB_USER} | ||
password: ${RDB_PASSWORD} | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
|
||
jpa: | ||
hibernate: | ||
ddl-auto: update |