Skip to content

Commit e47e259

Browse files
author
bu2000
committed
some logic is changed for integration
1 parent 29e7ac8 commit e47e259

17 files changed

Lines changed: 165 additions & 115 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/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,

src/main/java/com/webservice/algorithmchef/dto/fridgeingredient/ChangeFridgeIngredientRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public class ChangeFridgeIngredientRequest {
1111

1212
private Long ingredientId;
1313
private LocalDateTime purchasedDate;
14+
private LocalDateTime expiredDate;
1415
}

0 commit comments

Comments
 (0)