Compare commits

..

3 Commits

Author SHA1 Message Date
Jesse Brault
ca926d9ada MME-14 Update recipe should be a PUT endpoint. 2026-02-15 13:49:06 -06:00
Jesse Brault
9c5b9a7150 Add missing nullable annotation. 2026-02-13 10:58:39 -06:00
Jesse Brault
7f7714b7a3 MME-9 Transfer ingredients from recipe draft to recipe create spec. 2026-02-13 10:58:00 -06:00
4 changed files with 20 additions and 7 deletions

View File

@ -254,7 +254,7 @@ public class RecipesControllerTests {
final String updateBody = this.objectMapper.writeValueAsString(spec); final String updateBody = this.objectMapper.writeValueAsString(spec);
this.mockMvc.perform( this.mockMvc.perform(
post("/recipes/{username}/{slug}", owner.getUsername(), recipe.getSlug()) put("/recipes/{username}/{slug}", owner.getUsername(), recipe.getSlug())
.header("Authorization", "Bearer " + this.getAccessToken(owner)) .header("Authorization", "Bearer " + this.getAccessToken(owner))
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(updateBody) .content(updateBody)
@ -318,7 +318,7 @@ public class RecipesControllerTests {
final String accessToken = this.getAccessToken(owner); final String accessToken = this.getAccessToken(owner);
this.mockMvc.perform( this.mockMvc.perform(
post("/recipes/{username}/{slug}", owner.getUsername(), recipe.getSlug()) put("/recipes/{username}/{slug}", owner.getUsername(), recipe.getSlug())
.header("Authorization", "Bearer " + accessToken) .header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(body) .content(body)

View File

@ -368,7 +368,7 @@ public class RecipeService {
public Recipe publishDraft(UUID draftId, User modifier) { public Recipe publishDraft(UUID draftId, User modifier) {
final RecipeDraft recipeDraft = this.recipeDraftRepository.findById(draftId) final RecipeDraft recipeDraft = this.recipeDraftRepository.findById(draftId)
.orElseThrow(() -> new NoSuchEntityWithIdException(RecipeDraft.class, draftId)); .orElseThrow(() -> new NoSuchEntityWithIdException(RecipeDraft.class, draftId));
final RecipeCreateSpec spec = RecipeCreateSpec.builder() final var b = RecipeCreateSpec.builder()
.slug(recipeDraft.getSlug()) .slug(recipeDraft.getSlug())
.title(recipeDraft.getTitle()) .title(recipeDraft.getTitle())
.preparationTime(recipeDraft.getPreparationTime()) .preparationTime(recipeDraft.getPreparationTime())
@ -376,8 +376,21 @@ public class RecipeService {
.totalTime(recipeDraft.getTotalTime()) .totalTime(recipeDraft.getTotalTime())
.rawText(recipeDraft.getRawText()) .rawText(recipeDraft.getRawText())
.isPublic(false) .isPublic(false)
.mainImage(recipeDraft.getMainImage()) .mainImage(recipeDraft.getMainImage());
.build();
if (recipeDraft.getIngredients() != null) {
b.ingredients(recipeDraft.getIngredients().stream()
.map(ingredientDraft -> RecipeCreateSpec.IngredientCreateSpec.builder()
.amount(ingredientDraft.getAmount())
.name(ingredientDraft.getName())
.notes(ingredientDraft.getNotes())
.build()
)
.toList()
);
}
final RecipeCreateSpec spec = b.build();
final Recipe recipe = this.create(recipeDraft.getOwner(), spec, true); final Recipe recipe = this.create(recipeDraft.getOwner(), spec, true);
this.recipeDraftRepository.deleteById(draftId); // delete old draft this.recipeDraftRepository.deleteById(draftId); // delete old draft
return recipe; return recipe;

View File

@ -66,7 +66,7 @@ public class RecipesController {
return ResponseEntity.ok(this.getFullViewWrapper(username, slug, view, viewer)); return ResponseEntity.ok(this.getFullViewWrapper(username, slug, view, viewer));
} }
@PostMapping("/{username}/{slug}") @PutMapping("/{username}/{slug}")
public ResponseEntity<Map<String, Object>> updateByUsernameAndSlug( public ResponseEntity<Map<String, Object>> updateByUsernameAndSlug(
@PathVariable String username, @PathVariable String username,
@PathVariable String slug, @PathVariable String slug,

View File

@ -13,7 +13,7 @@ import java.time.OffsetDateTime;
public class RecipeInfoView { public class RecipeInfoView {
Integer id; Integer id;
OffsetDateTime created; OffsetDateTime created;
OffsetDateTime modified; @Nullable OffsetDateTime modified;
String slug; String slug;
String title; String title;
@Nullable Integer preparationTime; @Nullable Integer preparationTime;