Add endpoint for creating ai recipe draft.
This commit is contained in:
parent
7f985f3434
commit
b19dc42094
@ -42,7 +42,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@ExtendWith(IntegrationTestsExtension.class)
|
||||
public class RecipeControllerTests {
|
||||
public class RecipesControllerTests {
|
||||
|
||||
@Container
|
||||
private static final MinIOContainer container = new MinIOContainer(
|
||||
@ -0,0 +1,45 @@
|
||||
package app.mealsmadeeasy.api.recipe;
|
||||
|
||||
import app.mealsmadeeasy.api.file.File;
|
||||
import app.mealsmadeeasy.api.file.FileService;
|
||||
import app.mealsmadeeasy.api.user.User;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/recipe-drafts")
|
||||
@RequiredArgsConstructor
|
||||
public class RecipeDraftsController {
|
||||
|
||||
private final RecipeService recipeService;
|
||||
private final FileService fileService;
|
||||
|
||||
@PutMapping("/ai")
|
||||
public ResponseEntity<RecipeDraft> createRecipeDraft(
|
||||
@AuthenticationPrincipal User owner,
|
||||
@RequestParam MultipartFile sourceFile,
|
||||
@RequestParam String sourceFileName
|
||||
) throws IOException {
|
||||
if (owner == null) {
|
||||
throw new IllegalArgumentException("Must be logged in to create a RecipeDraft.");
|
||||
}
|
||||
final File file = this.fileService.create(
|
||||
sourceFile.getInputStream(),
|
||||
sourceFileName,
|
||||
sourceFile.getSize(),
|
||||
owner
|
||||
);
|
||||
final RecipeDraft recipeDraft = this.recipeService.createAiDraft(file, owner);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(recipeDraft);
|
||||
}
|
||||
|
||||
}
|
||||
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/recipes")
|
||||
public class RecipeController {
|
||||
public class RecipesController {
|
||||
|
||||
private final RecipeService recipeService;
|
||||
private final RecipeStarService recipeStarService;
|
||||
@ -40,7 +40,7 @@ public class RecipeController {
|
||||
private final SliceViewService sliceViewService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public RecipeController(
|
||||
public RecipesController(
|
||||
RecipeService recipeService,
|
||||
RecipeStarService recipeStarService,
|
||||
RecipeCommentService recipeCommentService,
|
||||
@ -10,7 +10,7 @@ spring.datasource.password=${POSTGRES_PASSWORD}
|
||||
spring.datasource.hikari.auto-commit=false
|
||||
|
||||
app.mealsmadeeasy.api.baseUrl=http://localhost:8080
|
||||
app.mealsmadeeasy.api.security.access-token-lifetime=60
|
||||
app.mealsmadeeasy.api.security.access-token-lifetime=300
|
||||
app.mealsmadeeasy.api.security.refresh-token-lifetime=3600
|
||||
app.mealsmadeeasy.api.minio.endpoint=http://${MINIO_HOST:localhost}:${MINIO_PORT:9000}
|
||||
app.mealsmadeeasy.api.minio.accessKey=${MINIO_ROOT_USER}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user