Skip to content

Commit c1bacc7

Browse files
authored
Merge pull request #90 from Decodeat/feat/89-product-delete
feat: 상품 삭제
2 parents 4b2e206 + 28f102c commit c1bacc7

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/main/java/com/DecodEat/domain/products/controller/ProductController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,10 @@ public ApiResponse<PageResponseDto<ProductSearchResponseDto.ProductPrevDto>> get
137137
return ApiResponse.onSuccess(productService.getMyLikedProducts(user, pageable));
138138
}
139139

140+
@DeleteMapping("/{productId}")
141+
@Operation(summary = "상품 삭제", description = "해당 상품과 관련된 모든 데이터가 삭제됩니다.")
142+
public ApiResponse<String> deleteProduct( @PathVariable Long productId) {
143+
return ApiResponse.onSuccess(productService.deleteProduct(productId));
144+
}
145+
140146
}

src/main/java/com/DecodEat/domain/products/service/ProductService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,9 @@ public ProductLikeResponseDTO addOrUpdateLike(Long userId, Long productId) {
454454
}
455455
return ProductConverter.toProductLikeDTO(productId, isLiked);
456456
}
457+
458+
public String deleteProduct(Long productId) {
459+
productRepository.deleteById(productId);
460+
return productId.toString()+"번 상품이 삭제되었습니다.";
461+
}
457462
}

src/main/java/com/DecodEat/global/config/WebOAuthSecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
5858
// .anyRequest().permitAll());
5959
.requestMatchers("/img/**", "/css/**", "/js/**", "/favicon.ico", "/error").permitAll()
6060
.requestMatchers("/swagger-ui/**","/v3/api-docs/**").permitAll() //누구나 가능
61-
.requestMatchers("/api/token", "/api/products/latest","/api/products/search/**","/api/products/recommendation/**").permitAll() //누구나 가능
61+
.requestMatchers("/api/token", "/api/products/latest","/api/products/search/**","/api/products/recommendation/**","api/products/").permitAll() //누구나 가능
6262
.requestMatchers(new RegexRequestMatcher("^/api/products/\\d+$", "GET")).permitAll()
63+
.requestMatchers(new RegexRequestMatcher("^/api/products/\\d+$", "DELETE")).permitAll()
6364
.requestMatchers("/api/users/**").hasAnyRole("USER", "ADMIN") // 유저 관련 API는 USER 또는 ADMIN 권한 필요
6465
.requestMatchers("/api/admin/**").hasRole("ADMIN") // 어드민 관련 API는 ADMIN 권한만 가능
6566
.anyRequest().authenticated()); // 나머지 요청은 인증 필요

0 commit comments

Comments
 (0)