Skip to content

Commit b55ff35

Browse files
authored
Merge pull request #14 from AlgorithmChef/feature/frontend_integration
Feature/frontend integration ocr 부분 제외하고 모든 거 통합 완료
2 parents 29e7ac8 + 1d19193 commit b55ff35

19 files changed

Lines changed: 182 additions & 130 deletions

src/main/java/com/webservice/algorithmchef/config/GeminiConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.webservice.algorithmchef.config;
22

3-
import com.google.genai.Client;
43
import org.springframework.beans.factory.annotation.Value;
54
import org.springframework.context.annotation.Bean;
65
import org.springframework.context.annotation.Configuration;
76

7+
import com.google.genai.Client;
8+
9+
810
@Configuration
911
public class GeminiConfig {
1012

src/main/java/com/webservice/algorithmchef/config/JwtAuthenticationFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
4747

4848
// 1. JWT 헤더가 없거나 'Bearer'가 아닌 경우
4949
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
50-
log.warn("Authorization 헤더가 없거나 Bearer 타입이 아님");
50+
log.debug("헤더에 토큰이 없어 비로그인 상태로 다음 필터 진행: {}", request.getRequestURI());
5151
filterChain.doFilter(request, response);
5252
return;
5353
}

src/main/java/com/webservice/algorithmchef/config/SecurityConfig.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package com.webservice.algorithmchef.config;
22

3+
import java.util.List;
4+
35
import org.springframework.context.annotation.Bean;
46
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.http.HttpMethod;
58
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
69
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
710
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
811
import org.springframework.security.config.http.SessionCreationPolicy;
912
import org.springframework.security.web.SecurityFilterChain;
1013
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
11-
12-
14+
import org.springframework.web.cors.CorsConfiguration;
15+
import org.springframework.web.cors.CorsConfigurationSource;
16+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
1317

1418
import lombok.RequiredArgsConstructor;
1519

@@ -24,6 +28,7 @@ public class SecurityConfig {
2428
@Bean
2529
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
2630
http
31+
.cors(org.springframework.security.config.Customizer.withDefaults())
2732
.csrf(AbstractHttpConfigurer::disable)
2833
.httpBasic(AbstractHttpConfigurer::disable)
2934
.formLogin(AbstractHttpConfigurer::disable);
@@ -36,12 +41,30 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3641
.authorizeHttpRequests(authorize -> authorize
3742
.requestMatchers("/auth/login", "/auth/signUp",
3843
"/auth/findPassword", "/auth/findUserId").permitAll()
44+
//.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
3945
.anyRequest().authenticated());
4046

4147
http
4248
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
4349

4450
return http.build();
4551
}
52+
53+
// @Bean
54+
// public CorsConfigurationSource corsConfigurationSource() {
55+
// CorsConfiguration configuration = new CorsConfiguration();
56+
//
57+
// // 1. 프론트엔드 포트 확인! (5173인지 3000인지 본인 환경에 맞춰주세요)
58+
// // 둘 다 넣어두면 안전합니다.
59+
// configuration.setAllowedOrigins(List.of("http://localhost:5173"));
60+
//
61+
// configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
62+
// configuration.setAllowedHeaders(List.of("*"));
63+
// configuration.setAllowCredentials(true);
64+
//
65+
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
66+
// source.registerCorsConfiguration("/**", configuration);
67+
// return source;
68+
// }
4669

4770
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.webservice.algorithmchef.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6+
7+
@Configuration
8+
public class WebConfig implements WebMvcConfigurer {
9+
10+
@Override
11+
public void addCorsMappings(CorsRegistry registry) {
12+
registry.addMapping("/**")
13+
.allowedOrigins("http://localhost:5173")
14+
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH");
15+
//.allowCredentials(true);
16+
}
17+
18+
}

src/main/java/com/webservice/algorithmchef/controller/AuthController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public ResponseEntity<?> signUp(@RequestBody UserSignUpRequest userSignUpRequest
5353
}
5454
}
5555

