Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

전남대 BE_박진화 6주차 과제 (Step3) #406

Open
wants to merge 129 commits into
base: jinhwa-park
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
316e185
Initial commit
wotjd243 Jun 23, 2024
8569d45
Initial commit
wotjd243 Jun 23, 2024
d5003d1
feat: set up the project
wotjd243 Jul 15, 2024
ba7709c
feat: migrate prev project codes
Jinhwa-Park Jul 16, 2024
6c1df36
feat: migrate prev project codes (#131)
Jinhwa-Park Jul 16, 2024
c9708c4
docs: delete unnecessary lines
Jinhwa-Park Jul 16, 2024
3efb237
docs: add README
Jinhwa-Park Jul 17, 2024
0d0c2a9
docs: modify typo
Jinhwa-Park Jul 17, 2024
f596fbf
rename: move prev codes to oldTestCodes directory
Jinhwa-Park Jul 17, 2024
319d6a2
feat: add codes about Category
Jinhwa-Park Jul 17, 2024
d50a1b7
feat: changed feature about set to update
Jinhwa-Park Jul 17, 2024
41a56e1
refactor: modify ProductController as modified Product entity
Jinhwa-Park Jul 17, 2024
8efe562
feat: add getEmailFromRequest method to JwtUtil
Jinhwa-Park Jul 17, 2024
2378e85
refactor: update controllers with clear return types and improve read…
Jinhwa-Park Jul 17, 2024
3c5036e
feat: add new fields(color, imageUrl, description) and update Catego…
Jinhwa-Park Jul 17, 2024
30200d0
feat: add path variable support for category deletion
Jinhwa-Park Jul 18, 2024
3d12d7b
feat: integrate category handling in ProductController
Jinhwa-Park Jul 18, 2024
e0e7fbe
feat: update Product entity to include category handling
Jinhwa-Park Jul 18, 2024
b6eca3e
feat: update ProductRequest, ProductResponse, ProductService to inclu…
Jinhwa-Park Jul 18, 2024
3f68385
feat: Add code to WishController to verify ProductId
Jinhwa-Park Jul 18, 2024
b5c7cbd
"remove: delete unnecessary product.html"
Jinhwa-Park Jul 18, 2024
b82b476
Merge branch 'jinhwa-park' into step1
Jinhwa-Park Jul 18, 2024
b9d1b08
docs: update README
Jinhwa-Park Jul 18, 2024
e6f9d4c
feat: make addOption page for admin
Jinhwa-Park Jul 18, 2024
4a990a1
refactor: change dependency injection from field to constructor
Jinhwa-Park Jul 18, 2024
f735135
feat: implement option features
Jinhwa-Park Jul 18, 2024
9db3978
feat: add option handle feature
Jinhwa-Park Jul 18, 2024
d781978
refactor: change dependency injection from field to constructor (JwtA…
Jinhwa-Park Jul 19, 2024
f55e846
feat: add option schema
Jinhwa-Park Jul 19, 2024
b74f7ad
feat: add redundancy option check feature
Jinhwa-Park Jul 19, 2024
37177da
feat: add properties
Jinhwa-Park Jul 19, 2024
78f78fa
refactor: change annotation from korean to english
Jinhwa-Park Jul 19, 2024
cd2982f
Revert "feat: add redundancy option check feature"
Jinhwa-Park Jul 19, 2024
4494483
Revert "Revert "feat: add redundancy option check feature""
Jinhwa-Park Jul 19, 2024
35c1d34
feat: add enforcing product have at least one option
Jinhwa-Park Jul 19, 2024
a72acdb
feat: add feat ProductController, OptionDTO, ProductRequest
Jinhwa-Park Jul 19, 2024
d10b7a0
docs: update README
Jinhwa-Park Jul 19, 2024
2c3afa5
docs: edit README indent
Jinhwa-Park Jul 19, 2024
ec2b9d5
feat: add getter and setter for quantity
Jinhwa-Park Jul 19, 2024
6e576f5
feat: add method for decrease quantity value
Jinhwa-Park Jul 19, 2024
1978094
docs: update README as include selectable options
Jinhwa-Park Jul 20, 2024
1eb1dd1
fix: make GlobalExceptionHandler handles proper error
Jinhwa-Park Jul 20, 2024
ae56b70
refactor: changes id variable to indicate clearly
Jinhwa-Park Jul 20, 2024
1737485
feat: Apply review feedback and add test code
Jinhwa-Park Jul 21, 2024
29c5d18
Merge branch 'step1' into step2
Jinhwa-Park Jul 21, 2024
8477326
feat: add builder, delete unnecessary import and annotations
Jinhwa-Park Jul 21, 2024
4e0459c
fix: modify as it works on test codes, change order, add option on data
Jinhwa-Park Jul 21, 2024
c8b4d09
feat: add CustomException, delete unnecessary annotations
Jinhwa-Park Jul 21, 2024
8d4dfbb
rename: modify OptionDTO to OptionRequest
Jinhwa-Park Jul 21, 2024
d47d8b0
refactor: Improve validation, error handling, entity retrieval
Jinhwa-Park Jul 21, 2024
0c75891
refactor: change to use CustomException
Jinhwa-Park Jul 21, 2024
a9d6536
refactor: change to use CustomException
Jinhwa-Park Jul 21, 2024
8e1b1a0
refactor: using SpringBootTest to WebMvcTest
Jinhwa-Park Jul 21, 2024
152c8ad
refactor: apply renamed OptionRequest
Jinhwa-Park Jul 21, 2024
44ae309
refactor: enhance validation
Jinhwa-Park Jul 21, 2024
3d9b0ed
feat: set up the project
wotjd243 Jul 22, 2024
aae0660
전남대_BE 박진화 4주차 과제 (1단계) (#219)
Jinhwa-Park Jul 22, 2024
5af08fe
fix: resolve conflicts
Jinhwa-Park Jul 22, 2024
289a9bd
전남대 BE_박진화 4주차 과제 (2단계) (#312)
Jinhwa-Park Jul 23, 2024
50f4da0
fix: resolve conflicts and update codes using builder
Jinhwa-Park Jul 23, 2024
965cd9a
feat: add InvalidQuantityException
Jinhwa-Park Jul 23, 2024
a9218d9
Merge branch 'jinhwa-park' into step3
Jinhwa-Park Jul 23, 2024
3d4dc9a
feat: update step0 as step3 in previous project spring-gift-enhancement
Jinhwa-Park Jul 23, 2024
d437145
전남대 BE_박진화 5주차 과제 (0단계 (#120)
Jinhwa-Park Jul 23, 2024
6575763
feat: make file structure
Jinhwa-Park Jul 24, 2024
cfb623e
feat: modify file names, add API-KEY
Jinhwa-Park Jul 24, 2024
8fa967d
feat: add @ConfigurationPropertiesScan
Jinhwa-Park Jul 25, 2024
c297314
feat: add Lombok
Jinhwa-Park Jul 25, 2024
e49417e
refactor: change code order
Jinhwa-Park Jul 25, 2024
75513b9
feat: add code about kakao
Jinhwa-Park Jul 25, 2024
7ce7418
feat: add regexp 가-힣
Jinhwa-Park Jul 25, 2024
63a6112
feat: implement kakao OAuth features
Jinhwa-Park Jul 25, 2024
52f6302
Merge branch 'jinhwa-park' of https://github.com/kakao-tech-campus-2n…
Jinhwa-Park Jul 25, 2024
804182a
feat: update as fit on step2
Jinhwa-Park Jul 25, 2024
afe1211
feat: add logger and complement AccessDeniedException
Jinhwa-Park Jul 26, 2024
6e5122e
feat: implement feature about Message
Jinhwa-Park Jul 26, 2024
6c4e300
feat: add method that return error's reason
Jinhwa-Park Jul 26, 2024
b9ba916
fix: fix wrong data type
Jinhwa-Park Jul 26, 2024
f47ba7b
feat: implement features about order
Jinhwa-Park Jul 26, 2024
c4b89d2
fix: initialization with constructor
Jinhwa-Park Jul 26, 2024
9880e6f
feat: implement feature that delete related wish list items when orde…
Jinhwa-Park Jul 26, 2024
0aa3867
refactor: remove unnecessary indent
Jinhwa-Park Jul 26, 2024
2e79d2c
feat: add method that help update id
Jinhwa-Park Jul 26, 2024
b8f4158
feat: modify parameter that fits on OrderRequest
Jinhwa-Park Jul 26, 2024
2501774
fix: fix JWT token validation and order placement logic
Jinhwa-Park Jul 27, 2024
dd9e329
docs: remove unnecessary indent or annotations
Jinhwa-Park Jul 27, 2024
6f74476
fix: fix everything I can do
Jinhwa-Park Jul 27, 2024
dd9cb6a
Merge branch 'step1' into step2
Jinhwa-Park Jul 27, 2024
32dea8a
fix: fix everything I can do, and merge with Hotfix branch
Jinhwa-Park Jul 27, 2024
f14fcd0
docs: Write API document
Jinhwa-Park Jul 28, 2024
f28b45d
전남대_BE 박진화 5주차 과제(Step1) (#215)
Jinhwa-Park Jul 28, 2024
5fd98b1
fix: conflict fix
Jinhwa-Park Jul 28, 2024
4bc5f59
feat: Merge previous project's codes
Jinhwa-Park Jul 29, 2024
7c187d2
feat: add swagger for API documentation
Jinhwa-Park Jul 30, 2024
4686e3b
전남대 BE_ 박진화 5주차 과제(Step2) (#323)
Jinhwa-Park Jul 30, 2024
c02d690
docs: add DS_Store as ignore type
Jinhwa-Park Jul 30, 2024
3705f2e
feat: add swagger
Jinhwa-Park Jul 30, 2024
0a45662
Merge branch 'jinhwa-park' into step3
Jinhwa-Park Jul 30, 2024
50d5533
refactor: change url usage
Jinhwa-Park Jul 31, 2024
d8663a2
fix: fix conflict and type.
Jinhwa-Park Jul 31, 2024
dc602f1
feat: update codes as previous project's step3
Jinhwa-Park Jul 31, 2024
1cb5c30
feat: update differences
Jinhwa-Park Jul 31, 2024
d6ac0e9
refactor: set codes like teamMates
Jinhwa-Park Aug 1, 2024
34e9860
refactor: set codes like teamMates
Jinhwa-Park Aug 1, 2024
647f5c4
feat: update codes that fits on teammate's API
Jinhwa-Park Aug 1, 2024
20b375e
fix: fix different implements
Jinhwa-Park Aug 2, 2024
3d15b3e
feat: modify codes
Jinhwa-Park Aug 2, 2024
26f7a5d
fix: fix all things
Jinhwa-Park Aug 2, 2024
c413e04
feat: add WebMvcConfigurer for CORS setting
Jinhwa-Park Aug 4, 2024
f74ac88
feat: implement point feature
Jinhwa-Park Aug 6, 2024
87d6c5c
fix: conflict fix
Jinhwa-Park Aug 6, 2024
f2e57f9
fix: OrderServiceTest fixed
Jinhwa-Park Aug 6, 2024
390beb4
feat: add or modify DTO files
Jinhwa-Park Aug 6, 2024
851d9fc
fix: conflict fix
Jinhwa-Park Aug 6, 2024
870f8f0
Merge branch 'jinhwa-park' of https://github.com/kakao-tech-campus-2n…
Jinhwa-Park Aug 6, 2024
2f6243f
Merge branch 'above' into step2
Jinhwa-Park Aug 6, 2024
37e3ee1
Merge branch 'above' into step3
Jinhwa-Park Aug 6, 2024
fac6ba0
Merge branch 'step2' into step3
Jinhwa-Park Aug 6, 2024
cda28a8
fix: fix conflicts
Jinhwa-Park Aug 7, 2024
8975e8b
Merge branch 'step2' of https://github.com/Jinhwa-Park/spring-gift-po…
Jinhwa-Park Aug 7, 2024
3bff443
Merge branch 'step3' of https://github.com/Jinhwa-Park/spring-gift-po…
Jinhwa-Park Aug 7, 2024
cfe218f
feat: make login access can access with email
Jinhwa-Park Aug 7, 2024
84f4156
feat: make login access can access with email
Jinhwa-Park Aug 7, 2024
4ff5af2
Revert "feat: make login access can access with email"
Jinhwa-Park Aug 7, 2024
72e55da
Merge branch 'publish' of https://github.com/Jinhwa-Park/spring-gift-…
Jinhwa-Park Aug 7, 2024
8e93b3e
feat: fixed
Jinhwa-Park Aug 7, 2024
3e42c10
Merge branch 'publish' of https://github.com/Jinhwa-Park/spring-gift-…
Jinhwa-Park Aug 7, 2024
02f2777
fix: fixed
Jinhwa-Park Aug 8, 2024
4597ac2
feat: add authorization-grant-type
Jinhwa-Park Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'war'
}

group = 'camp.nextstep.edu'
Expand Down Expand Up @@ -37,20 +36,21 @@ dependencies {
implementation 'jakarta.persistence:jakarta.persistence-api:3.1.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
implementation 'org.springframework.boot:spring-boot-configuration-processor'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-oauth2-client'
implementation 'org.springframework.security:spring-security-oauth2-jose'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'

runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-core'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
providedCompile 'jakarta.servlet:jakarta.servlet-api:4.0.4'

developmentOnly 'org.springframework.boot:spring-boot-devtools'
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-parameters'
}

tasks.named('test') {
useJUnitPlatform()
}
39 changes: 4 additions & 35 deletions src/main/java/gift/config/KakaoProperties.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package gift.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Getter
@Setter
@ConfigurationProperties(prefix = "kakao")
public class KakaoProperties {

Expand All @@ -27,39 +31,4 @@ public KakaoProperties(String adminKey, String clientId, String redirectUri, Str
this.authBaseUrl = authBaseUrl;
}

public String getAdminKey() {
return adminKey;
}

public String getClientId() {
return clientId;
}

public String getRedirectUri() {
return redirectUri;
}

public String getTokenRequestUri() {
return tokenRequestUri;
}

public String getMemberInfoRequestUri() {
return memberInfoRequestUri;
}

public String getApiUrl() {
return apiUrl;
}

public String getLoginUrl() {
return loginUrl;
}

public String getScope() {
return scope;
}

public String getAuthBaseUrl() {
return authBaseUrl;
}
}
62 changes: 62 additions & 0 deletions src/main/java/gift/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package gift.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

private final UserDetailsService userDetailsService;

public SecurityConfig(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/login", "/register", "/kakao-login").permitAll();
auth.anyRequest().authenticated();
})
.formLogin(form -> {
form.loginPage("/login");
form.defaultSuccessUrl("/home", true);
form.permitAll();
})
.logout(LogoutConfigurer::permitAll)
.oauth2Login(oauth2 -> oauth2
.loginPage("/login")
.defaultSuccessUrl("/home", true)
);

return http.build();
}

@Bean
public AuthenticationManager authManager(HttpSecurity http) throws Exception {
AuthenticationManagerBuilder authBuilder =
http.getSharedObject(AuthenticationManagerBuilder.class);

authBuilder
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());

return authBuilder.build();
}
}
6 changes: 3 additions & 3 deletions src/main/java/gift/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public FilterRegistrationBean<JwtAuthenticationFilter> jwtAuthenticationFilterRe
// 전역 CORS 설정 추가
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 모든 경로에 대해
.allowedOrigins("http://example.com") // 허용할 출처를 설정
registry.addMapping("/**")
.allowedOrigins("http://54.180.238.108:8080")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*"); // 모든 헤더 허용
.allowedHeaders("*");
}
}
18 changes: 9 additions & 9 deletions src/main/java/gift/controller/KakaoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ public KakaoController(KakaoService kakaoService) {
@GetMapping("/login")
@Operation(summary = "Redirect to Kakao login", description = "Redirects the user to Kakao login page", tags = { "Kakao Authentication System" })
public void redirectKakaoLogin(HttpServletResponse response) throws IOException {
String encodedRedirectUri = URLEncoder.encode(redirectUri, StandardCharsets.UTF_8.toString());
String encodedScope = URLEncoder.encode(scope, StandardCharsets.UTF_8.toString());
StringBuilder kakaoLoginUrl = new StringBuilder(authBaseUrl)
.append("?response_type=code")
.append("&client_id=").append(clientId)
.append("&redirect_uri=").append(encodedRedirectUri)
.append("&scope=").append(encodedScope);
String encodedRedirectUri = URLEncoder.encode(redirectUri, StandardCharsets.UTF_8);
String encodedScope = URLEncoder.encode(scope, StandardCharsets.UTF_8);
String kakaoLoginUrl = authBaseUrl +
"?response_type=code" +
"&client_id=" + clientId +
"&redirect_uri=" + encodedRedirectUri +
"&scope=" + encodedScope;

response.sendRedirect(kakaoLoginUrl.toString());
response.sendRedirect(kakaoLoginUrl);
}

@GetMapping("/callback")
@Operation(summary = "Kakao login callback", description = "Handles the callback after Kakao login", tags = { "Kakao Authentication System" })
public ResponseEntity<String> callback(
@Parameter(description = "Authorization code from Kakao", required = false)
@Parameter(description = "Authorization code from Kakao")
@RequestParam(required = false) String code) {
if (code == null || code.isEmpty()) {
return ResponseEntity.badRequest().body("Authorization code is missing");
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/gift/controller/OptionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import gift.dto.option.OptionResponse;
import gift.dto.option.OptionUpdateResponse;
import gift.entity.Option;
import gift.exception.CustomException;
import gift.service.OptionService;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -47,8 +49,7 @@ public ResponseEntity<OptionResponse> addOptionToProduct(
UriComponentsBuilder uriBuilder) {
Option option = optionService.addOptionToProduct(productId, optionRequest);
OptionResponse response = new OptionResponse(option.getId(), option.getName(), option.getQuantity());
URI location = uriBuilder.path("/api/products/{productId}/options/{optionId}")
.buildAndExpand(productId, option.getId()).toUri();
URI location = uriBuilder.path("/api/products/{productId}/options/{optionId}").buildAndExpand(productId, option.getId()).toUri();
return ResponseEntity.created(location).body(response);
}

Expand All @@ -72,8 +73,15 @@ public ResponseEntity<String> deleteOption(
@PathVariable Long optionId,
@Parameter(description = "ID of the product", required = true)
@RequestBody DeleteOptionRequest deleteOptionRequest) {
optionService.deleteOption(optionId, deleteOptionRequest.getEmail(), deleteOptionRequest.getPassword());
return ResponseEntity.ok("Option successfully deleted.");
try {
optionService.deleteOption(optionId, deleteOptionRequest.getEmail(), deleteOptionRequest.getPassword());
return ResponseEntity.ok("Option successfully deleted.");
} catch (CustomException.EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
} catch (CustomException.InvalidPasswordException e) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage());
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred: " + e.getMessage());
}
}
}

26 changes: 20 additions & 6 deletions src/main/java/gift/controller/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import gift.dto.order.OrderRequest;
import gift.dto.order.OrderResponse;
import gift.dto.point.PointRequest;
import gift.dto.point.PointResponse;
import gift.service.OrderService;
import gift.service.PointService;
import gift.util.JwtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,13 +27,16 @@
@Tag(name = "Order Management System", description = "Operations related to order management")
public class OrderController {
private final OrderService orderService;
private final PointService pointService;
private final JwtUtil jwtUtil;
private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

public OrderController(OrderService orderService, JwtUtil jwtUtil) {
public OrderController(OrderService orderService, PointService pointService, JwtUtil jwtUtil) {
this.orderService = orderService;
this.pointService = pointService;
this.jwtUtil = jwtUtil;
}

@GetMapping
@Operation(summary = "Get all orders for the logged-in user", description = "Fetches all orders made by the logged-in user", tags = {"Order Management System"})
public ResponseEntity<Page<OrderResponse>> getOrders(
Expand Down Expand Up @@ -61,12 +67,10 @@ public ResponseEntity<Page<OrderResponse>> getOrders(
}

@PostMapping
@Operation(summary = "Place an order", description = "Places a new order in the system", tags = { "Order Management System" })
@Operation(summary = "Place an order", description = "Places a new order in the system", tags = {"Order Management System"})
public ResponseEntity<OrderResponse> placeOrder(
@Parameter(description = "Order details", required = true)
@RequestBody OrderRequest orderRequest,
@Parameter(description = "Authorization token", required = true)
@RequestHeader("Authorization") String authorizationHeader) {
@Parameter(description = "Order details", required = true) @RequestBody OrderRequest orderRequest,
@Parameter(description = "Authorization token", required = true) @RequestHeader("Authorization") String authorizationHeader) {
logger.info("Received request to place order");
logger.info("Server current time: {}", Instant.now().getEpochSecond());

Expand Down Expand Up @@ -97,10 +101,20 @@ public ResponseEntity<OrderResponse> placeOrder(
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new OrderResponse("Failed to extract email from token"));
}

// Check if points should be used
if (orderRequest.isUsePoints()) {
PointRequest pointRequest = new PointRequest(orderRequest.getProductId(), orderRequest.getOptionId(), orderRequest.getQuantity(), email);
PointResponse pointResponse = pointService.usePoints(pointRequest);
if (pointResponse.getMessage() != null && pointResponse.getMessage().contains("Insufficient points")) {
return ResponseEntity.badRequest().body(new OrderResponse("Insufficient points to complete the order"));
}
}

OrderRequest newOrderRequest = new OrderRequest(
orderRequest.getProductId(),
orderRequest.getOptionId(),
orderRequest.getQuantity(),
orderRequest.isUsePoints(),
orderRequest.getMessage(),
LocalDateTime.now(),
email
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/gift/controller/PointController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gift.controller;

import gift.dto.point.PointRequest;
import gift.dto.point.PointResponse;
import gift.service.PointService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/members")
@Tag(name = "Point Management System", description = "Operations related to point management")
public class PointController {
private final PointService pointService;

@Autowired
public PointController(PointService pointService) {
this.pointService = pointService;
}

@GetMapping("/points")
@Operation(summary = "Get member's points", description = "Fetches the points balance for a member")
public ResponseEntity<PointResponse> getPoints(@RequestParam Long memberId) {
PointResponse pointResponse = pointService.getPoints(memberId);
return ResponseEntity.ok(pointResponse);
}

@PostMapping("/points")
@Operation(summary = "Add points to a member", description = "Adds points to a member")
public ResponseEntity<PointResponse> addPoints(@RequestBody PointRequest pointRequest) {
PointResponse pointResponse = pointService.addPoint(pointRequest);
return ResponseEntity.ok(pointResponse);
}
}
1 change: 1 addition & 0 deletions src/main/java/gift/controller/WishController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/gift/dto/OptionRequest.java

This file was deleted.

Loading