From 3e4465f0e3510e6cf0dff4880c7bb3ecc1b77769 Mon Sep 17 00:00:00 2001 From: Dar Malovani Date: Tue, 9 Jan 2024 16:45:24 +0200 Subject: [PATCH] fix: tests and format, also added e2e tests --- .framework/java/backend/build.gradle | 1 + .../main/java/io/spring/api/CommentsApi.java | 15 ++--- .../src/main/java/io/spring/api/ItemApi.java | 8 +-- .../java/io/spring/api/ItemFavoriteApi.java | 13 ++--- .../src/main/java/io/spring/api/ItemsApi.java | 3 +- .../spring/application/ItemQueryService.java | 16 ++--- .../item/DuplicatedItemValidator.java | 3 +- .../application/item/ItemCommandService.java | 4 +- .../main/java/io/spring/core/item/Item.java | 6 +- .../core/service/AuthorizationService.java | 2 +- .../io/spring/graphql/CommentDatafetcher.java | 6 +- .../io/spring/graphql/CommentMutation.java | 10 ++-- .../io/spring/graphql/ItemDatafetcher.java | 24 +++----- .../java/io/spring/graphql/ItemMutation.java | 21 +++---- .../io/spring/graphql/ProfileDatafetcher.java | 6 +- .../resources/application-test.properties | 5 +- .../main/resources/mapper/ItemReadService.xml | 4 +- ...va => AnythinkMarketApplicationTests.java} | 2 + .../java/io/spring/api/CommentsApiTest.java | 28 +-------- .../test/java/io/spring/api/ItemApiTest.java | 12 ++-- .../io/spring/api/ItemFavoriteApiTest.java | 4 +- .../test/java/io/spring/api/ItemsApiTest.java | 19 +++--- .../java/io/spring/api/ListItemApiTest.java | 11 ++-- .../comment/CommentQueryServiceTest.java | 6 +- .../item/ItemQueryServiceTest.java | 18 +++--- .../application/tag/TagsQueryServiceTest.java | 2 +- .../java/io/spring/core/item/ItemTest.java | 8 +-- .../MyBatisItemFavoriteRepositoryTest.java | 3 +- .../item/ItemRepositoryTransactionTest.java | 5 +- .../item/MyBatisItemRepositoryTest.java | 5 +- .../service/DefaultJwtServiceTest.java | 3 +- .../user/MyBatisUserRepositoryTest.java | 8 +-- .github/workflows/test_e2e_java.yml | 58 +++++++++++++++++++ 33 files changed, 167 insertions(+), 172 deletions(-) rename .framework/java/backend/src/test/java/io/spring/{AythinkMarketApplicationTests.java => AnythinkMarketApplicationTests.java} (73%) create mode 100644 .github/workflows/test_e2e_java.yml diff --git a/.framework/java/backend/build.gradle b/.framework/java/backend/build.gradle index decaba7a..ed5251cd 100644 --- a/.framework/java/backend/build.gradle +++ b/.framework/java/backend/build.gradle @@ -55,6 +55,7 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:2.2.2' + testImplementation 'com.h2database:h2:1.4.200' } tasks.named('test') { diff --git a/.framework/java/backend/src/main/java/io/spring/api/CommentsApi.java b/.framework/java/backend/src/main/java/io/spring/api/CommentsApi.java index b4bc6b92..2fddac17 100644 --- a/.framework/java/backend/src/main/java/io/spring/api/CommentsApi.java +++ b/.framework/java/backend/src/main/java/io/spring/api/CommentsApi.java @@ -1,15 +1,13 @@ package io.spring.api; import com.fasterxml.jackson.annotation.JsonRootName; -import io.spring.api.exception.NoAuthorizationException; import io.spring.api.exception.ResourceNotFoundException; import io.spring.application.CommentQueryService; import io.spring.application.data.CommentData; -import io.spring.core.item.Item; -import io.spring.core.item.ItemRepository; import io.spring.core.comment.Comment; import io.spring.core.comment.CommentRepository; -import io.spring.core.service.AuthorizationService; +import io.spring.core.item.Item; +import io.spring.core.item.ItemRepository; import io.spring.core.user.User; import java.util.HashMap; import java.util.List; @@ -42,8 +40,7 @@ public ResponseEntity createComment( @PathVariable("slug") String slug, @AuthenticationPrincipal User user, @Valid @RequestBody NewCommentParam newCommentParam) { - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); Comment comment = new Comment(newCommentParam.getBody(), user.getId(), item.getId()); commentRepository.save(comment); return ResponseEntity.status(201) @@ -53,8 +50,7 @@ public ResponseEntity createComment( @GetMapping public ResponseEntity getComments( @PathVariable("slug") String slug, @AuthenticationPrincipal User user) { - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); List comments = commentQueryService.findByItemId(item.getId(), user); return ResponseEntity.ok( new HashMap() { @@ -69,8 +65,7 @@ public ResponseEntity deleteComment( @PathVariable("slug") String slug, @PathVariable("id") String commentId, @AuthenticationPrincipal User user) { - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); return commentRepository .findById(item.getId(), commentId) .map( diff --git a/.framework/java/backend/src/main/java/io/spring/api/ItemApi.java b/.framework/java/backend/src/main/java/io/spring/api/ItemApi.java index 69035e79..e679bb65 100644 --- a/.framework/java/backend/src/main/java/io/spring/api/ItemApi.java +++ b/.framework/java/backend/src/main/java/io/spring/api/ItemApi.java @@ -3,9 +3,9 @@ import io.spring.api.exception.NoAuthorizationException; import io.spring.api.exception.ResourceNotFoundException; import io.spring.application.ItemQueryService; +import io.spring.application.data.ItemData; import io.spring.application.item.ItemCommandService; import io.spring.application.item.UpdateItemParam; -import io.spring.application.data.ItemData; import io.spring.core.item.Item; import io.spring.core.item.ItemRepository; import io.spring.core.service.AuthorizationService; @@ -53,11 +53,9 @@ public ResponseEntity updateItem( if (!AuthorizationService.canWriteItem(user, item)) { throw new NoAuthorizationException(); } - Item updatedItem = - itemCommandService.updateItem(item, updateItemParam); + Item updatedItem = itemCommandService.updateItem(item, updateItemParam); return ResponseEntity.ok( - itemResponse( - itemQueryService.findBySlug(updatedItem.getSlug(), user).get())); + itemResponse(itemQueryService.findBySlug(updatedItem.getSlug(), user).get())); }) .orElseThrow(ResourceNotFoundException::new); } diff --git a/.framework/java/backend/src/main/java/io/spring/api/ItemFavoriteApi.java b/.framework/java/backend/src/main/java/io/spring/api/ItemFavoriteApi.java index 75eff6ad..a7e3e6e3 100644 --- a/.framework/java/backend/src/main/java/io/spring/api/ItemFavoriteApi.java +++ b/.framework/java/backend/src/main/java/io/spring/api/ItemFavoriteApi.java @@ -3,10 +3,10 @@ import io.spring.api.exception.ResourceNotFoundException; import io.spring.application.ItemQueryService; import io.spring.application.data.ItemData; -import io.spring.core.item.Item; -import io.spring.core.item.ItemRepository; import io.spring.core.favorite.ItemFavorite; import io.spring.core.favorite.ItemFavoriteRepository; +import io.spring.core.item.Item; +import io.spring.core.item.ItemRepository; import io.spring.core.user.User; import java.util.HashMap; import lombok.AllArgsConstructor; @@ -29,8 +29,7 @@ public class ItemFavoriteApi { @PostMapping public ResponseEntity favoriteItem( @PathVariable("slug") String slug, @AuthenticationPrincipal User user) { - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); ItemFavorite itemFavorite = new ItemFavorite(item.getId(), user.getId()); itemFavoriteRepository.save(itemFavorite); return responseItemData(itemQueryService.findBySlug(slug, user).get()); @@ -39,8 +38,7 @@ public ResponseEntity favoriteItem( @DeleteMapping public ResponseEntity unfavoriteItem( @PathVariable("slug") String slug, @AuthenticationPrincipal User user) { - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); itemFavoriteRepository .find(item.getId(), user.getId()) .ifPresent( @@ -50,8 +48,7 @@ public ResponseEntity unfavoriteItem( return responseItemData(itemQueryService.findBySlug(slug, user).get()); } - private ResponseEntity> responseItemData( - final ItemData itemData) { + private ResponseEntity> responseItemData(final ItemData itemData) { return ResponseEntity.ok( new HashMap() { { diff --git a/.framework/java/backend/src/main/java/io/spring/api/ItemsApi.java b/.framework/java/backend/src/main/java/io/spring/api/ItemsApi.java index 210c2113..e5da1ec1 100644 --- a/.framework/java/backend/src/main/java/io/spring/api/ItemsApi.java +++ b/.framework/java/backend/src/main/java/io/spring/api/ItemsApi.java @@ -54,7 +54,6 @@ public ResponseEntity getItems( @RequestParam(value = "seller", required = false) String seller, @AuthenticationPrincipal User user) { return ResponseEntity.ok( - itemQueryService.findRecentItems( - tag, seller, favoritedBy, new Page(offset, limit), user)); + itemQueryService.findRecentItems(tag, seller, favoritedBy, new Page(offset, limit), user)); } } diff --git a/.framework/java/backend/src/main/java/io/spring/application/ItemQueryService.java b/.framework/java/backend/src/main/java/io/spring/application/ItemQueryService.java index 3ac17f70..ff214bfe 100644 --- a/.framework/java/backend/src/main/java/io/spring/application/ItemQueryService.java +++ b/.framework/java/backend/src/main/java/io/spring/application/ItemQueryService.java @@ -57,8 +57,7 @@ public CursorPager findRecentItemsWithCursor( String favoritedBy, CursorPageParameter page, User currentUser) { - List itemIds = - itemReadService.findItemsWithCursor(tag, seller, favoritedBy, page); + List itemIds = itemReadService.findItemsWithCursor(tag, seller, favoritedBy, page); if (itemIds.size() == 0) { return new CursorPager<>(new ArrayList<>(), page.getDirection(), false); } else { @@ -83,8 +82,7 @@ public CursorPager findUserFeedWithCursor( if (followedUsers.size() == 0) { return new CursorPager<>(new ArrayList<>(), page.getDirection(), false); } else { - List items = - itemReadService.findItemsOfSellersWithCursor(followedUsers, page); + List items = itemReadService.findItemsOfSellersWithCursor(followedUsers, page); boolean hasExtra = items.size() > page.getLimit(); if (hasExtra) { items.remove(page.getLimit()); @@ -134,9 +132,7 @@ private void setIsFollowingSeller(List items, User currentUser) { Set followingSellers = userRelationshipQueryService.followingSellers( currentUser.getId(), - items.stream() - .map(itemData1 -> itemData1.getProfileData().getId()) - .collect(toList())); + items.stream().map(itemData1 -> itemData1.getProfileData().getId()).collect(toList())); items.forEach( itemData -> { if (followingSellers.contains(itemData.getProfileData().getId())) { @@ -154,15 +150,13 @@ private void setFavoriteCount(List items) { item -> { countMap.put(item.getId(), item.getCount()); }); - items.forEach( - itemData -> itemData.setFavoritesCount(countMap.get(itemData.getId()))); + items.forEach(itemData -> itemData.setFavoritesCount(countMap.get(itemData.getId()))); } private void setIsFavorite(List items, User currentUser) { Set favoritedItems = itemFavoritesReadService.userFavorites( - items.stream().map(itemData -> itemData.getId()).collect(toList()), - currentUser); + items.stream().map(itemData -> itemData.getId()).collect(toList()), currentUser); items.forEach( itemData -> { diff --git a/.framework/java/backend/src/main/java/io/spring/application/item/DuplicatedItemValidator.java b/.framework/java/backend/src/main/java/io/spring/application/item/DuplicatedItemValidator.java index 658acf06..a7042a39 100644 --- a/.framework/java/backend/src/main/java/io/spring/application/item/DuplicatedItemValidator.java +++ b/.framework/java/backend/src/main/java/io/spring/application/item/DuplicatedItemValidator.java @@ -6,8 +6,7 @@ import javax.validation.ConstraintValidatorContext; import org.springframework.beans.factory.annotation.Autowired; -class DuplicatedItemValidator - implements ConstraintValidator { +class DuplicatedItemValidator implements ConstraintValidator { @Autowired private ItemQueryService itemQueryService; diff --git a/.framework/java/backend/src/main/java/io/spring/application/item/ItemCommandService.java b/.framework/java/backend/src/main/java/io/spring/application/item/ItemCommandService.java index 528d6d6d..14a9e154 100644 --- a/.framework/java/backend/src/main/java/io/spring/application/item/ItemCommandService.java +++ b/.framework/java/backend/src/main/java/io/spring/application/item/ItemCommandService.java @@ -29,9 +29,7 @@ public Item createItem(@Valid NewItemParam newItemParam, User creator) { public Item updateItem(Item item, @Valid UpdateItemParam updateItemParam) { item.update( - updateItemParam.getTitle(), - updateItemParam.getDescription(), - updateItemParam.getImage()); + updateItemParam.getTitle(), updateItemParam.getDescription(), updateItemParam.getImage()); itemRepository.save(item); return item; } diff --git a/.framework/java/backend/src/main/java/io/spring/core/item/Item.java b/.framework/java/backend/src/main/java/io/spring/core/item/Item.java index c13a724d..4f0f160f 100644 --- a/.framework/java/backend/src/main/java/io/spring/core/item/Item.java +++ b/.framework/java/backend/src/main/java/io/spring/core/item/Item.java @@ -59,9 +59,9 @@ public void update(String title, String description, String image) { this.updatedAt = new DateTime(); } if (!Util.isEmpty(image)) { - this.image = image; - this.updatedAt = new DateTime(); - } + this.image = image; + this.updatedAt = new DateTime(); + } } public static String toSlug(String title) { diff --git a/.framework/java/backend/src/main/java/io/spring/core/service/AuthorizationService.java b/.framework/java/backend/src/main/java/io/spring/core/service/AuthorizationService.java index 94b949ba..bb7fba2d 100644 --- a/.framework/java/backend/src/main/java/io/spring/core/service/AuthorizationService.java +++ b/.framework/java/backend/src/main/java/io/spring/core/service/AuthorizationService.java @@ -1,7 +1,7 @@ package io.spring.core.service; -import io.spring.core.item.Item; import io.spring.core.comment.Comment; +import io.spring.core.item.Item; import io.spring.core.user.User; public class AuthorizationService { diff --git a/.framework/java/backend/src/main/java/io/spring/graphql/CommentDatafetcher.java b/.framework/java/backend/src/main/java/io/spring/graphql/CommentDatafetcher.java index 1102ba31..4f4bc896 100644 --- a/.framework/java/backend/src/main/java/io/spring/graphql/CommentDatafetcher.java +++ b/.framework/java/backend/src/main/java/io/spring/graphql/CommentDatafetcher.java @@ -12,15 +12,15 @@ import io.spring.application.CursorPager; import io.spring.application.CursorPager.Direction; import io.spring.application.DateTimeCursor; -import io.spring.application.data.ItemData; import io.spring.application.data.CommentData; +import io.spring.application.data.ItemData; import io.spring.core.user.User; -import io.spring.graphql.DgsConstants.ITEM; import io.spring.graphql.DgsConstants.COMMENTPAYLOAD; -import io.spring.graphql.types.Item; +import io.spring.graphql.DgsConstants.ITEM; import io.spring.graphql.types.Comment; import io.spring.graphql.types.CommentEdge; import io.spring.graphql.types.CommentsConnection; +import io.spring.graphql.types.Item; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; diff --git a/.framework/java/backend/src/main/java/io/spring/graphql/CommentMutation.java b/.framework/java/backend/src/main/java/io/spring/graphql/CommentMutation.java index 7bcbf995..35b7f761 100644 --- a/.framework/java/backend/src/main/java/io/spring/graphql/CommentMutation.java +++ b/.framework/java/backend/src/main/java/io/spring/graphql/CommentMutation.java @@ -8,10 +8,10 @@ import io.spring.api.exception.ResourceNotFoundException; import io.spring.application.CommentQueryService; import io.spring.application.data.CommentData; -import io.spring.core.item.Item; -import io.spring.core.item.ItemRepository; import io.spring.core.comment.Comment; import io.spring.core.comment.CommentRepository; +import io.spring.core.item.Item; +import io.spring.core.item.ItemRepository; import io.spring.core.service.AuthorizationService; import io.spring.core.user.User; import io.spring.graphql.DgsConstants.MUTATION; @@ -32,8 +32,7 @@ public class CommentMutation { public DataFetcherResult createComment( @InputArgument("slug") String slug, @InputArgument("body") String body) { User user = SecurityUtil.getCurrentUser().orElseThrow(AuthenticationException::new); - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); Comment comment = new Comment(body, user.getId(), item.getId()); commentRepository.save(comment); CommentData commentData = @@ -51,8 +50,7 @@ public DeletionStatus removeComment( @InputArgument("slug") String slug, @InputArgument("id") String commentId) { User user = SecurityUtil.getCurrentUser().orElseThrow(AuthenticationException::new); - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); return commentRepository .findById(item.getId(), commentId) .map( diff --git a/.framework/java/backend/src/main/java/io/spring/graphql/ItemDatafetcher.java b/.framework/java/backend/src/main/java/io/spring/graphql/ItemDatafetcher.java index faffa4ee..3dd97d65 100644 --- a/.framework/java/backend/src/main/java/io/spring/graphql/ItemDatafetcher.java +++ b/.framework/java/backend/src/main/java/io/spring/graphql/ItemDatafetcher.java @@ -10,17 +10,17 @@ import graphql.relay.DefaultPageInfo; import graphql.schema.DataFetchingEnvironment; import io.spring.api.exception.ResourceNotFoundException; -import io.spring.application.ItemQueryService; import io.spring.application.CursorPageParameter; import io.spring.application.CursorPager; import io.spring.application.CursorPager.Direction; import io.spring.application.DateTimeCursor; -import io.spring.application.data.ItemData; +import io.spring.application.ItemQueryService; import io.spring.application.data.CommentData; +import io.spring.application.data.ItemData; import io.spring.core.user.User; import io.spring.core.user.UserRepository; -import io.spring.graphql.DgsConstants.ITEMPAYLOAD; import io.spring.graphql.DgsConstants.COMMENT; +import io.spring.graphql.DgsConstants.ITEMPAYLOAD; import io.spring.graphql.DgsConstants.PROFILE; import io.spring.graphql.DgsConstants.QUERY; import io.spring.graphql.types.Item; @@ -80,8 +80,7 @@ public DataFetcherResult getFeed( .build(); return DataFetcherResult.newResult() .data(itemsConnection) - .localContext( - items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) + .localContext(items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) .build(); } @@ -130,8 +129,7 @@ public DataFetcherResult userFeed( .build(); return DataFetcherResult.newResult() .data(itemsConnection) - .localContext( - items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) + .localContext(items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) .build(); } @@ -184,8 +182,7 @@ public DataFetcherResult userFavorites( .build(); return DataFetcherResult.newResult() .data(itemsConnection) - .localContext( - items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) + .localContext(items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) .build(); } @@ -237,8 +234,7 @@ public DataFetcherResult userItems( .build(); return DataFetcherResult.newResult() .data(itemsConnection) - .localContext( - items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) + .localContext(items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) .build(); } @@ -292,8 +288,7 @@ public DataFetcherResult getItems( .build(); return DataFetcherResult.newResult() .data(itemsConnection) - .localContext( - items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) + .localContext(items.getData().stream().collect(Collectors.toMap(ItemData::getSlug, a -> a))) .build(); } @@ -319,8 +314,7 @@ public DataFetcherResult getItem(DataFetchingEnvironment dfe) { } @DgsData(parentType = COMMENT.TYPE_NAME, field = COMMENT.Item) - public DataFetcherResult getCommentItem( - DataFetchingEnvironment dataFetchingEnvironment) { + public DataFetcherResult getCommentItem(DataFetchingEnvironment dataFetchingEnvironment) { CommentData comment = dataFetchingEnvironment.getLocalContext(); User current = SecurityUtil.getCurrentUser().orElse(null); ItemData itemData = diff --git a/.framework/java/backend/src/main/java/io/spring/graphql/ItemMutation.java b/.framework/java/backend/src/main/java/io/spring/graphql/ItemMutation.java index de4c4ba3..2e09d92f 100644 --- a/.framework/java/backend/src/main/java/io/spring/graphql/ItemMutation.java +++ b/.framework/java/backend/src/main/java/io/spring/graphql/ItemMutation.java @@ -9,17 +9,17 @@ import io.spring.application.item.ItemCommandService; import io.spring.application.item.NewItemParam; import io.spring.application.item.UpdateItemParam; -import io.spring.core.item.Item; -import io.spring.core.item.ItemRepository; import io.spring.core.favorite.ItemFavorite; import io.spring.core.favorite.ItemFavoriteRepository; +import io.spring.core.item.Item; +import io.spring.core.item.ItemRepository; import io.spring.core.service.AuthorizationService; import io.spring.core.user.User; import io.spring.graphql.DgsConstants.MUTATION; import io.spring.graphql.exception.AuthenticationException; -import io.spring.graphql.types.ItemPayload; import io.spring.graphql.types.CreateItemInput; import io.spring.graphql.types.DeletionStatus; +import io.spring.graphql.types.ItemPayload; import io.spring.graphql.types.UpdateItemInput; import java.util.Collections; import lombok.AllArgsConstructor; @@ -33,8 +33,7 @@ public class ItemMutation { private ItemRepository itemRepository; @DgsMutation(field = MUTATION.CreateItem) - public DataFetcherResult createItem( - @InputArgument("input") CreateItemInput input) { + public DataFetcherResult createItem(@InputArgument("input") CreateItemInput input) { User user = SecurityUtil.getCurrentUser().orElseThrow(AuthenticationException::new); NewItemParam newItemParam = NewItemParam.builder() @@ -53,8 +52,7 @@ public DataFetcherResult createItem( @DgsMutation(field = MUTATION.UpdateItem) public DataFetcherResult updateItem( @InputArgument("slug") String slug, @InputArgument("changes") UpdateItemInput params) { - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); User user = SecurityUtil.getCurrentUser().orElseThrow(AuthenticationException::new); if (!AuthorizationService.canWriteItem(user, item)) { throw new NoAuthorizationException(); @@ -72,8 +70,7 @@ public DataFetcherResult updateItem( @DgsMutation(field = MUTATION.FavoriteItem) public DataFetcherResult favoriteItem(@InputArgument("slug") String slug) { User user = SecurityUtil.getCurrentUser().orElseThrow(AuthenticationException::new); - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); ItemFavorite itemFavorite = new ItemFavorite(item.getId(), user.getId()); itemFavoriteRepository.save(itemFavorite); return DataFetcherResult.newResult() @@ -85,8 +82,7 @@ public DataFetcherResult favoriteItem(@InputArgument("slug") String @DgsMutation(field = MUTATION.UnfavoriteItem) public DataFetcherResult unfavoriteItem(@InputArgument("slug") String slug) { User user = SecurityUtil.getCurrentUser().orElseThrow(AuthenticationException::new); - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); itemFavoriteRepository .find(item.getId(), user.getId()) .ifPresent( @@ -102,8 +98,7 @@ public DataFetcherResult unfavoriteItem(@InputArgument("slug") Stri @DgsMutation(field = MUTATION.DeleteItem) public DeletionStatus deleteItem(@InputArgument("slug") String slug) { User user = SecurityUtil.getCurrentUser().orElseThrow(AuthenticationException::new); - Item item = - itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); + Item item = itemRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new); if (!AuthorizationService.canWriteItem(user, item)) { throw new NoAuthorizationException(); diff --git a/.framework/java/backend/src/main/java/io/spring/graphql/ProfileDatafetcher.java b/.framework/java/backend/src/main/java/io/spring/graphql/ProfileDatafetcher.java index 0afc3f48..e421eea5 100644 --- a/.framework/java/backend/src/main/java/io/spring/graphql/ProfileDatafetcher.java +++ b/.framework/java/backend/src/main/java/io/spring/graphql/ProfileDatafetcher.java @@ -6,16 +6,16 @@ import graphql.schema.DataFetchingEnvironment; import io.spring.api.exception.ResourceNotFoundException; import io.spring.application.ProfileQueryService; -import io.spring.application.data.ItemData; import io.spring.application.data.CommentData; +import io.spring.application.data.ItemData; import io.spring.application.data.ProfileData; import io.spring.core.user.User; -import io.spring.graphql.DgsConstants.ITEM; import io.spring.graphql.DgsConstants.COMMENT; +import io.spring.graphql.DgsConstants.ITEM; import io.spring.graphql.DgsConstants.QUERY; import io.spring.graphql.DgsConstants.USER; -import io.spring.graphql.types.Item; import io.spring.graphql.types.Comment; +import io.spring.graphql.types.Item; import io.spring.graphql.types.Profile; import io.spring.graphql.types.ProfilePayload; import java.util.Map; diff --git a/.framework/java/backend/src/main/resources/application-test.properties b/.framework/java/backend/src/main/resources/application-test.properties index 0902f5cb..612f0b6e 100644 --- a/.framework/java/backend/src/main/resources/application-test.properties +++ b/.framework/java/backend/src/main/resources/application-test.properties @@ -1 +1,4 @@ -spring.datasource.url=jdbc:sqlite::memory: \ No newline at end of file +spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password diff --git a/.framework/java/backend/src/main/resources/mapper/ItemReadService.xml b/.framework/java/backend/src/main/resources/mapper/ItemReadService.xml index e6599e13..01ee5490 100644 --- a/.framework/java/backend/src/main/resources/mapper/ItemReadService.xml +++ b/.framework/java/backend/src/main/resources/mapper/ItemReadService.xml @@ -58,8 +58,8 @@ order by A.created_at desc - offset #{page.offset} rows limit #{page.limit} + offset #{page.offset}