56-
@Transactional
5756
@PatchMapping("/findPassword")
5857
public ResponseEntity<?> findPassword(@RequestBody FindPasswordRequest fPasswordRequest){
5958
try {

src/main/java/com/webservice/algorithmchef/controller/BoardController.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public class BoardController {
2727
// 게시글 목록 조회(게시판)
2828
@GetMapping("/posts")
2929
public ResponseEntity<BoardPostListResponse> getPostList(
30-
@RequestParam(defaultValue = "0") int page,
31-
@RequestParam(defaultValue = "20") int size,
32-
@RequestParam(defaultValue = "createdAt,desc") String sort,
33-
@RequestParam(required = false) String filter
30+
@RequestParam(defaultValue = "0",value="page") int page,
31+
@RequestParam(defaultValue = "20",value="size") int size,
32+
@RequestParam(defaultValue = "createdAt,desc",value="sort") String sort,
33+
@RequestParam(required = false,value="filter") String filter
3434
) {
3535
BoardPostListResponse response = boardService.getPostList(page, size, sort, filter);
3636
return ResponseEntity.ok(response);
@@ -55,10 +55,10 @@ public ResponseEntity<Map<String, String>> createPost(
5555
// 게시글 조회
5656
@GetMapping("/post/{postId}")
5757
public ResponseEntity<BoardPostResponse> getPostDetail(
58-
@PathVariable Long postId,
59-
@RequestParam(defaultValue = "0") int page,
60-
@RequestParam(defaultValue = "20") int size,
61-
@RequestParam(defaultValue = "createdAt,asc") String sort
58+
@PathVariable("postId") Long postId,
59+
@RequestParam(defaultValue = "0",value="page") int page,
60+
@RequestParam(defaultValue = "20",value="size") int size,
61+
@RequestParam(defaultValue = "createdAt,asc",value="sort") String sort
6262
) {
6363
try {
6464
BoardPostResponse response = boardService.getPostDetail(postId, page, size, sort);
@@ -71,7 +71,7 @@ public ResponseEntity<BoardPostResponse> getPostDetail(
7171
// 댓글 작성
7272
@PostMapping("/post/{postId}/comment")
7373
public ResponseEntity<Map<String, String>> createComment(
74-
@PathVariable Long postId,
74+
@PathVariable("postId") Long postId,
7575
@RequestBody BoardCommentRequest requestDto,
7676
@AuthenticationPrincipal UserDetails userDetails
7777
) {
@@ -91,10 +91,10 @@ public ResponseEntity<Map<String, String>> createComment(
9191
// 대댓글 조회
9292
@GetMapping("/comments/{commentId}/replies")
9393
public ResponseEntity<CommentReplyListResponse> getReplies(
94-
@PathVariable Long commentId,
95-
@RequestParam(defaultValue = "0") int page,
96-
@RequestParam(defaultValue = "20") int size,
97-
@RequestParam(defaultValue = "createdAt,asc") String sort
94+
@PathVariable("commentId") Long commentId,
95+
@RequestParam(defaultValue = "0",value="page") int page,
96+
@RequestParam(defaultValue = "10",value="size") int size,
97+
@RequestParam(defaultValue = "createdAt,asc",value="sort") String sort
9898
) {
9999
try {
100100
CommentReplyListResponse response = boardService.getReplies(commentId, page, size, sort);
@@ -107,7 +107,7 @@ public ResponseEntity<CommentReplyListResponse> getReplies(
107107
// 게시글 수정
108108
@PutMapping("/post/{postId}")
109109
public ResponseEntity<Map<String, String>> updatePost(
110-
@PathVariable Long postId,
110+
@PathVariable("postId") Long postId,
111111
@RequestBody BoardPostRequest requestDto,
112112
@AuthenticationPrincipal UserDetails userDetails
113113
) {
@@ -133,7 +133,7 @@ public ResponseEntity<Map<String, String>> updatePost(
133133
// 게시글 삭제
134134
@DeleteMapping("/post/{postId}")
135135
public ResponseEntity<Map<String, String>> deletePost(
136-
@PathVariable Long postId,
136+
@PathVariable("postId") Long postId,
137137
@AuthenticationPrincipal UserDetails userDetails
138138
) {
139139
if (userDetails == null) {

src/main/java/com/webservice/algorithmchef/controller/GeminiRecipeController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public ResponseEntity<List<GeminiRecipeResponse>> recommendCondition(@RequestBod
4343
@PostMapping("/expir")
4444
public ResponseEntity<List<GeminiRecipeResponse>> recommendExpir(@RequestBody ExpirRequest request) {
4545
log.info("재료 추천 요청 - userId: {}", request.userId());
46+
log.info("요청한 재료",request);
4647
return ResponseEntity.ok(
4748
recipeService.recommendExpir(request.userId(), request.ingredients(), request.excludedTitles())
4849
);

src/main/java/com/webservice/algorithmchef/controller/RecipeSearchController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@RestController
1212
@RequestMapping("/api/recipes")
13-
@CrossOrigin(origins = "http://localhost:3000")
13+
//@CrossOrigin(origins = "http://localhost:3000")
1414
public class RecipeSearchController {
1515

1616
private final RecipeService recipeService;
@@ -20,7 +20,7 @@ public RecipeSearchController(RecipeService recipeService) {
2020
}
2121

2222
@GetMapping("/search")
23-
public ResponseEntity<?> getRandomRecipe(@RequestParam String ingredient) {
23+
public ResponseEntity<?> getRandomRecipe(@RequestParam("ingredient") String ingredient) {
2424

2525
Recipe recipe = recipeService.getRandomRecipeByIngredient(ingredient);
2626

@@ -32,7 +32,7 @@ public ResponseEntity<?> getRandomRecipe(@RequestParam String ingredient) {
3232
}
3333

3434
@GetMapping("/search-multi")
35-
public ResponseEntity<?> getRandomRecipeMultiple(@RequestParam String ingredients) {
35+
public ResponseEntity<?> getRandomRecipeMultiple(@RequestParam("ingredients") String ingredients) {
3636

3737
List<String> ingList =
3838
Arrays.stream(ingredients.split(","))

src/main/java/com/webservice/algorithmchef/controller/SttController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@Slf4j
1717
@RestController
1818
@RequestMapping("/api")
19-
@CrossOrigin(origins = "http://localhost:3000")
19+
//@CrossOrigin(origins = "http://localhost:3000")
2020
@RequiredArgsConstructor
2121
public class SttController {
2222

src/main/java/com/webservice/algorithmchef/controller/UserFridgeController.java

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.webservice.algorithmchef.dto.fridgeingredient.ChangeFridgeIngredientRequest;
1818
import com.webservice.algorithmchef.dto.fridgeingredient.ChangeFridgeIngredientResponse;
1919
import com.webservice.algorithmchef.dto.userfridge.FridgeBatchUpdateRequest;
20-
import com.webservice.algorithmchef.dto.userfridge.PageUserFridgeResponse;
2120
import com.webservice.algorithmchef.dto.userfridge.UserFridgeRequest;
2221
import com.webservice.algorithmchef.dto.userfridge.UserFridgeResponse;
2322
import com.webservice.algorithmchef.service.UserFridgeService;
@@ -44,28 +43,22 @@ public ResponseEntity<?> registerIngredients(@RequestBody UserFridgeRequest frid
4443
}
4544

4645
@GetMapping("/ingredients")
47-
public ResponseEntity<?> retrieve(
48-
@RequestParam(value="category",required = false)String category,
49-
@RequestParam(value="name",required = false)String name,
50-
@RequestParam(value="page", defaultValue = "0")int page,
51-
@RequestParam(value="size", defaultValue = "10")int size,
52-
@AuthenticationPrincipal UserDetails userDetails){
53-
try {
54-
String userId = userDetails.getUsername();
55-
PageUserFridgeResponse response = null;
56-
if(category != null) {
57-
response = userFridgeService.filteredByCategory(userId, category, size, page);
58-
}else if(name != null) {
59-
response = userFridgeService.filteredByName(userId, name, size, page);
60-
}else {
61-
response = userFridgeService.retrieveAll(userId, size, page);
62-
}
63-
return ResponseEntity.ok(response);
64-
}catch(IllegalArgumentException e) {
65-
return ResponseEntity.badRequest().body(e.getMessage());
66-
}
67-
68-
}
46+
public ResponseEntity<?> retrieve(
47+
@RequestParam(value = "category", required = false) String category,
48+
@AuthenticationPrincipal UserDetails userDetails) {
49+
try {
50+
String userId = userDetails.getUsername();
51+
UserFridgeResponse response;
52+
if (category != null) {
53+
response = userFridgeService.filteredByCategory(userId, category);
54+
} else {
55+
response = userFridgeService.retrieveAll(userId);
56+
}
57+
return ResponseEntity.ok(response);
58+
} catch (IllegalArgumentException e) {
59+
return ResponseEntity.badRequest().body(e.getMessage());
60+
}
61+
}
6962

7063
@PatchMapping("/ingredient/update")
7164
public ResponseEntity<?> updatePurchasedDate(@RequestBody ChangeFridgeIngredientRequest request,

0 commit comments

Comments
 (0)