Skip to content

Commit f527cde

Browse files
committed
update database
1 parent b59bed0 commit f527cde

16 files changed

Lines changed: 226 additions & 248 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.webservice.algorithmchef.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.mail.javamail.JavaMailSender;
6+
import org.springframework.mail.javamail.JavaMailSenderImpl;
7+
8+
@Configuration
9+
public class MailConfig {
10+
11+
@Bean
12+
public JavaMailSender javaMailSender() {
13+
// 실제 SMTP 설정 없이 빈만 등록하는 임시 설정
14+
return new JavaMailSenderImpl();
15+
}
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.webservice.algorithmchef.controller;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
6+
import org.springframework.security.core.userdetails.UserDetails;
7+
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestBody;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import com.webservice.algorithmchef.dto.recipereview.RecipeReviewRequest;
12+
import com.webservice.algorithmchef.dto.recipereview.RecipeReviewResponse;
13+
import com.webservice.algorithmchef.service.RecipeReviewService;
14+
15+
import lombok.RequiredArgsConstructor;
16+
17+
@RestController
18+
@RequiredArgsConstructor
19+
public class RecipeReviewController {
20+
21+
private final RecipeReviewService rService;
22+
23+
@PostMapping("/recipe/review")
24+
public ResponseEntity<?> makeReview(@RequestBody RecipeReviewRequest request,
25+
@AuthenticationPrincipal UserDetails userDetails){
26+
try {
27+
String userId = userDetails.getUsername();
28+
RecipeReviewResponse response = rService.makeReview(request, userId);
29+
return ResponseEntity.status(HttpStatus.CREATED).body(response);
30+
}catch (IllegalArgumentException e) {
31+
return ResponseEntity.badRequest().body(e.getMessage());
32+
}
33+
}
34+
35+
}

src/main/java/com/webservice/algorithmchef/dto/recipe/CookRcpResponse.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ public String getName() {
9090
return name;
9191
}
9292

93-
public String[] getParts() {
94-
if (parts == null || parts.isBlank()) {
95-
return new String[0]; // 빈 배열 반환
96-
}
97-
return parts.split("[,\\n]+");
93+
public String getParts() {
94+
return parts;
9895
}
9996

10097
public String getImageUrl() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.webservice.algorithmchef.dto.recipereview;
2+
3+
import lombok.Getter;
4+
import lombok.NoArgsConstructor;
5+
6+
@Getter
7+
@NoArgsConstructor
8+
public class RecipeReviewRequest {
9+
10+
private String name;
11+
private float rating;
12+
private String content;
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.webservice.algorithmchef.dto.recipereview;
2+
3+
import com.webservice.algorithmchef.model.RecipeReview;
4+
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
@Getter
9+
@NoArgsConstructor
10+
public class RecipeReviewResponse {
11+
12+
private String name;
13+
private String userId;
14+
private float rating;
15+
16+
public RecipeReviewResponse(RecipeReview review) {
17+
this.name = review.getRecipe().getName();
18+
this.userId = review.getUser().getUserId();
19+
this.rating = review.getRating();
20+
}
21+
}

src/main/java/com/webservice/algorithmchef/model/Ingredient.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,4 @@ public class Ingredient {
4646
@OneToMany(mappedBy = "ingredient",orphanRemoval = true,cascade = CascadeType.ALL)
4747
private List<FridgeIngredient> ingredients;
4848

49-
@OneToMany(mappedBy = "ingredient",orphanRemoval = true,cascade = CascadeType.ALL)
50-
private List<RecipeIngredient> recipeIngredients;
51-
5249
}

src/main/java/com/webservice/algorithmchef/model/Recipe.java

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,46 @@
2525
@ToString
2626
public class Recipe {
2727

28-
@Id
29-
@GeneratedValue(strategy = GenerationType.IDENTITY)
30-
@Column(name="recipe_id")
31-
private Long id;
32-
33-
@Column(nullable = false, unique = true)
34-
private String name;
35-
36-
@Lob
37-
private String description;
28+
@Id
29+
@GeneratedValue(strategy = GenerationType.IDENTITY)
30+
@Column(name="recipe_id")
31+
private Long id;
32+
33+
@Column(nullable = false)
34+
private String name;
35+
36+
@Lob
37+
private String description;
3838

3939
@Lob
40-
@Column(nullable = false, columnDefinition = "LONGTEXT")
40+
@Column(nullable = false)
4141
private String instructions;
4242

4343
private String imageUrl;
44-
45-
@Column(nullable = false)
46-
private String type;
47-
48-
@Column(nullable = false)
49-
private double kcal;
50-
51-
@OneToMany(mappedBy = "recipe", orphanRemoval = true)
52-
private List<RecipeTag> recipeTags;
53-
54-
@OneToMany(mappedBy = "recipe", orphanRemoval = true)
55-
private List<RecipeIngredient> recipeIngredients;
56-
57-
@OneToMany(mappedBy = "recipe", orphanRemoval = true)
58-
private List<RecipeReview> recipeReviews;
59-
60-
}
44+
45+
@Column(nullable = false)
46+
private String type;
47+
48+
@Lob
49+
@Column(name = "needed_ingredients", columnDefinition = "TEXT")
50+
private String neededIngredients;
51+
52+
@Column(nullable = false)
53+
private double kcal;
54+
55+
@Column
56+
private String tag;
57+
58+
@Column
59+
private String portions;
60+
61+
@Column
62+
private String time;
63+
64+
@Column
65+
private String tip;
66+
67+
@OneToMany(mappedBy = "recipe", orphanRemoval = true)
68+
private List<RecipeReview> recipeReviews;
69+
70+
}

src/main/java/com/webservice/algorithmchef/model/RecipeIngredient.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/main/java/com/webservice/algorithmchef/model/RecipeReview.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import jakarta.persistence.GenerationType;
1212
import jakarta.persistence.Id;
1313
import jakarta.persistence.JoinColumn;
14+
import jakarta.persistence.Lob;
1415
import jakarta.persistence.ManyToOne;
1516
import lombok.AllArgsConstructor;
1617
import lombok.Builder;
@@ -28,23 +29,27 @@
2829
@ToString
2930
public class RecipeReview {
3031

31-
@Id
32-
@GeneratedValue(strategy = GenerationType.IDENTITY)
33-
@Column(name="review_id")
34-
private Long id;
35-
36-
@ManyToOne(fetch = FetchType.LAZY)
37-
@JoinColumn(name="user_id")
38-
private User user;
39-
40-
@ManyToOne(fetch = FetchType.LAZY)
41-
@JoinColumn(name="recipe_id")
42-
private Recipe recipe;
43-
44-
@Column(nullable = false)
45-
private float rating;
46-
47-
@CreationTimestamp
48-
private LocalDateTime createdAt;
49-
50-
}
32+
@Id
33+
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@Column(name="review_id")
35+
private Long id;
36+
37+
@ManyToOne(fetch = FetchType.LAZY)
38+
@JoinColumn(name="user_id")
39+
private User user;
40+
41+
@ManyToOne(fetch = FetchType.LAZY)
42+
@JoinColumn(name="recipe_id")
43+
private Recipe recipe;
44+
45+
@Column(nullable = false)
46+
private float rating;
47+
48+
@Column
49+
@Lob
50+
private String content;
51+
52+
@CreationTimestamp
53+
private LocalDateTime createdAt;
54+
55+
}

src/main/java/com/webservice/algorithmchef/model/RecipeTag.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)