Compare commits

..

No commits in common. "ca926d9adad69585d740fecd616b85d1a86206fb" and "98c89f6247fb9a039d75b82895d517b7900cf8b8" have entirely different histories.

4 changed files with 7 additions and 20 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(
put("/recipes/{username}/{slug}", owner.getUsername(), recipe.getSlug()) post("/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(
put("/recipes/{username}/{slug}", owner.getUsername(), recipe.getSlug()) post("/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 var b = RecipeCreateSpec.builder() final RecipeCreateSpec spec = RecipeCreateSpec.builder()
.slug(recipeDraft.getSlug()) .slug(recipeDraft.getSlug())
.title(recipeDraft.getTitle()) .title(recipeDraft.getTitle())
.preparationTime(recipeDraft.getPreparationTime()) .preparationTime(recipeDraft.getPreparationTime())
@ -376,21 +376,8 @@ 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));
} }
@PutMapping("/{username}/{slug}") @PostMapping("/{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;
@Nullable OffsetDateTime modified; OffsetDateTime modified;
String slug; String slug;
String title; String title;
@Nullable Integer preparationTime; @Nullable Integer preparationTime;