Skip to content

Commit 012c1bf

Browse files
authored
Merge pull request #31 from ttakkeun/feat/30
[Feat] 사용자 포인트 차감 API 구현
2 parents 180c084 + 05109a3 commit 012c1bf

File tree

6 files changed

+139
-106
lines changed

6 files changed

+139
-106
lines changed

.github/workflows/dev_deploy.yml

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
name: ttakkeun dev CI/CD
2-
3-
on:
4-
pull_request:
5-
types: [closed] # merge가 됐을 때 작동하도록 함
6-
workflow_dispatch: # (2).수동 실행도 가능하도록
7-
8-
jobs:
9-
build:
10-
runs-on: ubuntu-latest # (3).OS환경
11-
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
12-
# develop 브랜치에 merge가 됐을 때 작동하도록 설정
13-
14-
steps:
15-
- name: Checkout # 위에서 기재한 develop 브랜치의 코드를 가져옴
16-
uses: actions/checkout@v2 # (4).코드 check out
17-
18-
- name: Set up JDK 17 # 깃허브 자체적으로 자바 jdk를 설치함
19-
uses: actions/setup-java@v3
20-
with:
21-
java-version: 17 # (5).자바 설치
22-
distribution: 'adopt'
23-
24-
- name: Grant execute permission for gradlew # gradle이 들어갈 대상에 권한을 부여함
25-
run: chmod +x ./gradlew
26-
shell: bash # (6).권한 부여
27-
28-
- name: Build with Gradle
29-
run: ./gradlew clean build -x test
30-
shell: bash # (7).build시작
31-
# (5), (6), (7) - Github Actions를 이용해서 Jar 파일을 만드는 과정
32-
33-
- name: Get current time
34-
uses: 1466587594/get-current-time@v2
35-
id: current-time
36-
with:
37-
format: YYYY-MM-DDTHH-mm-ss
38-
utcOffset: "+09:00" # (8).build시점의 시간확보
39-
40-
- name: Show Current Time
41-
run: echo "CurrentTime=$"
42-
shell: bash # (9).확보한 시간 보여주기
43-
# (8), (9) - 타임스탬프를 기록하기 위한 과정
44-
45-
- name: Generate deployment package
46-
run: |
47-
mkdir -p deploy
48-
cp build/libs/*.jar deploy/application.jar
49-
cp Procfile deploy/Procfile
50-
cp -r .ebextensions-dev deploy/.ebextensions
51-
cp -r .platform deploy/.platform
52-
cd deploy && zip -r deploy.zip .
53-
# Github Action을 통해 깃허브가 자체적으로 리눅스 가상 환경을 만들어서
54-
# 배포에 필요한 빌드 과정을 진행하는 과정
55-
56-
- name: List deploy directory contents
57-
run: |
58-
echo "Contents of deploy directory:"
59-
ls -R deploy
60-
shell: bash
61-
62-
- name: Check nginx.conf existence
63-
run: |
64-
if [ -f deploy/.platform/nginx.conf ]; then
65-
echo "nginx.conf found"
66-
else
67-
echo "nginx.conf not found"
68-
exit 1
69-
fi
70-
shell: bash
71-
# nginx 상태 점검용 코드 추가
72-
73-
- name: Unzip deploy package
74-
run: |
75-
unzip deploy/deploy.zip -d deploy/unzipped
76-
echo "Contents of unzipped deploy directory:"
77-
ls -R deploy/unzipped
78-
shell: bash
79-
# deploy.zip 파일 내 내용 확인
80-
81-
- name: Beanstalk Deploy
82-
uses: einaregilsson/beanstalk-deploy@v21
83-
with:
84-
aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }} # 깃허브에 secrets로 설정함
85-
aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }} # 깃허브에 secrets로 설정함
86-
application_name: umc-ttakkeun-dev
87-
environment_name: Umc-ttakkeun-dev-env # Elastic Beanstalk명
88-
version_label: github-action-${{ steps.current-time.outputs.formattedTime }} # 타임스탬프
89-
region: ap-northeast-2
90-
deployment_package: deploy/deploy.zip
91-
wait_for_deployment: false
92-
# Elastic beanstalk에 배포 요청
1+
#name: ttakkeun dev CI/CD
2+
#
3+
#on:
4+
# pull_request:
5+
# types: [closed] # merge가 됐을 때 작동하도록 함
6+
# workflow_dispatch: # (2).수동 실행도 가능하도록
7+
#
8+
#jobs:
9+
# build:
10+
# runs-on: ubuntu-latest # (3).OS환경
11+
# if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
12+
# # develop 브랜치에 merge가 됐을 때 작동하도록 설정
13+
#
14+
# steps:
15+
# - name: Checkout # 위에서 기재한 develop 브랜치의 코드를 가져옴
16+
# uses: actions/checkout@v2 # (4).코드 check out
17+
#
18+
# - name: Set up JDK 17 # 깃허브 자체적으로 자바 jdk를 설치함
19+
# uses: actions/setup-java@v3
20+
# with:
21+
# java-version: 17 # (5).자바 설치
22+
# distribution: 'adopt'
23+
#
24+
# - name: Grant execute permission for gradlew # gradle이 들어갈 대상에 권한을 부여함
25+
# run: chmod +x ./gradlew
26+
# shell: bash # (6).권한 부여
27+
#
28+
# - name: Build with Gradle
29+
# run: ./gradlew clean build -x test
30+
# shell: bash # (7).build시작
31+
# # (5), (6), (7) - Github Actions를 이용해서 Jar 파일을 만드는 과정
32+
#
33+
# - name: Get current time
34+
# uses: 1466587594/get-current-time@v2
35+
# id: current-time
36+
# with:
37+
# format: YYYY-MM-DDTHH-mm-ss
38+
# utcOffset: "+09:00" # (8).build시점의 시간확보
39+
#
40+
# - name: Show Current Time
41+
# run: echo "CurrentTime=$"
42+
# shell: bash # (9).확보한 시간 보여주기
43+
# # (8), (9) - 타임스탬프를 기록하기 위한 과정
44+
#
45+
# - name: Generate deployment package
46+
# run: |
47+
# mkdir -p deploy
48+
# cp build/libs/*.jar deploy/application.jar
49+
# cp Procfile deploy/Procfile
50+
# cp -r .ebextensions-dev deploy/.ebextensions
51+
# cp -r .platform deploy/.platform
52+
# cd deploy && zip -r deploy.zip .
53+
# # Github Action을 통해 깃허브가 자체적으로 리눅스 가상 환경을 만들어서
54+
# # 배포에 필요한 빌드 과정을 진행하는 과정
55+
#
56+
# - name: List deploy directory contents
57+
# run: |
58+
# echo "Contents of deploy directory:"
59+
# ls -R deploy
60+
# shell: bash
61+
#
62+
# - name: Check nginx.conf existence
63+
# run: |
64+
# if [ -f deploy/.platform/nginx.conf ]; then
65+
# echo "nginx.conf found"
66+
# else
67+
# echo "nginx.conf not found"
68+
# exit 1
69+
# fi
70+
# shell: bash
71+
# # nginx 상태 점검용 코드 추가
72+
#
73+
# - name: Unzip deploy package
74+
# run: |
75+
# unzip deploy/deploy.zip -d deploy/unzipped
76+
# echo "Contents of unzipped deploy directory:"
77+
# ls -R deploy/unzipped
78+
# shell: bash
79+
# # deploy.zip 파일 내 내용 확인
80+
#
81+
# - name: Beanstalk Deploy
82+
# uses: einaregilsson/beanstalk-deploy@v21
83+
# with:
84+
# aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }} # 깃허브에 secrets로 설정함
85+
# aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }} # 깃허브에 secrets로 설정함
86+
# application_name: umc-ttakkeun-dev
87+
# environment_name: Umc-ttakkeun-dev-env # Elastic Beanstalk명
88+
# version_label: github-action-${{ steps.current-time.outputs.formattedTime }} # 타임스탬프
89+
# region: ap-northeast-2
90+
# deployment_package: deploy/deploy.zip
91+
# wait_for_deployment: false
92+
# # Elastic beanstalk에 배포 요청

src/main/java/ttakkeun/ttakkeun_server/apiPayLoad/ApiResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static <T> ApiResponse<T> of(BaseCode code, T result){
3131

3232
// 실패한 경우
3333
public static <T> ApiResponse<T> onFailure(String code, String message, T data) {
34-
return new ApiResponse<>(true, code, message, data);
34+
return new ApiResponse<>(false, code, message, data);
3535
}
3636

3737
public static <T> ApiResponse<T> ofFailure(BaseErrorCode code, T result) {

src/main/java/ttakkeun/ttakkeun_server/controller/DiagnoseController.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package ttakkeun.ttakkeun_server.controller;
22

3+
import feign.Response;
34
import lombok.RequiredArgsConstructor;
45
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.http.HttpStatus;
67
import org.springframework.http.ResponseEntity;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.RequestMapping;
9-
import org.springframework.web.bind.annotation.RequestParam;
10-
import org.springframework.web.bind.annotation.RestController;
8+
import org.springframework.web.bind.annotation.*;
119
import ttakkeun.ttakkeun_server.apiPayLoad.ApiResponse;
1210
import ttakkeun.ttakkeun_server.apiPayLoad.code.status.ErrorStatus;
1311
import ttakkeun.ttakkeun_server.apiPayLoad.code.status.SuccessStatus;
1412
import ttakkeun.ttakkeun_server.dto.GetMyPointResponseDTO;
13+
import ttakkeun.ttakkeun_server.dto.UpdateMyPointResponseDTO;
1514
import ttakkeun.ttakkeun_server.service.DiagnoseService;
1615

1716
import java.util.NoSuchElementException;
@@ -26,7 +25,7 @@ public class DiagnoseController {
2625
private DiagnoseService diagnoseService;
2726

2827
// memberId 임의로 입력받아서 조회하는 방식으로 구현함
29-
// 추후 액세스 토큰으로 멤버 아이디 받아와서 조회하는 방식으로 수정 예정
28+
// 추후 로그인 정보로 멤버 아이디 받아와서 조회하는 방식으로 수정 예정
3029
@GetMapping("/point")
3130
public ResponseEntity<ApiResponse<GetMyPointResponseDTO>> getPointsByMember(@RequestParam("member-id") Long memberId) {
3231
try {
@@ -35,10 +34,25 @@ public ResponseEntity<ApiResponse<GetMyPointResponseDTO>> getPointsByMember(@Req
3534
return ResponseEntity.ok(response);
3635
} catch (NoSuchElementException e) {
3736
ApiResponse<GetMyPointResponseDTO> response = ApiResponse.ofFailure(ErrorStatus.MEMBER_NOT_FOUND, null);
38-
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
37+
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
3938
} catch (Exception e) {
4039
ApiResponse<GetMyPointResponseDTO> response = ApiResponse.ofFailure(ErrorStatus._INTERNAL_SERVER_ERROR, null);
4140
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
4241
}
4342
}
43+
44+
@PatchMapping("/loading")
45+
public ResponseEntity<ApiResponse<UpdateMyPointResponseDTO>> updatePointsByMember(@RequestParam("member-id") Long memberId) {
46+
try {
47+
Integer point = diagnoseService.updatePointsByMember(memberId);
48+
ApiResponse<UpdateMyPointResponseDTO> response = ApiResponse.of(SuccessStatus._OK, new UpdateMyPointResponseDTO(point));
49+
return ResponseEntity.ok(response);
50+
} catch (NoSuchElementException e) {
51+
ApiResponse<UpdateMyPointResponseDTO> response = ApiResponse.ofFailure(ErrorStatus.MEMBER_NOT_FOUND, null);
52+
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
53+
} catch (Exception e) {
54+
ApiResponse<UpdateMyPointResponseDTO> response = ApiResponse.ofFailure(ErrorStatus._INTERNAL_SERVER_ERROR, null);
55+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
56+
}
57+
}
4458
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package ttakkeun.ttakkeun_server.dto;
2+
3+
public record UpdateMyPointResponseDTO(Integer point) {
4+
}

src/main/java/ttakkeun/ttakkeun_server/service/DiagnoseService.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,23 @@ private boolean isToday(LocalDateTime dateTime) {
5151
return today.equals(date);
5252
// 입력받은 값이 오늘 날짜와 같다면 true 반환, 오늘 날짜와 다르다면 false 반환
5353
}
54+
55+
public Integer updatePointsByMember(Long memberId) throws Exception {
56+
Optional<Point> pointOpt = pointRepository.findByMemberId(memberId);
57+
58+
if (pointOpt.isPresent()) {
59+
Point point = pointOpt.get(); // Optinal 객체에서 point를 가져옴
60+
Integer points = point.getPoints();
61+
62+
// 진단시 포인트가 1점 차감됨
63+
point.setPoints(points-1);
64+
point.setUpdatedAt(LocalDateTime.now());
65+
pointRepository.save(point);
66+
return point.getPoints();
67+
} else {
68+
// Optional 객체에서 값이 비어있는 경우 예외를 던짐
69+
// 0 반환에서 오류 발생하도록 수정함
70+
throw new NoSuchElementException("Member with ID " + memberId + " not found");
71+
}
72+
}
5473
}

src/main/resources/application.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ spring:
22
main:
33
allow-bean-definition-overriding: true
44
datasource:
5-
# url: ${db.url}
6-
# username: ${db.username}
7-
# password: ${db.password}
8-
#
9-
url: jdbc:mysql://localhost:3306/ttakkeun
10-
username: root
11-
password: sallyjane
5+
url: ${db.url}
6+
username: ${db.username}
7+
password: ${db.password}
128
driver-class-name: com.mysql.cj.jdbc.Driver
139
sql:
1410
init:

0 commit comments

Comments
 (0)