Skip to content

Commit 321292f

Browse files
authored
Merge pull request #63 from Team-Meal/fix-59-validate-ai-meal-callback
[meal] AI 급식 콜백 요청 검증 추가
2 parents 15ba7ee + 47f6977 commit 321292f

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎src/main/kotlin/team/nongchun/hororog/domain/meal/controller/MealController.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ class MealController(
120120
)
121121
@PostMapping
122122
fun createAiMeal(
123-
@RequestBody request: CreateAiMealRequest,
123+
@Valid @RequestBody request: CreateAiMealRequest,
124124
): ResponseEntity<Any> = ResponseEntity.ok(mapOf("id" to createAiMealService.execute(request)))
125125
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package team.nongchun.hororog.domain.meal.dto
22

33
import com.fasterxml.jackson.annotation.JsonProperty
4+
import jakarta.validation.constraints.DecimalMin
5+
import jakarta.validation.constraints.NotBlank
46

57
data class CreateAiMealRequest(
68
@JsonProperty("diet_id")
79
val dietId: Long,
810
@JsonProperty("menu_name")
11+
@field:NotBlank
912
val menuName: String,
13+
@field:DecimalMin("0.0")
1014
val kcal: Double,
15+
@field:DecimalMin("0.0")
1116
val protein: Double,
17+
@field:DecimalMin("0.0")
1218
val fat: Double,
19+
@field:DecimalMin("0.0")
1320
val sodium: Double,
1421
)

‎src/test/kotlin/team/nongchun/hororog/domain/meal/controller/MealControllerTest.kt‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,52 @@ class MealControllerTest
176176
status { isForbidden() }
177177
}
178178
}
179+
180+
@Test
181+
fun `AI 급식 콜백의 메뉴명이 비어 있으면 400을 반환한다`() {
182+
val nutritionist = saveMember(Role.NUTRITIONIST, "nutritionist@hororog.team")
183+
184+
mockMvc
185+
.post("/meals") {
186+
header(HttpHeaders.AUTHORIZATION, "Bearer ${accessToken(nutritionist)}")
187+
contentType = MediaType.APPLICATION_JSON
188+
content =
189+
"""
190+
{
191+
"diet_id": 1,
192+
"menu_name": "",
193+
"kcal": 100.0,
194+
"protein": 10.0,
195+
"fat": 5.0,
196+
"sodium": 300.0
197+
}
198+
""".trimIndent()
199+
}.andExpect {
200+
status { isBadRequest() }
201+
}
202+
}
203+
204+
@Test
205+
fun `AI 급식 콜백의 영양값이 음수이면 400을 반환한다`() {
206+
val nutritionist = saveMember(Role.NUTRITIONIST, "nutritionist@hororog.team")
207+
208+
mockMvc
209+
.post("/meals") {
210+
header(HttpHeaders.AUTHORIZATION, "Bearer ${accessToken(nutritionist)}")
211+
contentType = MediaType.APPLICATION_JSON
212+
content =
213+
"""
214+
{
215+
"diet_id": 1,
216+
"menu_name": "현미밥",
217+
"kcal": -1.0,
218+
"protein": 10.0,
219+
"fat": 5.0,
220+
"sodium": 300.0
221+
}
222+
""".trimIndent()
223+
}.andExpect {
224+
status { isBadRequest() }
225+
}
226+
}
179227
}

0 commit comments

Comments
 (0)