Skip to content

Commit 070db50

Browse files
authored
Merge pull request #13 from hykim02/main
[Merge] 식단 리팩토링 코드 병합
2 parents 780b6f9 + 5e268af commit 070db50

File tree

23 files changed

+489
-220
lines changed

23 files changed

+489
-220
lines changed

.github/workflows/cd.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy to GCP
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '.github/workflows/**'
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write
15+
contents: read
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
# CI에서 생성한 JAR 파일 다운로드
20+
- name: Download JAR Artifact
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: application-jar
24+
path: build/libs/
25+
26+
- name: Login to DockerHub
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKER_USERNAME }}
30+
password: ${{ secrets.DOCKER_PASSWORD }}
31+
32+
- name: Build & Push Docker Image
33+
uses: docker/build-push-action@v6
34+
with:
35+
push: true
36+
context: .
37+
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest
38+
39+
- name: Authenticate to GCP
40+
uses: google-github-actions/auth@v2
41+
with:
42+
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
43+
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
44+
45+
- name: Deploy to GCP Compute Engine
46+
uses: google-github-actions/ssh-compute@v1
47+
with:
48+
instance_name: ${{ secrets.GCP_INSTANCE_NAME }}
49+
zone: ${{ secrets.GCP_INSTANCE_ZONE }}
50+
ssh_private_key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
51+
command: |
52+
cd /app/${{ github.repository }}
53+
sudo curl -o docker-compose.yml https://raw.githubusercontent.com/${{ github.repository }}/main/docker-compose.yml
54+
sudo docker-compose down
55+
sudo docker-compose up -d ${{ secrets.DOCKER_IMAGE_NAME }}
56+
sudo docker image prune -a -f

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Java CI with Gradle
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up JDK 21
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '21'
24+
distribution: 'temurin'
25+
26+
- name: Setup Gradle
27+
uses: gradle/actions/setup-gradle@v4
28+
29+
- name: Build with Gradle
30+
run: ./gradlew build
31+
32+
# 빌드 결과물을 아티팩트로 업로드 (JAR 파일)
33+
- name: Upload JAR Artifact
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: application-jar
37+
path: build/libs/*.jar

.github/workflows/gradle.yml

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/main/java/com/example/Jinus/controller/v2/CafeteriaControllerV2.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.example.Jinus.utility.ListCardResponse;
1111
import org.springframework.web.bind.annotation.PostMapping;
1212
import org.springframework.web.bind.annotation.RequestBody;
13+
import org.springframework.web.bind.annotation.RequestMapping;
1314
import org.springframework.web.bind.annotation.RestController;
1415

1516
import java.util.ArrayList;
@@ -18,6 +19,7 @@
1819
import java.util.Map;
1920

2021
@RestController
22+
@RequestMapping("/api/v2/spring")
2123
public class CafeteriaControllerV2 {
2224

2325
private final UserServiceV2 userServiceV2;
@@ -33,20 +35,14 @@ public CafeteriaControllerV2(
3335
this.cafeteriaServiceV2 = cafeteriaServiceV2;
3436
}
3537

36-
3738
// 사용자 존재 여부에 따라 응답
38-
@PostMapping("/api/spring/cafeteria/v2")
39+
@PostMapping("/cafeteria")
3940
public String responseCafeteriaOrCampusListCard(@RequestBody RequestDto requestDto) {
4041
// userId로 campusId 찾기
4142
String userId = requestDto.getUserRequest().getUser().getId();
4243
int campusId = userServiceV2.getUserCampusId(userId);
4344
int sysCampusId = requestDto.getAction().getClientExtra().getSys_campus_id();
4445

45-
// 사용자가 존재 & 식당 블록에서 캠퍼스 눌렀을 때 -> 식당 리스트
46-
if (campusId != -1 && sysCampusId != -1) {
47-
return cafeteriaServiceV2.makeCafeteriaListCard(campusId);
48-
} else { // 사용자가 존재 X & 식당 블록에서 더보기 버튼 눌렀을 때 -> 캠퍼스 리스트
49-
return campusServiceV2.makeCampusListCard();
50-
}
46+
return cafeteriaServiceV2.campusOrCafeteria(campusId, sysCampusId);
5147
}
5248
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.Jinus.controller.v2;
2+
3+
import com.example.Jinus.dto.request.RequestDto;
4+
import com.example.Jinus.service.v2.cafeteria.DietServiceV2;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.web.bind.annotation.PostMapping;
7+
import org.springframework.web.bind.annotation.RequestBody;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
@RequestMapping("/api/v2/spring")
13+
@RequiredArgsConstructor
14+
public class DietControllerV2 {
15+
private final DietServiceV2 dietServiceV2;
16+
17+
@PostMapping("/dish")
18+
public String handleRequest(@RequestBody RequestDto requestDto) {
19+
return dietServiceV2.requestHandler(requestDto);
20+
}
21+
}

src/main/java/com/example/Jinus/controller/v2/NoticeControllerV2.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import com.example.Jinus.dto.request.RequestDto;
44
import com.example.Jinus.dto.response.*;
55
import com.example.Jinus.entity.notice.NoticeCategoryEntity;
6-
import com.example.Jinus.service.v2.notice.NoticeCategoryServiceV2;
6+
import com.example.Jinus.service.v2.notice.CategoryServiceV2;
77
import com.example.Jinus.service.v2.notice.NoticeServiceV2;
88
import com.example.Jinus.service.v2.userInfo.DepartmentServiceV2;
99
import com.example.Jinus.service.v2.userInfo.UserServiceV2;
1010
import com.example.Jinus.utility.JsonUtils;
1111
import com.example.Jinus.utility.TextCardResponse;
1212
import org.springframework.web.bind.annotation.PostMapping;
1313
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.RequestMapping;
1415
import org.springframework.web.bind.annotation.RestController;
1516

1617
import java.util.ArrayList;
@@ -19,15 +20,16 @@
1920
import static java.lang.String.valueOf;
2021

2122
@RestController
23+
@RequestMapping("/api/v2/spring")
2224
public class NoticeControllerV2 {
2325

2426
private final NoticeServiceV2 noticeServiceV2;
25-
private final NoticeCategoryServiceV2 noticeCategoryServiceV2;
27+
private final CategoryServiceV2 noticeCategoryServiceV2;
2628
private final DepartmentServiceV2 departmentServiceV2;
2729
private final UserServiceV2 userServiceV2;
2830

2931
public NoticeControllerV2(NoticeServiceV2 noticeServiceV2,
30-
NoticeCategoryServiceV2 noticeCategoryServiceV2,
32+
CategoryServiceV2 noticeCategoryServiceV2,
3133
DepartmentServiceV2 departmentServiceV2,
3234
UserServiceV2 userServiceV2) {
3335
this.noticeServiceV2 = noticeServiceV2;
@@ -37,15 +39,15 @@ public NoticeControllerV2(NoticeServiceV2 noticeServiceV2,
3739
}
3840

3941
// 학교 공지사항 조회
40-
@PostMapping("/api/spring/main-notice/v2")
42+
@PostMapping("/main-notice")
4143
public String getMainNotice() {
4244
int departmentId = 117; // 학교 공지사항 id
4345
String departmentEng = "main"; // 학과 영문명
4446
return existUserReturnNotice(departmentEng, departmentId);
4547
}
4648

4749
// 학과 공지사항 조회
48-
@PostMapping("/api/spring/department-notice/v2")
50+
@PostMapping("/department-notice")
4951
public String responseDepartmentNotice(@RequestBody RequestDto requestDto) {
5052
String userId = requestDto.getUserRequest().getUser().getId();
5153
int departmentId = userServiceV2.getUserDepartmentId(userId);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.Jinus.dto.request;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public class HandleRequestDto {
9+
private final String kakaoId;
10+
private final String campusName;
11+
private final String day;
12+
private final String period;
13+
private final String cafeteriaName;
14+
15+
public HandleRequestDto(String kakaoId, String campusName, String day, String period, String cafeteriaName) {
16+
this.kakaoId = kakaoId;
17+
this.campusName = campusName;
18+
this.day = day;
19+
this.period = period;
20+
this.cafeteriaName = cafeteriaName;
21+
}
22+
23+
}

src/main/java/com/example/Jinus/entity/cafeteria/CafeteriaDietEntity.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import lombok.NoArgsConstructor;
77
import lombok.Setter;
88

9-
import java.time.LocalDateTime;
9+
import java.sql.Date;
1010

1111
@Entity
1212
@Getter
@@ -20,11 +20,8 @@ public class CafeteriaDietEntity {
2020
@GeneratedValue(strategy = GenerationType.IDENTITY)
2121
private int dietId;
2222

23-
@Column(name = "date", columnDefinition = "TIMESTAMP WITH TIME ZONE")
24-
private LocalDateTime dateTime; // 날짜 + 시간 + 시간대
25-
26-
// @Column(name = "date")
27-
// private LocalTime date;
23+
@Column(name = "date")
24+
private Date dietDate;
2825

2926
@Column(name = "day")
3027
private String day_of_week;

src/main/java/com/example/Jinus/repository/v2/cafeteria/CafeteriaRepositoryV2.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.HashMap;
99
import java.util.List;
10+
import java.util.Optional;
1011

1112
public interface CafeteriaRepositoryV2 extends JpaRepository<CafeteriaEntity, Integer> {
1213
// 사용자 campusId와 동일한 식당이름과 url 찾기
@@ -16,6 +17,10 @@ public interface CafeteriaRepositoryV2 extends JpaRepository<CafeteriaEntity, In
1617
// campusId와 식당이름으로 cafeteriaId 찾기
1718
@Query("SELECT c.id FROM CafeteriaEntity c " +
1819
"WHERE c.campusId = :campusId AND c.cafeteriaNameKo = :cafeteriaName")
19-
int findCafeteriaId(@Param("cafeteriaName") String cafeteriaName,
20-
@Param("campusId") int campusId);
20+
Optional<Integer> findCafeteriaId(@Param("cafeteriaName") String cafeteriaName,
21+
@Param("campusId") int campusId);
22+
23+
// cafeteriaId로 imgUrl 찾기
24+
@Query("SELECT c.thumbnailUrl FROM CafeteriaEntity c WHERE c.id = :cafeteriaId")
25+
String findImgUrlByCafeteriaId(@Param("cafeteriaId")int cafeteriaId);
2126
}

0 commit comments

Comments
 (0)