Compare commits
3 Commits
98c89f6247
...
ca926d9ada
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca926d9ada | ||
|
|
9c5b9a7150 | ||
|
|
7f7714b7a3 |
@ -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)
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user