Compare commits
2 Commits
ba40c48719
...
d1df876bb3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1df876bb3 | ||
|
|
c8e660b596 |
@ -139,7 +139,6 @@ public class ImageControllerTests {
|
||||
.header("Authorization", "Bearer " + this.getAccessToken(owner))
|
||||
)
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.count").value(1))
|
||||
.andExpect(jsonPath("$.content").isArray())
|
||||
.andExpect(jsonPath("$.content").isNotEmpty())
|
||||
.andExpect(jsonPath("$.content[0].url").isNotEmpty())
|
||||
|
||||
@ -182,7 +182,6 @@ public class RecipesControllerTests {
|
||||
final Recipe recipe = this.createTestRecipe(owner, true);
|
||||
this.mockMvc.perform(get("/recipes"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.count").isNotEmpty())
|
||||
.andExpect(jsonPath("$.slice.number").value(0))
|
||||
.andExpect(jsonPath("$.slice.size").value(20))
|
||||
.andExpect(jsonPath("$.content").isArray())
|
||||
@ -201,7 +200,6 @@ public class RecipesControllerTests {
|
||||
.header("Authorization", "Bearer " + loginDetails.getAccessToken().getToken())
|
||||
)
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.count").isNotEmpty())
|
||||
.andExpect(jsonPath("$.slice.number").value(0))
|
||||
.andExpect(jsonPath("$.slice.size").value(20))
|
||||
.andExpect(jsonPath("$.content").isArray())
|
||||
|
||||
@ -5,7 +5,6 @@ import app.mealsmadeeasy.api.image.converter.ImageToViewConverter;
|
||||
import app.mealsmadeeasy.api.image.converter.ImageUpdateBodyToSpecConverter;
|
||||
import app.mealsmadeeasy.api.image.spec.ImageCreateSpec;
|
||||
import app.mealsmadeeasy.api.image.view.ImageView;
|
||||
import app.mealsmadeeasy.api.sliceview.SliceView;
|
||||
import app.mealsmadeeasy.api.sliceview.SliceViewService;
|
||||
import app.mealsmadeeasy.api.user.User;
|
||||
import app.mealsmadeeasy.api.user.UserService;
|
||||
@ -26,6 +25,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -54,16 +54,21 @@ public class ImageController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<SliceView<ImageView>> getOwnedImages(
|
||||
public ResponseEntity<Object> getOwnedImages(
|
||||
@AuthenticationPrincipal User principal,
|
||||
@RequestParam(name = "count", defaultValue = "false") boolean doCount,
|
||||
Pageable pageable
|
||||
) {
|
||||
if (doCount) {
|
||||
final int count = this.imageService.countOwnedImages(principal);
|
||||
return ResponseEntity.ok(Map.of("count", count));
|
||||
} else {
|
||||
final Slice<Image> images = this.imageService.getOwnedImages(principal, pageable);
|
||||
final Slice<ImageView> imageViews = images.map(image ->
|
||||
this.imageToViewConverter.convert(image, principal, false)
|
||||
);
|
||||
final int count = this.imageService.countOwnedImages(principal);
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(imageViews, count));
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(imageViews));
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{username}/{filename}")
|
||||
|
||||
@ -88,15 +88,13 @@ public class RecipesController {
|
||||
final Slice<RecipeInfoView> publicRecipeInfoViews = publicRecipes.map(
|
||||
recipe -> this.recipeToInfoViewConverter.convert(recipe, null)
|
||||
);
|
||||
final int count = this.recipeService.countPublicRecipes();
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(publicRecipeInfoViews, count));
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(publicRecipeInfoViews));
|
||||
} else {
|
||||
final Slice<Recipe> recipes = this.recipeService.getViewableBy(pageable, user);
|
||||
final Slice<RecipeInfoView> recipeInfoViews = recipes.map(
|
||||
recipe -> this.recipeToInfoViewConverter.convert(recipe, user)
|
||||
);
|
||||
final int count = this.recipeService.countViewableBy(user);
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(recipeInfoViews, count));
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(recipeInfoViews));
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,8 +164,7 @@ public class RecipesController {
|
||||
pageable,
|
||||
principal
|
||||
);
|
||||
final int count = this.recipeCommentService.countComments(username, slug);
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(slice, count));
|
||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(slice));
|
||||
}
|
||||
|
||||
@PostMapping("/{username}/{slug}/comments")
|
||||
|
||||
@ -2,7 +2,7 @@ package app.mealsmadeeasy.api.sliceview;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record SliceView<T>(List<T> content, SliceViewMeta slice, Integer count) {
|
||||
public record SliceView<T>(List<T> content, SliceViewMeta slice) {
|
||||
|
||||
public record SliceViewMeta(Integer size, Integer number, Boolean hasNext) {}
|
||||
|
||||
|
||||
@ -6,13 +6,13 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class SliceViewService {
|
||||
|
||||
public <T> SliceView<T> getSliceView(Slice<T> slice, int count) {
|
||||
public <T> SliceView<T> getSliceView(Slice<T> slice) {
|
||||
final SliceView.SliceViewMeta meta = new SliceView.SliceViewMeta(
|
||||
slice.getSize(),
|
||||
slice.getNumber(),
|
||||
slice.hasNext()
|
||||
);
|
||||
return new SliceView<>(slice.getContent(), meta, count);
|
||||
return new SliceView<>(slice.getContent(), meta);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user