Skip to content

Commit e89a30c

Browse files
committed
fix: 포인트 차감 500애러 해결 및 리워드 구매시 이메일 전송 오류 해결, 사용자 정보 제대로 출력되게 수정
1 parent 5ac5cc8 commit e89a30c

File tree

15 files changed

+298
-28
lines changed

15 files changed

+298
-28
lines changed
532 KB
Binary file not shown.
0 Bytes
Binary file not shown.
14.8 KB
Binary file not shown.
0 Bytes
Binary file not shown.
26.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
594 Bytes
Binary file not shown.

.gradle/file-system.probe

0 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.swyp.global.config;
2+
3+
import com.swyp.social_login.service.auth.UserService;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.boot.ApplicationArguments;
6+
import org.springframework.boot.ApplicationRunner;
7+
import org.springframework.stereotype.Component;
8+
9+
/**
10+
* 애플리케이션 시작 시 자동으로 실행되는 작업을 수행하는 클래스
11+
*/
12+
@Component
13+
@RequiredArgsConstructor
14+
public class ApplicationStartupRunner implements ApplicationRunner {
15+
16+
private final UserService userService;
17+
18+
@Override
19+
public void run(ApplicationArguments args) throws Exception {
20+
// 애플리케이션 시작 시 사용자 엔터티 연결 실행
21+
System.out.println("애플리케이션 시작: 사용자 엔터티 연결 작업 실행...");
22+
userService.linkUserEntities();
23+
}
24+
}

Location-based-target-authentication/src/main/java/com/swyp/point/controller/PointController.java

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.swyp.point.controller;
22
import com.swyp.point.dto.PointAddRequest;
33
import com.swyp.point.dto.PointBalanceResponse;
4-
import com.swyp.point.dto.PointDedeductRequest;
4+
import com.swyp.point.dto.PointDeductRequest;
5+
import com.swyp.point.enums.PointType;
56
import com.swyp.point.service.PointService;
67
import com.swyp.social_login.entity.AuthUser;
78
import com.swyp.social_login.repository.UserRepository;
@@ -109,44 +110,84 @@ public ResponseEntity<Map<String, Object>> addPoints(
109110
//포인트 차감
110111
@Operation(
111112
summary = "포인트 차감",
112-
description = "사용자의 포인트를 차감합니다.",
113+
description = "사용자의 포인트를 차감하고 선택한 쿠폰(스타벅스, 편의점 등)을 발급합니다.",
113114
responses = {
114115
@ApiResponse(
115116
responseCode = "200",
116-
description = "포인트 차감 성공",
117+
description = "포인트 차감 및 쿠폰 발급 성공",
117118
content = @Content(
118119
mediaType = "application/json",
119-
schema = @Schema(example = "{\"status\": \"success\", \"message\": \"포인트가 차감됨\", \"totalPoints\": 450}")
120+
schema = @Schema(example = "{\"status\": \"success\", \"message\": \"포인트가 차감되었습니다\", \"totalPoints\": 450}")
120121
)
121122
),
122123
@ApiResponse(
123124
responseCode = "400",
124-
description = "포인트가 부족함",
125+
description = "포인트가 부족하거나 쿠폰 발급 조건 불충족",
125126
content = @Content(
126127
mediaType = "application/json",
127-
schema = @Schema(example = "{\"status\": \"fail\", \"message\": \"포인트가 부족함\"}")
128+
schema = @Schema(example = "{\"status\": \"fail\", \"message\": \"포인트가 부족합니다. 현재 포인트: 1000, 필요 포인트: 5000\"}")
128129
)
130+
),
131+
@ApiResponse(
132+
responseCode = "404",
133+
description = "사용자를 찾을 수 없음"
134+
),
135+
@ApiResponse(
136+
responseCode = "500",
137+
description = "서버 내부 오류"
129138
)
130139
}
131140
)
132141
@PostMapping("/{userId}/deduct")
133142
public ResponseEntity<Map<String, Object>> deductPoints(
134143
@PathVariable("userId") Long pathUserId,
135-
@RequestBody PointDedeductRequest pointRequest,
144+
@RequestBody PointDeductRequest pointRequest,
136145
HttpServletRequest request) {
137146
try {
138147
// userId로 사용자 찾기
139148
AuthUser authUser = findAuthUser(pathUserId);
140149

141150
try {
151+
// 쿠폰 타입 검증 및 포인트 검증
152+
if (pointRequest.getPointType() != null &&
153+
(pointRequest.getPointType() == PointType.GIFT_STARBUCKS ||
154+
pointRequest.getPointType() == PointType.GIFT_COUPON)) {
155+
156+
// 스타벅스 쿠폰은 최소 5,000 포인트 필요
157+
if (pointRequest.getPointType() == PointType.GIFT_STARBUCKS && pointRequest.getPoints() < 5000) {
158+
Map<String, Object> response = new HashMap<>();
159+
response.put("status", "fail");
160+
response.put("message", "스타벅스 쿠폰은 최소 5,000 포인트가 필요합니다.");
161+
return ResponseEntity.badRequest().body(response);
162+
}
163+
164+
// 편의점 쿠폰은 최소 10,000 포인트 필요
165+
if (pointRequest.getPointType() == PointType.GIFT_COUPON && pointRequest.getPoints() < 10000) {
166+
Map<String, Object> response = new HashMap<>();
167+
response.put("status", "fail");
168+
response.put("message", "편의점 쿠폰은 최소 10,000 포인트가 필요합니다.");
169+
return ResponseEntity.badRequest().body(response);
170+
}
171+
}
172+
142173
// 포인트 차감 처리
143174
boolean success = pointService.deductPoints(authUser, pointRequest.getPoints(), pointRequest.getPointType(), pointRequest.getDescription(), pointRequest.getGoalId());
175+
144176
if (success) {
145177
int updatedPoints = pointService.getUserPoints(authUser);
146178
Map<String, Object> response = new HashMap<>();
147-
response.put("status", "success");
148-
response.put("message", "포인트가 성공적으로 차감되었습니다");
149-
response.put("totalPoints", updatedPoints);
179+
180+
if (pointRequest.getPointType() == PointType.GIFT_STARBUCKS || pointRequest.getPointType() == PointType.GIFT_COUPON) {
181+
response.put("status", "success");
182+
response.put("message", "포인트가 차감되었습니다");
183+
response.put("totalPoints", updatedPoints);
184+
response.put("couponType", pointRequest.getPointType().name());
185+
} else {
186+
response.put("status", "success");
187+
response.put("message", "포인트가 차감되었습니다");
188+
response.put("totalPoints", updatedPoints);
189+
}
190+
150191
return ResponseEntity.ok(response);
151192
} else {
152193
Map<String, Object> response = new HashMap<>();
@@ -166,9 +207,13 @@ public ResponseEntity<Map<String, Object>> deductPoints(
166207
errorResponse.put("message", "사용자를 찾을 수 없습니다");
167208
return ResponseEntity.status(404).body(errorResponse);
168209
} catch (Exception e) {
210+
// 자세한 예외 로깅 추가
211+
e.printStackTrace();
169212
Map<String, Object> errorResponse = new HashMap<>();
170213
errorResponse.put("status", "error");
171214
errorResponse.put("message", "서버 오류가 발생했습니다: " + e.getMessage());
215+
// 개발 환경에서만 스택 트레이스 포함
216+
errorResponse.put("stackTrace", e.toString());
172217
return ResponseEntity.status(500).body(errorResponse);
173218
}
174219
}

0 commit comments

Comments
 (0)