From 0f3893c5577afde1e49187055913fedaec28b541 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:10:56 +0900 Subject: [PATCH 01/16] =?UTF-8?q?=E3=82=AB=E3=82=BF=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A2=E3=82=A4=E3=83=86=E3=83=A0=E3=81=AEdto=E3=81=AE?= =?UTF-8?q?=E5=BC=95=E6=95=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/dto/catalog/PostCatalogItemRequest.java | 2 -- .../admin/controller/dto/catalog/PutCatalogItemRequest.java | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PostCatalogItemRequest.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PostCatalogItemRequest.java index d16c0b127..308e22898 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PostCatalogItemRequest.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PostCatalogItemRequest.java @@ -1,6 +1,5 @@ package com.dressca.web.admin.controller.dto.catalog; -import java.time.LocalDateTime; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Data; @@ -25,5 +24,4 @@ public class PostCatalogItemRequest { private long catalogCategoryId; @NotNull private long catalogBrandId; - private LocalDateTime rowVersion = LocalDateTime.now(); } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java index d0b1680dc..01ce82859 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java @@ -1,5 +1,6 @@ package com.dressca.web.admin.controller.dto.catalog; +import java.time.LocalDateTime; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Data; @@ -22,4 +23,6 @@ public class PutCatalogItemRequest { public long catalogCategoryId; @NotNull public long catalogBrandId; + @NotNull + public LocalDateTime rowVersion; } From 924f00542bf022525aa58a13b4f58f17aa271413 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:11:48 +0900 Subject: [PATCH 02/16] =?UTF-8?q?=E3=82=A2=E3=83=97=E3=83=AA=E3=82=B1?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=B5=E3=83=BC=E3=83=93?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E6=9B=B4=E6=96=B0=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=81=AE=E5=BC=95=E6=95=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CatalogApplicationService.java | 7 ++++--- .../CatalogApplicationServiceTest.java | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java index a63850804..7320ad279 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java @@ -182,6 +182,7 @@ public void deleteItemFromCatalog(long id) throws CatalogNotFoundException, Perm * @param productCode 商品コード。 * @param catalogCategoryId カテゴリID。 * @param catalogBrandId ブランドID。 + * @param rowVersion 行バージョン。 * @throws CatalogNotFoundException 更新対象のカタログアイテムが存在しなかった場合。 * @throws PermissionDeniedException 更新権限がない場合。 * @throws CatalogBrandNotFoundException 更新対象のカタログブランドが存在しなかった場合。 @@ -189,7 +190,7 @@ public void deleteItemFromCatalog(long id) throws CatalogNotFoundException, Perm * @throws OptimisticLockingFailureException 楽観ロックエラーの場合。 */ public void updateCatalogItem(long id, String name, String description, BigDecimal price, String productCode, - long catalogCategoryId, long catalogBrandId) + long catalogCategoryId, long catalogBrandId, LocalDateTime rowVersion) throws CatalogNotFoundException, PermissionDeniedException, CatalogBrandNotFoundException, CatalogCategoryNotFoundException, OptimisticLockingFailureException { @@ -214,8 +215,8 @@ public void updateCatalogItem(long id, String name, String description, BigDecim } CatalogItem item = new CatalogItem(id, name, description, price, productCode, catalogCategoryId, catalogBrandId); - // 変更前の行バージョンを取得し、変更対象のカタログアイテムに追加 - item.setRowVersion(currentCatalogItem.getRowVersion()); + // 変更前の行バージョンを、変更対象のカタログアイテムに追加 + item.setRowVersion(rowVersion); int updateRowCount = this.catalogRepository.update(item); if (updateRowCount == 0) { diff --git a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java index 209d615fc..7056df350 100644 --- a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java +++ b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.when; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.List; import java.util.Random; import org.junit.jupiter.api.BeforeEach; @@ -227,7 +228,8 @@ void setUp() { when(this.catalogRepository.update(any())).thenReturn(1); // Action - this.service.updateCatalogItem(1L, "Name", "Description.", BigDecimal.valueOf(100_000_000L), "C000000001", 1L, 1L); + this.service.updateCatalogItem(1L, "Name", "Description.", BigDecimal.valueOf(100_000_000L), "C000000001", 1L, 1L, + LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0)); // Assert verify(this.catalogRepository, times(1)).update(any()); @@ -250,7 +252,7 @@ void setUp() { // Action Executable action = () -> { this.service.updateCatalogItem(targetId, "Name", "Description.", BigDecimal.valueOf(100_000_000L), "C000000001", - 1L, 1L); + 1L, 1L, LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0)); }; // Assert @@ -273,7 +275,7 @@ void setUp() { // Action Executable action = () -> { this.service.updateCatalogItem(1L, "Name", "Description.", BigDecimal.valueOf(100_000_000L), "C000000001", 1L, - targetId); + targetId, LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0)); }; // Assert @@ -296,7 +298,7 @@ void setUp() { // Action Executable action = () -> { this.service.updateCatalogItem(1L, "Name", "Description.", BigDecimal.valueOf(100_000_000L), "C000000001", - targetId, 1L); + targetId, 1L, LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0)); }; // Assert @@ -321,7 +323,7 @@ void setUp() { // Action Executable action = () -> { this.service.updateCatalogItem(1L, "Name", "Description.", BigDecimal.valueOf(100_000_000L), "C000000001", - 1L, 1L); + 1L, 1L, LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0)); }; // Assert @@ -346,7 +348,7 @@ void setUp() { // Action Executable action = () -> { this.service.updateCatalogItem(targetId, "Name", "Description.", BigDecimal.valueOf(100_000_000L), "C000000001", - 1L, 1L); + 1L, 1L, LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0)); }; // Assert From 1b987fdfc10bcb05d340de4398f0622ab8026bea Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:12:31 +0900 Subject: [PATCH 03/16] =?UTF-8?q?=E3=82=AB=E3=82=BF=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A2=E3=82=A4=E3=83=86=E3=83=A0=E3=81=AEget=E3=81=AEdto?= =?UTF-8?q?=E3=81=AE=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=81=AB?= =?UTF-8?q?=E8=A1=8C=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/admin/controller/dto/catalog/CatalogItemResponse.java | 3 +++ .../java/com/dressca/web/admin/mapper/CatalogItemMapper.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemResponse.java index 5dc2c5613..16c657862 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemResponse.java @@ -1,6 +1,7 @@ package com.dressca.web.admin.controller.dto.catalog; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.List; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -30,4 +31,6 @@ public class CatalogItemResponse { private long catalogCategoryId; @NotNull private long catalogBrandId; + @NotNull + private LocalDateTime rowVersion; } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java index 80226dbb0..85c361774 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java @@ -27,6 +27,7 @@ public static CatalogItemResponse convert(CatalogItem item) { .collect(Collectors.toList()); return new CatalogItemResponse(item.getId(), item.getName(), item.getProductCode(), assetCodes, - item.getDescription(), item.getPrice(), item.getCatalogCategoryId(), item.getCatalogBrandId()); + item.getDescription(), item.getPrice(), item.getCatalogCategoryId(), item.getCatalogBrandId(), + item.getRowVersion()); } } From ff3de4bca60aebb450ddb6c52d740210c9160803 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:13:21 +0900 Subject: [PATCH 04/16] =?UTF-8?q?API=E4=BB=95=E6=A7=98=E3=81=AE=E8=BB=BD?= =?UTF-8?q?=E5=BE=AE=E3=81=AA=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-docs/web-admin/api-specification.json | 20 ++++++++++++------- .../controller/CatalogItemsController.java | 8 ++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json index f35400fc8..73385fcec 100644 --- a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json +++ b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json @@ -375,7 +375,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PagedListOfCatalogItemResponse" + "$ref": "#/components/schemas/CatalogItemResponse" } } }, @@ -548,6 +548,10 @@ }, "productCode": { "type": "string" + }, + "rowVersion": { + "type": "string", + "format": "date-time" } }, "required": [ @@ -557,7 +561,8 @@ "id", "name", "price", - "productCode" + "productCode", + "rowVersion" ] }, "Link": { @@ -617,10 +622,6 @@ }, "productCode": { "type": "string" - }, - "rowVersion": { - "type": "string", - "format": "date-time" } }, "required": [ @@ -655,6 +656,10 @@ }, "productCode": { "type": "string" + }, + "rowVersion": { + "type": "string", + "format": "date-time" } }, "required": [ @@ -663,7 +668,8 @@ "description", "name", "price", - "productCode" + "productCode", + "rowVersion" ] }, "UserResponse": { diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java index 45a4474d1..f64de2000 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java @@ -66,7 +66,7 @@ public class CatalogItemsController { */ @Operation(summary = "指定したIDのカタログアイテムを返します。", description = "指定したIDのカタログアイテムを返します。") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PagedListOfCatalogItemResponse.class))), + @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = CatalogItemResponse.class))), @ApiResponse(responseCode = "401", description = "未認証エラー", content = @Content), @ApiResponse(responseCode = "404", description = "対象のIDが存在しない。", content = @Content) }) @@ -154,7 +154,7 @@ public ResponseEntity postCatalogItem(@RequestBody PostCatalogItemR @ApiResponse(responseCode = "404", description = "対象のIDが存在しない。", content = @Content) }) @DeleteMapping("{catalogItemId}") - public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") long catalogItemId) + public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") long catalogItemId) throws PermissionDeniedException { try { this.service.deleteItemFromCatalog(catalogItemId); @@ -183,14 +183,14 @@ public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemI @ApiResponse(responseCode = "409", description = "更新の競合が発生。", content = @Content), }) @PutMapping("{catalogItemId}") - public ResponseEntity putCatalogItem(@PathVariable("catalogItemId") long catalogItemId, + public ResponseEntity putCatalogItem(@PathVariable("catalogItemId") long catalogItemId, @RequestBody PutCatalogItemRequest putCatalogItemRequest) throws PermissionDeniedException, OptimisticLockingFailureException { try { this.service.updateCatalogItem(catalogItemId, putCatalogItemRequest.getName(), putCatalogItemRequest.getDescription(), new BigDecimal(putCatalogItemRequest.getPrice()), putCatalogItemRequest.getProductCode(), putCatalogItemRequest.getCatalogCategoryId(), - putCatalogItemRequest.getCatalogBrandId()); + putCatalogItemRequest.getCatalogBrandId(), putCatalogItemRequest.getRowVersion()); } catch (CatalogNotFoundException e) { apLog.info(e.getMessage()); apLog.debug(ExceptionUtils.getStackTrace(e)); From 4bf0256be248a4fa51558c57c01a322631aa0f62 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:25:32 +0900 Subject: [PATCH 05/16] =?UTF-8?q?javadoc=E3=81=AE=E8=AA=A4=E8=A8=98?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dressca/web/admin/authorization/UserStoreImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java index f168d8f9c..1fa81af42 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java @@ -41,7 +41,7 @@ public String loginUserRole() { /** * ログイン中のユーザーが指定したロールに属しているかどうか確認します。 * - * @return ログインしている場合true。未ログインの場合false。 + * @return ロールに属している場合true。未ログインの場合false。 */ public boolean isInRole(String role) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); From 2c779fe931149e6172c19096d621e45504428f4b Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:20:35 +0900 Subject: [PATCH 06/16] =?UTF-8?q?=E6=A5=BD=E8=A6=B3=E3=83=AD=E3=83=83?= =?UTF-8?q?=E3=82=AF=E5=AF=BE=E5=BF=9C=E3=81=AE=E3=82=BF=E3=82=B9=E3=82=AF?= =?UTF-8?q?=E3=81=AE=E4=B8=8D=E8=A6=81=E3=81=AA=E8=A8=98=E8=BF=B0=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/web-csr/dressca-backend/infrastructure/build.gradle | 2 -- .../repository/mybatis/generated/mapper/CatalogItemMapper.xml | 1 - 2 files changed, 3 deletions(-) diff --git a/samples/web-csr/dressca-backend/infrastructure/build.gradle b/samples/web-csr/dressca-backend/infrastructure/build.gradle index 0e8133495..28b213237 100644 --- a/samples/web-csr/dressca-backend/infrastructure/build.gradle +++ b/samples/web-csr/dressca-backend/infrastructure/build.gradle @@ -64,8 +64,6 @@ task updateMyBatisGeneratorMapperForOptimisticLocking { // 正規表現と置換のペアをリストにまとめる def replacements = [ - [ /((?:(?!and ${optimisticLockColumn} = \#\{${optimisticLockVariable},jdbcType=${optimisticLockJdbcType}})[\s\S])*?)(<\/if>)/, - "\$1and ${optimisticLockColumn} = #{${optimisticLockVariable},jdbcType=${optimisticLockJdbcType}}\n \$2" ], [ /( - and row_version = #{rowVersion,jdbcType=TIMESTAMP} From 9edcb1c3374d65fb5ee1a1ce65acee109671b220 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:21:14 +0900 Subject: [PATCH 07/16] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=82=92=E8=A4=87=E6=95=B0=E8=BF=94=E3=81=99?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorization/UserStore.java | 6 ++++-- .../web/admin/authorization/UserStoreImpl.java | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/authorization/UserStore.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/authorization/UserStore.java index 87b1e933c..6d6b65cc0 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/authorization/UserStore.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/authorization/UserStore.java @@ -1,13 +1,15 @@ package com.dressca.applicationcore.authorization; +import java.util.List; + /** * ユーザーのセッション情報のインターフェース。 */ public interface UserStore { - public String loginUserName(); + public String getLoginUserName(); - public String loginUserRole(); + public List getLoginUserRoles(); public boolean isInRole(String role); } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java index 1fa81af42..2e38e1caa 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/authorization/UserStoreImpl.java @@ -1,5 +1,8 @@ package com.dressca.web.admin.authorization; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; @@ -17,7 +20,8 @@ public class UserStoreImpl implements UserStore { * * @return ログイン中のユーザー名。未ログインの場合、空文字。 */ - public String loginUserName() { + @Override + public String getLoginUserName() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { return authentication.getName(); @@ -28,14 +32,17 @@ public String loginUserName() { /** * ログイン中のユーザーのロールを取得します。 * - * @return ログイン中のユーザーのロール。未ログインの場合、空文字 + * @return ログイン中のユーザーのロールの配列。未ログインの場合、空の配列。 */ - public String loginUserRole() { + @Override + public List getLoginUserRoles() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { - return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).findFirst().orElse(""); + List roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority) + .collect(Collectors.toList()); + return roles; } - return ""; + return new ArrayList<>(); } /** From 712deb3b406cb15836c0a314734ee88ce3d713a7 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:22:50 +0900 Subject: [PATCH 08/16] =?UTF-8?q?DTO=E3=82=AF=E3=83=A9=E3=82=B9=E7=BE=A4?= =?UTF-8?q?=E3=81=AE=E5=91=BD=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catalog/CatalogItemSummaryResponse.java | 23 ------------------- ...nse.java => GetCatalogBrandsResponse.java} | 2 +- ...java => GetCatalogCategoriesResponse.java} | 2 +- ...ponse.java => GetCatalogItemResponse.java} | 2 +- .../PagedListOfCatalogItemResponse.java | 2 +- .../dto/catalog/PutCatalogItemRequest.java | 14 +++++------ .../GetLoginUserResponse.java} | 8 ++++--- .../web/admin/mapper/CatalogBrandMapper.java | 12 +++++----- .../admin/mapper/CatalogCategoryMapper.java | 12 +++++----- .../web/admin/mapper/CatalogItemMapper.java | 12 +++++----- 10 files changed, 34 insertions(+), 55 deletions(-) delete mode 100644 samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemSummaryResponse.java rename samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/{CatalogBrandResponse.java => GetCatalogBrandsResponse.java} (90%) rename samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/{CatalogCategoryResponse.java => GetCatalogCategoriesResponse.java} (90%) rename samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/{CatalogItemResponse.java => GetCatalogItemResponse.java} (95%) rename samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/{UserResponse.java => user/GetLoginUserResponse.java} (58%) diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemSummaryResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemSummaryResponse.java deleted file mode 100644 index f60af18dd..000000000 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemSummaryResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.dressca.web.admin.controller.dto.catalog; - -import java.util.List; -import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * カタログアイテムの概要を取得する際に用いるdtoクラスです。 - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class CatalogItemSummaryResponse { - @NotNull - private long id; - @NotNull - private String name; - @NotNull - private String productCode; - private List assetCodes; -} diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogBrandResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogBrandsResponse.java similarity index 90% rename from samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogBrandResponse.java rename to samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogBrandsResponse.java index 41f45c223..98e2bbb9f 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogBrandResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogBrandsResponse.java @@ -11,7 +11,7 @@ @Data @AllArgsConstructor @NoArgsConstructor -public class CatalogBrandResponse { +public class GetCatalogBrandsResponse { @NotNull private long id; @NotNull diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogCategoryResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogCategoriesResponse.java similarity index 90% rename from samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogCategoryResponse.java rename to samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogCategoriesResponse.java index 0ddf1345f..2718d3003 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogCategoryResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogCategoriesResponse.java @@ -11,7 +11,7 @@ @Data @AllArgsConstructor @NoArgsConstructor -public class CatalogCategoryResponse { +public class GetCatalogCategoriesResponse { @NotNull private long id; @NotNull diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogItemResponse.java similarity index 95% rename from samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemResponse.java rename to samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogItemResponse.java index 16c657862..15227eba1 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/CatalogItemResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/GetCatalogItemResponse.java @@ -14,7 +14,7 @@ @Data @NoArgsConstructor @AllArgsConstructor -public class CatalogItemResponse { +public class GetCatalogItemResponse { @NotNull private long id; diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java index 213e6ab56..ff18f1ac5 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java @@ -12,7 +12,7 @@ @NoArgsConstructor @AllArgsConstructor public class PagedListOfCatalogItemResponse { - private List items; + private List items; private int totalCount; private int page; private int pageSize; diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java index 01ce82859..a629445b2 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PutCatalogItemRequest.java @@ -12,17 +12,17 @@ @AllArgsConstructor public class PutCatalogItemRequest { @NotNull - public String name = ""; + private String name = ""; @NotNull - public String description = ""; + private String description = ""; @NotNull - public long price; + private long price; @NotNull - public String productCode; + private String productCode; @NotNull - public long catalogCategoryId; + private long catalogCategoryId; @NotNull - public long catalogBrandId; + private long catalogBrandId; @NotNull - public LocalDateTime rowVersion; + private LocalDateTime rowVersion; } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/UserResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/user/GetLoginUserResponse.java similarity index 58% rename from samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/UserResponse.java rename to samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/user/GetLoginUserResponse.java index 2ca2cc118..89a516696 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/UserResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/user/GetLoginUserResponse.java @@ -1,5 +1,7 @@ -package com.dressca.web.admin.controller.dto; +package com.dressca.web.admin.controller.dto.user; +import java.util.ArrayList; +import java.util.List; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Data; @@ -9,9 +11,9 @@ */ @Data @AllArgsConstructor -public class UserResponse { +public class GetLoginUserResponse { @NotNull private String userName = ""; @NotNull - private String role = ""; + private List roles = new ArrayList<>(); } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogBrandMapper.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogBrandMapper.java index 3341b5358..824dbbbae 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogBrandMapper.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogBrandMapper.java @@ -1,23 +1,23 @@ package com.dressca.web.admin.mapper; import com.dressca.applicationcore.catalog.CatalogBrand; -import com.dressca.web.admin.controller.dto.catalog.CatalogBrandResponse; +import com.dressca.web.admin.controller.dto.catalog.GetCatalogBrandsResponse; /** - * {@link CatalogBrand} と {@link CatalogBrandResponse} のマッパーです。 + * {@link CatalogBrand} と {@link GetCatalogBrandsResponse} のマッパーです。 */ public class CatalogBrandMapper { /** - * {@link CatalogBrand} オブジェクトを {@link CatalogBrandResponse} に変換します。 + * {@link CatalogBrand} オブジェクトを {@link GetCatalogBrandsResponse} に変換します。 * * @param catalogBrand オブジェクト - * @return {@link CatalogBrandResponse} オブジェクト + * @return {@link GetCatalogBrandsResponse} オブジェクト */ - public static CatalogBrandResponse convert(CatalogBrand catalogBrand) { + public static GetCatalogBrandsResponse convert(CatalogBrand catalogBrand) { if (catalogBrand == null) { return null; } - return new CatalogBrandResponse(catalogBrand.getId(), catalogBrand.getName()); + return new GetCatalogBrandsResponse(catalogBrand.getId(), catalogBrand.getName()); } } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogCategoryMapper.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogCategoryMapper.java index 6ff852d4b..b1bb40c1d 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogCategoryMapper.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogCategoryMapper.java @@ -1,23 +1,23 @@ package com.dressca.web.admin.mapper; import com.dressca.applicationcore.catalog.CatalogCategory; -import com.dressca.web.admin.controller.dto.catalog.CatalogCategoryResponse; +import com.dressca.web.admin.controller.dto.catalog.GetCatalogCategoriesResponse; /** - * {@link CatalogCategory} と {@link CatalogCategoryResponse} のマッパーです。 + * {@link CatalogCategory} と {@link GetCatalogCategoriesResponse} のマッパーです。 */ public class CatalogCategoryMapper { /** - * {@link CatalogCategory} オブジェクトを {@link CatalogCategoryResponse} に変換します。 + * {@link CatalogCategory} オブジェクトを {@link GetCatalogCategoriesResponse} に変換します。 * * @param catalogCategory {@link CatalogCategory} オブジェクト - * @return {@link CatalogCategoryResponse} オブジェクト + * @return {@link GetCatalogCategoriesResponse} オブジェクト */ - public static CatalogCategoryResponse convert(CatalogCategory catalogCategory) { + public static GetCatalogCategoriesResponse convert(CatalogCategory catalogCategory) { if (catalogCategory == null) { return null; } - return new CatalogCategoryResponse(catalogCategory.getId(), catalogCategory.getName()); + return new GetCatalogCategoriesResponse(catalogCategory.getId(), catalogCategory.getName()); } } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java index 85c361774..52ef0b3c2 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/mapper/CatalogItemMapper.java @@ -4,20 +4,20 @@ import java.util.stream.Collectors; import com.dressca.applicationcore.catalog.CatalogItem; import com.dressca.applicationcore.catalog.CatalogItemAsset; -import com.dressca.web.admin.controller.dto.catalog.CatalogItemResponse; +import com.dressca.web.admin.controller.dto.catalog.GetCatalogItemResponse; /** - * {@link CatalogItem} と {@link CatalogItemResponse} のマッパーです。 + * {@link CatalogItem} と {@link GetCatalogItemResponse} のマッパーです。 */ public class CatalogItemMapper { /** - * {@link CatalogItem} オブジェクトを {@link CatalogItemResponse} に変換します。 + * {@link CatalogItem} オブジェクトを {@link GetCatalogItemResponse} に変換します。 * * @param item {@link CatalogItem} オブジェクト - * @return {@link CatalogItemResponse} オブジェクト + * @return {@link GetCatalogItemResponse} オブジェクト */ - public static CatalogItemResponse convert(CatalogItem item) { + public static GetCatalogItemResponse convert(CatalogItem item) { if (item == null) { return null; @@ -26,7 +26,7 @@ public static CatalogItemResponse convert(CatalogItem item) { List assetCodes = item.getAssets().stream().map(CatalogItemAsset::getAssetCode) .collect(Collectors.toList()); - return new CatalogItemResponse(item.getId(), item.getName(), item.getProductCode(), assetCodes, + return new GetCatalogItemResponse(item.getId(), item.getName(), item.getProductCode(), assetCodes, item.getDescription(), item.getPrice(), item.getCatalogCategoryId(), item.getCatalogBrandId(), item.getRowVersion()); } From 82c96b20d76e89e6be764b13247e3d6eb90c1efa Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:24:09 +0900 Subject: [PATCH 09/16] =?UTF-8?q?=E3=82=AB=E3=82=BF=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A2=E3=82=A4=E3=83=86=E3=83=A0=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=AB=E6=A5=BD=E8=A6=B3=E5=90=8C=E6=99=82=E5=AE=9F=E8=A1=8C?= =?UTF-8?q?=E5=88=B6=E5=BE=A1=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CatalogApplicationService.java | 27 ++++++++++++------- .../catalog/CatalogRepository.java | 14 ++++++---- .../mybatis/MybatisCatalogRepository.java | 6 +++-- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java index 7320ad279..c6051047c 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java @@ -23,6 +23,7 @@ import com.dressca.applicationcore.catalog.CatalogRepository; import com.dressca.systemcommon.constant.MessageIdConstant; import com.dressca.systemcommon.constant.SystemPropertyConstants; +import com.dressca.systemcommon.constant.UserRoleConstant; import com.dressca.systemcommon.exception.OptimisticLockingFailureException; /** @@ -74,7 +75,7 @@ public void setUserStore(UserStore userStore) { public CatalogItem getCatalogItem(long id) throws CatalogNotFoundException, PermissionDeniedException { apLog.debug(messages.getMessage(MessageIdConstant.D_CATALOG0005_LOG, new Object[] { id }, Locale.getDefault())); - if (!this.userStore.isInRole("ROLE_ADMIN")) { + if (!this.userStore.isInRole(UserRoleConstant.ADMIN)) { throw new PermissionDeniedException("getCatalogItem"); } @@ -118,7 +119,7 @@ public List getCatalogItemsByAdmin(long brandId, long categoryId, i apLog.debug(messages.getMessage(MessageIdConstant.D_CATALOG0001_LOG, new Object[] { brandId, categoryId, page, pageSize }, Locale.getDefault())); - if (!this.userStore.isInRole("ROLE_ADMIN")) { + if (!this.userStore.isInRole(UserRoleConstant.ADMIN)) { throw new PermissionDeniedException("getCatalogItemsByAdmin"); } @@ -141,7 +142,7 @@ public CatalogItem addItemToCatalog(String name, String description, BigDecimal long catalogCategoryId, long catalogBrandId) throws PermissionDeniedException { apLog.debug(messages.getMessage(MessageIdConstant.D_CATALOG0006_LOG, new Object[] {}, Locale.getDefault())); - if (!this.userStore.isInRole("ROLE_ADMIN")) { + if (!this.userStore.isInRole(UserRoleConstant.ADMIN)) { throw new PermissionDeniedException("addItemToCatalog"); } @@ -155,21 +156,27 @@ public CatalogItem addItemToCatalog(String name, String description, BigDecimal /** * カタログからアイテムを削除します。 * - * @param id 削除対象のカタログアイテムのID。 - * @throws PermissionDeniedException 削除権限がない場合。 - * @throws CatalogNotFoundException 削除対象のカタログアイテムが存在しなかった場合。 + * @param id 削除対象のカタログアイテムのID。 + * @param rowVersion 行バージョン。 + * @throws PermissionDeniedException 削除権限がない場合。 + * @throws CatalogNotFoundException 削除対象のカタログアイテムが存在しなかった場合。 + * @throws OptimisticLockingFailureException 楽観ロックエラーの場合。 * */ - public void deleteItemFromCatalog(long id) throws CatalogNotFoundException, PermissionDeniedException { + public void deleteItemFromCatalog(long id, LocalDateTime rowVersion) + throws CatalogNotFoundException, PermissionDeniedException, OptimisticLockingFailureException { apLog.debug(messages.getMessage(MessageIdConstant.D_CATALOG0007_LOG, new Object[] { id }, Locale.getDefault())); - if (!this.userStore.isInRole("ROLE_ADMIN")) { + if (!this.userStore.isInRole(UserRoleConstant.ADMIN)) { throw new PermissionDeniedException("deleteItemFromCatalog"); } CatalogItem item = this.catalogRepository.findById(id); if (item == null) { throw new CatalogNotFoundException(id); } - this.catalogRepository.remove(item); + int deleteRowCount = this.catalogRepository.remove(id, rowVersion); + if (deleteRowCount == 0) { + throw new OptimisticLockingFailureException(id); + } } /** @@ -196,7 +203,7 @@ public void updateCatalogItem(long id, String name, String description, BigDecim apLog.debug(messages.getMessage(MessageIdConstant.D_CATALOG0008_LOG, new Object[] { id }, Locale.getDefault())); - if (!this.userStore.isInRole("ROLE_ADMIN")) { + if (!this.userStore.isInRole(UserRoleConstant.ADMIN)) { throw new PermissionDeniedException("updateCatalogItem"); } CatalogItem currentCatalogItem = catalogRepository.findById(id); diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogRepository.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogRepository.java index 522119932..bdb479804 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogRepository.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogRepository.java @@ -1,5 +1,6 @@ package com.dressca.applicationcore.catalog; +import java.time.LocalDateTime; import java.util.List; /** @@ -70,15 +71,18 @@ List findByBrandIdAndCategoryId(long brandId, long categoryId, int /** * カタログアイテムを削除します。 - * - * @param item カタログアイテム + * + * @param id カタログアイテムID + * @param rowVersion 行バージョン + * @return 削除できたら1、できなければ0を返す */ - int remove(CatalogItem item); + int remove(Long id, LocalDateTime rowVersion); /** * カタログアイテムを更新します。 - * - * @param item カタログアイテム + * + * @param item カタログアイテム。 + * @return 更新できたら1、できなければ0を返す。 */ int update(CatalogItem item); diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java index 2f941c81d..268ad52ea 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java @@ -7,6 +7,7 @@ import com.dressca.infrastructure.repository.mybatis.generated.mapper.CatalogItemMapper; import com.dressca.infrastructure.repository.mybatis.mapper.JoinedCatalogItemMapper; import com.dressca.infrastructure.repository.mybatis.translator.EntityTranslator; +import java.time.LocalDateTime; import java.util.List; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; @@ -61,13 +62,14 @@ public CatalogItem findById(long id) { public CatalogItem add(CatalogItem item) { CatalogItemEntity entity = EntityTranslator.createCatalogItemEntity(item); catalogItemMapper.insert(entity); + item.setId(entity.getId()); return item; } @Override - public int remove(CatalogItem item) { + public int remove(Long id, LocalDateTime rowVersion) { CatalogItemEntityExample catalogItemExample = new CatalogItemEntityExample(); - catalogItemExample.createCriteria().andIdEqualTo(item.getId()); + catalogItemExample.createCriteria().andIdEqualTo(id).andRowVersionEqualTo(rowVersion); return catalogItemMapper.deleteByExample(catalogItemExample); } From 97af9617b4b04a22ea1219b0c790ac787ec4024b Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:25:07 +0900 Subject: [PATCH 10/16] =?UTF-8?q?=E4=B8=8D=E8=B6=B3=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8BAPI=E3=83=AC=E3=82=B9=E3=83=9D=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-docs/web-admin/api-specification.json | 155 ++++++++++++------ .../admin/controller/AssetsController.java | 8 +- .../controller/CatalogBrandsController.java | 11 +- .../CatalogCategoriesController.java | 11 +- .../controller/CatalogItemsController.java | 92 ++++++----- .../web/admin/controller/UsersController.java | 13 +- 6 files changed, 190 insertions(+), 100 deletions(-) diff --git a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json index 73385fcec..26a27aac8 100644 --- a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json +++ b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json @@ -116,10 +116,16 @@ } } }, - "description": "成功." + "description": "成功。" + }, + "401": { + "description": "未認証。" }, "404": { - "description": "アセットコードに対応するアセットがない." + "description": "アセットコードに対応するアセットがない。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "アセットを取得する.", @@ -139,12 +145,18 @@ "schema": { "type": "array", "items": { - "$ref": "#/components/schemas/CatalogBrandResponse" + "$ref": "#/components/schemas/GetCatalogBrandsResponse" } } } }, - "description": "成功" + "description": "成功。" + }, + "401": { + "description": "未認証。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "カタログブランドの一覧を取得する.", @@ -164,12 +176,18 @@ "schema": { "type": "array", "items": { - "$ref": "#/components/schemas/CatalogCategoryResponse" + "$ref": "#/components/schemas/GetCatalogCategoriesResponse" } } } }, - "description": "成功" + "description": "成功。" + }, + "401": { + "description": "未認証。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "カタログカテゴリの一覧を取得します.", @@ -233,16 +251,19 @@ } } }, - "description": "成功" + "description": "成功。" }, "400": { - "description": "リクエストエラー" + "description": "リクエストエラー。" }, "401": { - "description": "未認証エラー" + "description": "未認証。" }, "404": { - "description": "リソースアクセスエラー" + "description": "失敗。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "カタログアイテムを検索して返します.", @@ -267,11 +288,17 @@ "201": { "description": "成功。" }, + "400": { + "description": "リクエストエラー。" + }, "401": { - "description": "未認証エラー" + "description": "未認証。" }, "404": { - "description": "リソースアクセスエラー" + "description": "失敗。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "カタログにアイテムを追加します。", @@ -293,17 +320,35 @@ "type": "integer", "format": "int64" } + }, + { + "in": "query", + "name": "rowVersion", + "required": true, + "schema": { + "type": "string", + "format": "date-time" + } } ], "responses": { "204": { - "description": "成功." + "description": "成功。" + }, + "400": { + "description": "リクエストエラー。" }, "401": { - "description": "未認証エラー" + "description": "未認証。" }, "404": { - "description": "対象のIDが存在しない。" + "description": "指定した ID のアイテムがカタログに存在しない。" + }, + "409": { + "description": "競合が発生。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "カタログから指定したカタログアイテム ID のアイテムを削除します。", @@ -337,16 +382,22 @@ }, "responses": { "204": { - "description": "成功." + "description": "成功。" + }, + "400": { + "description": "リクエストエラー。" }, "401": { - "description": "未認証エラー" + "description": "未認証。" }, "404": { - "description": "対象のIDが存在しない。" + "description": "指定した ID のアイテムがカタログに存在しない。" }, "409": { - "description": "更新の競合が発生。" + "description": "競合が発生。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "指定したIDのカタログアイテムの情報を更新します。", @@ -358,7 +409,7 @@ "/api/catalog-items/{id}": { "get": { "description": "指定したIDのカタログアイテムを返します。", - "operationId": "getById", + "operationId": "getCatalogItem", "parameters": [ { "in": "path", @@ -375,17 +426,23 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CatalogItemResponse" + "$ref": "#/components/schemas/GetCatalogItemResponse" } } }, - "description": "成功" + "description": "成功。" + }, + "400": { + "description": "リクエストエラー。" }, "401": { - "description": "未認証エラー" + "description": "未認証。" }, "404": { - "description": "対象のIDが存在しない。" + "description": "指定した ID のアイテムがカタログに存在しない。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "指定したIDのカタログアイテムを返します。", @@ -465,14 +522,17 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/UserResponse" + "$ref": "#/components/schemas/GetLoginUserResponse" } } }, - "description": "成功." + "description": "成功。" }, "401": { - "description": "未認証エラー." + "description": "未認証。" + }, + "500": { + "description": "サーバーエラー。" } }, "summary": "ログイン中のユーザーの情報を取得します。", @@ -484,7 +544,7 @@ }, "components": { "schemas": { - "CatalogBrandResponse": { + "GetCatalogBrandsResponse": { "type": "object", "properties": { "id": { @@ -500,7 +560,7 @@ "name" ] }, - "CatalogCategoryResponse": { + "GetCatalogCategoriesResponse": { "type": "object", "properties": { "id": { @@ -516,7 +576,7 @@ "name" ] }, - "CatalogItemResponse": { + "GetCatalogItemResponse": { "type": "object", "properties": { "assetCodes": { @@ -565,6 +625,24 @@ "rowVersion" ] }, + "GetLoginUserResponse": { + "type": "object", + "properties": { + "roles": { + "type": "array", + "items": { + "type": "string" + } + }, + "userName": { + "type": "string" + } + }, + "required": [ + "roles", + "userName" + ] + }, "Link": { "type": "object", "properties": { @@ -582,7 +660,7 @@ "items": { "type": "array", "items": { - "$ref": "#/components/schemas/CatalogItemResponse" + "$ref": "#/components/schemas/GetCatalogItemResponse" } }, "page": { @@ -671,21 +749,6 @@ "productCode", "rowVersion" ] - }, - "UserResponse": { - "type": "object", - "properties": { - "role": { - "type": "string" - }, - "userName": { - "type": "string" - } - }, - "required": [ - "role", - "userName" - ] } } } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/AssetsController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/AssetsController.java index 7b3eba884..5766964dd 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/AssetsController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/AssetsController.java @@ -51,8 +51,12 @@ public class AssetsController { */ @Operation(summary = "アセットを取得する.", description = "与えられたアセットコードに対応するアセットを返却する.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功.", content = @Content(mediaType = "image/*", schema = @Schema(implementation = Resource.class))), - @ApiResponse(responseCode = "404", description = "アセットコードに対応するアセットがない.", content = @Content) }) + @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "image/*", schema = @Schema(implementation = Resource.class))), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "404", description = "アセットコードに対応するアセットがない。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content) + }) + @GetMapping("{assetCode}") public ResponseEntity get( @Parameter(required = true, description = "アセットコード") @PathVariable("assetCode") String assetCode) diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogBrandsController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogBrandsController.java index ddfe47bae..4959827ee 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogBrandsController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogBrandsController.java @@ -4,7 +4,7 @@ import java.util.stream.Collectors; import com.dressca.applicationcore.applicationservice.CatalogApplicationService; import com.dressca.applicationcore.catalog.CatalogBrand; -import com.dressca.web.admin.controller.dto.catalog.CatalogBrandResponse; +import com.dressca.web.admin.controller.dto.catalog.GetCatalogBrandsResponse; import com.dressca.web.admin.mapper.CatalogBrandMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -41,10 +41,13 @@ public class CatalogBrandsController { */ @Operation(summary = "カタログブランドの一覧を取得する.", description = "カタログブランドの一覧を取得する.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CatalogBrandResponse.class)))) }) + @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = GetCatalogBrandsResponse.class)))), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content) + }) @GetMapping - public ResponseEntity> getCatalogBrands() { - List brands = this.service.getBrands().stream() + public ResponseEntity> getCatalogBrands() { + List brands = this.service.getBrands().stream() .map(CatalogBrandMapper::convert) .collect(Collectors.toList()); diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogCategoriesController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogCategoriesController.java index f6eabdc23..b2c77cf73 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogCategoriesController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogCategoriesController.java @@ -4,7 +4,7 @@ import java.util.stream.Collectors; import com.dressca.applicationcore.applicationservice.CatalogApplicationService; import com.dressca.applicationcore.catalog.CatalogCategory; -import com.dressca.web.admin.controller.dto.catalog.CatalogCategoryResponse; +import com.dressca.web.admin.controller.dto.catalog.GetCatalogCategoriesResponse; import com.dressca.web.admin.mapper.CatalogCategoryMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -41,10 +41,13 @@ public class CatalogCategoriesController { */ @Operation(summary = "カタログカテゴリの一覧を取得します.", description = "カタログカテゴリの一覧を取得します.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CatalogCategoryResponse.class)))) }) + @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = GetCatalogCategoriesResponse.class)))), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content) + }) @GetMapping - public ResponseEntity> getCatalogCategories() { - List categories = this.service.getCategories().stream() + public ResponseEntity> getCatalogCategories() { + List categories = this.service.getCategories().stream() .map(CatalogCategoryMapper::convert) .collect(Collectors.toList()); diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java index f64de2000..f0f4f7bb3 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java @@ -2,6 +2,7 @@ import java.math.BigDecimal; import java.net.URI; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; import com.dressca.applicationcore.applicationservice.CatalogApplicationService; @@ -14,7 +15,7 @@ import com.dressca.systemcommon.constant.SystemPropertyConstants; import com.dressca.systemcommon.exception.OptimisticLockingFailureException; import com.dressca.systemcommon.exception.SystemException; -import com.dressca.web.admin.controller.dto.catalog.CatalogItemResponse; +import com.dressca.web.admin.controller.dto.catalog.GetCatalogItemResponse; import com.dressca.web.admin.controller.dto.catalog.PagedListOfCatalogItemResponse; import com.dressca.web.admin.controller.dto.catalog.PostCatalogItemRequest; import com.dressca.web.admin.controller.dto.catalog.PutCatalogItemRequest; @@ -62,16 +63,19 @@ public class CatalogItemsController { * * @param id ID。 * @return カタログアイテム。 - * @throws PermissionDeniedException 認可エラー + * @throws PermissionDeniedException 認可エラー。 */ @Operation(summary = "指定したIDのカタログアイテムを返します。", description = "指定したIDのカタログアイテムを返します。") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = CatalogItemResponse.class))), - @ApiResponse(responseCode = "401", description = "未認証エラー", content = @Content), - @ApiResponse(responseCode = "404", description = "対象のIDが存在しない。", content = @Content) + @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "application/json", schema = @Schema(implementation = GetCatalogItemResponse.class))), + @ApiResponse(responseCode = "400", description = "リクエストエラー。", content = @Content), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "404", description = "指定した ID のアイテムがカタログに存在しない。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content) }) @GetMapping("{id}") - public ResponseEntity getById(@PathVariable("id") long id) throws PermissionDeniedException { + public ResponseEntity getCatalogItem(@PathVariable("id") long id) + throws PermissionDeniedException { CatalogItem item; try { item = this.service.getCatalogItem(id); @@ -80,26 +84,27 @@ public ResponseEntity getById(@PathVariable("id") long id) apLog.debug(ExceptionUtils.getStackTrace(e)); return ResponseEntity.notFound().build(); } - CatalogItemResponse returnValue = CatalogItemMapper.convert(item); + GetCatalogItemResponse returnValue = CatalogItemMapper.convert(item); return ResponseEntity.ok().body(returnValue); } /** * カタログアイテムを検索して返します。 * - * @param brandId ブランドID - * @param categoryId カテゴリID - * @param page ページ番号。未指定の場合は1。 + * @param brandId ブランドID。未指定の場合は0。 + * @param categoryId カテゴリID。未指定の場合は0。 + * @param page ページ番号。未指定の場合は0。 * @param pageSize ページサイズ。未指定の場合は20。 - * @return カタログアイテムの一覧 - * @throws PermissionDeniedException 認可エラー + * @return カタログアイテムの一覧。 + * @throws PermissionDeniedException 認可エラー。 */ @Operation(summary = "カタログアイテムを検索して返します.", description = "カタログアイテムを検索して返します.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PagedListOfCatalogItemResponse.class))), - @ApiResponse(responseCode = "400", description = "リクエストエラー", content = @Content), - @ApiResponse(responseCode = "401", description = "未認証エラー", content = @Content), - @ApiResponse(responseCode = "404", description = "リソースアクセスエラー", content = @Content) + @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PagedListOfCatalogItemResponse.class))), + @ApiResponse(responseCode = "400", description = "リクエストエラー。", content = @Content), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "404", description = "失敗。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content), }) @GetMapping public ResponseEntity getByQuery( @@ -108,7 +113,8 @@ public ResponseEntity getByQuery( @RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize) throws PermissionDeniedException { - List items = this.service.getCatalogItemsByAdmin(brandId, categoryId, page, pageSize).stream() + List items = this.service.getCatalogItemsByAdmin(brandId, categoryId, page, pageSize) + .stream() .map(CatalogItemMapper::convert).collect(Collectors.toList()); int totalCount = this.service.countCatalogItems(brandId, categoryId); @@ -119,45 +125,53 @@ public ResponseEntity getByQuery( /** * カタログにアイテムを追加します。 * - * @param postCatalogItemRequest 追加するカタログアイテム - * @return 追加したカタログアイテム - * @throws PermissionDeniedException 認可エラー + * @param postCatalogItemRequest 追加するアイテムの情報。 + * @return なし。 + * @throws PermissionDeniedException 認可エラー。 */ @Operation(summary = "カタログにアイテムを追加します。", description = "カタログにアイテムを追加します。") @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "成功。", content = @Content), - @ApiResponse(responseCode = "401", description = "未認証エラー", content = @Content), - @ApiResponse(responseCode = "404", description = "リソースアクセスエラー", content = @Content) + @ApiResponse(responseCode = "400", description = "リクエストエラー。", content = @Content), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "404", description = "失敗。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content) }) @PostMapping public ResponseEntity postCatalogItem(@RequestBody PostCatalogItemRequest postCatalogItemRequest) throws PermissionDeniedException { - this.service.addItemToCatalog(postCatalogItemRequest.getName(), postCatalogItemRequest.getDescription(), + CatalogItem addedCatalogItem = this.service.addItemToCatalog(postCatalogItemRequest.getName(), + postCatalogItemRequest.getDescription(), new BigDecimal(postCatalogItemRequest.getPrice()), postCatalogItemRequest.getProductCode(), postCatalogItemRequest.getCatalogCategoryId(), postCatalogItemRequest.getCatalogBrandId()); - - return ResponseEntity.created(URI.create("catalog-items")).build(); + return ResponseEntity.created(URI.create("/api/catalog-items/" + addedCatalogItem.getId())).build(); } /** * カタログから指定したカタログアイテム ID のアイテムを削除します。 * * @param catalogItemId カタログアイテムID。 + * @param rowVersion 行バージョン。 * @return なし。 - * @throws PermissionDeniedException 認可エラー + * @throws PermissionDeniedException 認可エラー。 + * @throws OptimisticLockingFailureException 楽観ロックエラー。 */ @Operation(summary = "カタログから指定したカタログアイテム ID のアイテムを削除します。", description = "カタログから指定したカタログアイテム ID のアイテムを削除します。") @ApiResponses(value = { - @ApiResponse(responseCode = "204", description = "成功.", content = @Content), - @ApiResponse(responseCode = "401", description = "未認証エラー", content = @Content), - @ApiResponse(responseCode = "404", description = "対象のIDが存在しない。", content = @Content) + @ApiResponse(responseCode = "204", description = "成功。", content = @Content), + @ApiResponse(responseCode = "400", description = "リクエストエラー。", content = @Content), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "404", description = "指定した ID のアイテムがカタログに存在しない。", content = @Content), + @ApiResponse(responseCode = "409", description = "競合が発生。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content), }) @DeleteMapping("{catalogItemId}") - public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") long catalogItemId) - throws PermissionDeniedException { + public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") long catalogItemId, + @RequestParam LocalDateTime rowVersion) + throws PermissionDeniedException, OptimisticLockingFailureException { try { - this.service.deleteItemFromCatalog(catalogItemId); + this.service.deleteItemFromCatalog(catalogItemId, rowVersion); } catch (CatalogNotFoundException e) { apLog.info(e.getMessage()); apLog.debug(ExceptionUtils.getStackTrace(e)); @@ -172,15 +186,17 @@ public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") lon * @param catalogItemId カタログアイテムID。 * @param putCatalogItemRequest 更新するカタログアイテムの情報。 * @return なし。 - * @throws OptimisticLockingFailureException 楽観ロックエラー - * @throws PermissionDeniedException 認可エラー + * @throws OptimisticLockingFailureException 楽観ロックエラー。 + * @throws PermissionDeniedException 認可エラー。 */ @Operation(summary = "指定したIDのカタログアイテムの情報を更新します。", description = "指定したIDのカタログアイテムの情報を更新します。") @ApiResponses(value = { - @ApiResponse(responseCode = "204", description = "成功.", content = @Content), - @ApiResponse(responseCode = "401", description = "未認証エラー", content = @Content), - @ApiResponse(responseCode = "404", description = "対象のIDが存在しない。", content = @Content), - @ApiResponse(responseCode = "409", description = "更新の競合が発生。", content = @Content), + @ApiResponse(responseCode = "204", description = "成功。", content = @Content), + @ApiResponse(responseCode = "400", description = "リクエストエラー。", content = @Content), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "404", description = "指定した ID のアイテムがカタログに存在しない。", content = @Content), + @ApiResponse(responseCode = "409", description = "競合が発生。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content), }) @PutMapping("{catalogItemId}") public ResponseEntity putCatalogItem(@PathVariable("catalogItemId") long catalogItemId, diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/UsersController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/UsersController.java index a8251eccc..6b6be4db8 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/UsersController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/UsersController.java @@ -3,7 +3,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.dressca.applicationcore.authorization.UserStore; -import com.dressca.web.admin.controller.dto.UserResponse; +import com.dressca.web.admin.controller.dto.user.GetLoginUserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -32,16 +32,17 @@ public class UsersController { * * @return ユーザの情報。 */ - @Operation(summary = "ログイン中のユーザーの情報を取得します。", description = "ユーザーの情報。") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = UserResponse.class))), - @ApiResponse(responseCode = "401", description = "未認証エラー.", content = @Content) + @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "application/json", schema = @Schema(implementation = GetLoginUserResponse.class))), + @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content) }) @GetMapping - public ResponseEntity getLoginUser() { + public ResponseEntity getLoginUser() { - UserResponse response = new UserResponse(this.userStore.loginUserName(), this.userStore.loginUserRole()); + GetLoginUserResponse response = new GetLoginUserResponse(this.userStore.getLoginUserName(), + this.userStore.getLoginUserRoles()); return ResponseEntity.ok().body(response); } From b6660e2cb1434c8f2f6f0c05ca9456f70cffce13 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:48:04 +0900 Subject: [PATCH 11/16] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=AB=E3=82=92=E5=AE=9A=E6=95=B0=E3=81=A7?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applicationservice/CatalogApplicationService.java | 2 +- .../applicationcore/constant/UserRoleConstant.java | 9 +++++++++ .../web/admin/filter/DummyUserInjectionFilter.java | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/constant/UserRoleConstant.java diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java index c6051047c..22a0ebd53 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/applicationservice/CatalogApplicationService.java @@ -21,9 +21,9 @@ import com.dressca.applicationcore.catalog.CatalogItem; import com.dressca.applicationcore.catalog.CatalogNotFoundException; import com.dressca.applicationcore.catalog.CatalogRepository; +import com.dressca.applicationcore.constant.UserRoleConstant; import com.dressca.systemcommon.constant.MessageIdConstant; import com.dressca.systemcommon.constant.SystemPropertyConstants; -import com.dressca.systemcommon.constant.UserRoleConstant; import com.dressca.systemcommon.exception.OptimisticLockingFailureException; /** diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/constant/UserRoleConstant.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/constant/UserRoleConstant.java new file mode 100644 index 000000000..8c6ce7367 --- /dev/null +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/constant/UserRoleConstant.java @@ -0,0 +1,9 @@ +package com.dressca.applicationcore.constant; + +/** + * ユーザーのロール用定数クラス。 + */ +public class UserRoleConstant { + /** 管理者の権限名。 */ + public static final String ADMIN = "ROLE_ADMIN"; +} diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/filter/DummyUserInjectionFilter.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/filter/DummyUserInjectionFilter.java index f5836af78..d8bec6244 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/filter/DummyUserInjectionFilter.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/filter/DummyUserInjectionFilter.java @@ -10,6 +10,7 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; +import com.dressca.applicationcore.constant.UserRoleConstant; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; @@ -27,7 +28,8 @@ public class DummyUserInjectionFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { - UserDetails dummyUser = new User("admin@example.com", "", List.of(new SimpleGrantedAuthority("ROLE_ADMIN"))); + UserDetails dummyUser = new User("admin@example.com", "", + List.of(new SimpleGrantedAuthority(UserRoleConstant.ADMIN))); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(dummyUser, dummyUser.getPassword(), dummyUser.getAuthorities()); From fac238e9f986d9726340b0e7c61af622ccff74de Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:43:54 +0900 Subject: [PATCH 12/16] =?UTF-8?q?PagedListOfCatalogItemResponse=E3=81=AE?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E5=88=86=E3=82=92=E3=83=9E=E3=83=BC=E3=82=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-docs/web-admin/api-specification.json | 12 ++++++- .../web-consumer/api-specification.json | 12 ++++++- .../CatalogApplicationServiceTest.java | 36 ++++++++++++++++--- .../mybatis/MybatisCatalogRepository.java | 2 +- .../controller/CatalogItemsController.java | 2 +- .../PagedListOfCatalogItemResponse.java | 25 ++++++++++--- .../controller/CatalogItemsController.java | 2 +- .../PagedListOfCatalogItemResponse.java | 25 ++++++++++--- 8 files changed, 98 insertions(+), 18 deletions(-) diff --git a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json index 26a27aac8..2f0f1f12a 100644 --- a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json +++ b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json @@ -228,7 +228,7 @@ "schema": { "type": "integer", "format": "int32", - "default": 0 + "default": 1 } }, { @@ -657,6 +657,12 @@ "PagedListOfCatalogItemResponse": { "type": "object", "properties": { + "hasNext": { + "type": "boolean" + }, + "hasPrevious": { + "type": "boolean" + }, "items": { "type": "array", "items": { @@ -674,6 +680,10 @@ "totalCount": { "type": "integer", "format": "int32" + }, + "totalPages": { + "type": "integer", + "format": "int32" } } }, diff --git a/samples/web-csr/dressca-backend/api-docs/web-consumer/api-specification.json b/samples/web-csr/dressca-backend/api-docs/web-consumer/api-specification.json index 260c73089..473f1b645 100644 --- a/samples/web-csr/dressca-backend/api-docs/web-consumer/api-specification.json +++ b/samples/web-csr/dressca-backend/api-docs/web-consumer/api-specification.json @@ -326,7 +326,7 @@ "schema": { "type": "integer", "format": "int32", - "default": 0 + "default": 1 } }, { @@ -763,6 +763,12 @@ "PagedListOfCatalogItemResponse": { "type": "object", "properties": { + "hasNext": { + "type": "boolean" + }, + "hasPrevious": { + "type": "boolean" + }, "items": { "type": "array", "items": { @@ -780,6 +786,10 @@ "totalCount": { "type": "integer", "format": "int32" + }, + "totalPages": { + "type": "integer", + "format": "int32" } } }, diff --git a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java index 7056df350..feeb9eeb2 100644 --- a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java +++ b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/applicationservice/CatalogApplicationServiceTest.java @@ -163,18 +163,20 @@ void setUp() { @Test void testDeleteItemFromCatalog_正常系_リポジトリのremoveを1回呼出す() - throws CatalogNotFoundException, PermissionDeniedException { + throws CatalogNotFoundException, PermissionDeniedException, OptimisticLockingFailureException { // Arrange long targetId = 1L; CatalogItem item = createCatalogItem(targetId); when(this.userStore.isInRole(anyString())).thenReturn(true); when(this.catalogRepository.findById(anyLong())).thenReturn(item); + when(this.catalogRepository.remove(anyLong(), any())).thenReturn(1); + LocalDateTime rowVersion = LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0); // Action - this.service.deleteItemFromCatalog(1L); + this.service.deleteItemFromCatalog(1L, rowVersion); // Assert - verify(this.catalogRepository, times(1)).remove(any()); + verify(this.catalogRepository, times(1)).remove(any(), any()); } @@ -184,10 +186,12 @@ void setUp() { long targetId = 999L; when(this.userStore.isInRole(anyString())).thenReturn(true); when(this.catalogRepository.findById(anyLong())).thenReturn(null); + when(this.catalogRepository.remove(anyLong(), any())).thenReturn(1); + LocalDateTime rowVersion = LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0); // Action Executable action = () -> { - this.service.deleteItemFromCatalog(targetId); + this.service.deleteItemFromCatalog(targetId, rowVersion); }; // Assert @@ -201,16 +205,38 @@ void setUp() { CatalogItem item = createCatalogItem(targetId); when(this.userStore.isInRole(anyString())).thenReturn(false); when(this.catalogRepository.findById(anyLong())).thenReturn(item); + when(this.catalogRepository.remove(anyLong(), any())).thenReturn(1); + LocalDateTime rowVersion = LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0); // Action Executable action = () -> { - this.service.deleteItemFromCatalog(1L); + this.service.deleteItemFromCatalog(1L, rowVersion); }; // Assert assertThrows(PermissionDeniedException.class, action); } + @Test + void testDeleteItemFromCatalog_異常系_楽観ロックエラー() { + // Arrange + long targetId = 1L; + CatalogItem item = createCatalogItem(targetId); + when(this.userStore.isInRole(anyString())).thenReturn(true); + when(this.catalogRepository.findById(anyLong())).thenReturn(item); + when(this.catalogRepository.remove(anyLong(), any())).thenReturn(0); + LocalDateTime rowVersion = LocalDateTime.of(2024, 1, 1, 0, 0, 0, 0); + + // Action + Executable action = () -> { + this.service.deleteItemFromCatalog(1L, rowVersion); + }; + + // Assert + assertThrows(OptimisticLockingFailureException.class, action); + + } + @Test void testUpdateCatalogItem_正常系_リポジトリのupdateを1回呼出す() throws CatalogNotFoundException, PermissionDeniedException, CatalogBrandNotFoundException, CatalogCategoryNotFoundException, OptimisticLockingFailureException { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java index 268ad52ea..3a6ae038a 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java @@ -34,7 +34,7 @@ public List findByCategoryIdIn(List categoryIds) { @Override public List findByBrandIdAndCategoryId(long brandId, long categoryId, int page, int pageSize) { - int offset = pageSize * page; + int offset = pageSize * (page - 1); return mapper.findByBrandIdAndCategoryId(brandId, categoryId, pageSize, offset); } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java index f0f4f7bb3..cea7282c3 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java @@ -110,7 +110,7 @@ public ResponseEntity getCatalogItem(@PathVariable("id") public ResponseEntity getByQuery( @RequestParam(name = "brandId", defaultValue = "0") long brandId, @RequestParam(name = "categoryId", defaultValue = "0") long categoryId, - @RequestParam(name = "page", defaultValue = "0") int page, + @RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize) throws PermissionDeniedException { List items = this.service.getCatalogItemsByAdmin(brandId, categoryId, page, pageSize) diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java index ff18f1ac5..61d036433 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java @@ -1,19 +1,36 @@ package com.dressca.web.admin.controller.dto.catalog; import java.util.List; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NoArgsConstructor; /** * 検索したカタログアイテムの情報を取得する際に用いるdtoクラスです。 */ @Data -@NoArgsConstructor -@AllArgsConstructor public class PagedListOfCatalogItemResponse { private List items; private int totalCount; private int page; private int pageSize; + private int totalPages; + private boolean hasPrevious; + private boolean hasNext; + + /** + * コンストラクタ。 + * + * @param items カタログアイテムのリスト。 + * @param totalCount カタログアイテムの合計数。 + * @param page 現在のページ番号。 + * @param pageSize ページ数の合計。 + */ + public PagedListOfCatalogItemResponse(List items, int totalCount, int page, int pageSize) { + this.items = items; + this.totalCount = totalCount; + this.page = page; + this.pageSize = pageSize; + this.totalPages = this.totalCount / this.pageSize + (this.totalCount % this.pageSize == 0 ? 0 : 1); + this.hasPrevious = this.page > 1; + this.hasNext = this.page < this.totalPages; + } } diff --git a/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/CatalogItemsController.java b/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/CatalogItemsController.java index 24139cdba..eb231feb9 100644 --- a/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/CatalogItemsController.java +++ b/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/CatalogItemsController.java @@ -50,7 +50,7 @@ public class CatalogItemsController { public ResponseEntity getByQuery( @RequestParam(name = "brandId", defaultValue = "0") long brandId, @RequestParam(name = "categoryId", defaultValue = "0") long categoryId, - @RequestParam(name = "page", defaultValue = "0") int page, + @RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize) { List items = service.getCatalogItemsByConsumer(brandId, categoryId, page, pageSize).stream() .map(CatalogItemMapper::convert) diff --git a/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/dto/catalog/PagedListOfCatalogItemResponse.java b/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/dto/catalog/PagedListOfCatalogItemResponse.java index f0a1a0335..cb0bbf54c 100644 --- a/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/dto/catalog/PagedListOfCatalogItemResponse.java +++ b/samples/web-csr/dressca-backend/web-consumer/src/main/java/com/dressca/web/consumer/controller/dto/catalog/PagedListOfCatalogItemResponse.java @@ -1,19 +1,36 @@ package com.dressca.web.consumer.controller.dto.catalog; import java.util.List; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NoArgsConstructor; /** * 検索したカタログアイテムの情報を取得する際に用いるdtoクラスです。 */ @Data -@NoArgsConstructor -@AllArgsConstructor public class PagedListOfCatalogItemResponse { private List items; private int totalCount; private int page; private int pageSize; + private int totalPages; + private boolean hasPrevious; + private boolean hasNext; + + /** + * コンストラクタ。 + * + * @param items カタログアイテムのリスト。 + * @param totalCount カタログアイテムの合計数。 + * @param page 現在のページ番号。 + * @param pageSize ページ数の合計。 + */ + public PagedListOfCatalogItemResponse(List items, int totalCount, int page, int pageSize) { + this.items = items; + this.totalCount = totalCount; + this.page = page; + this.pageSize = pageSize; + this.totalPages = this.totalCount / this.pageSize + (this.totalCount % this.pageSize == 0 ? 0 : 1); + this.hasPrevious = this.page > 1; + this.hasNext = this.page < this.totalPages; + } } From 541c646bcc20ae89a3af2c2508d6aac18913fc25 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:20:17 +0900 Subject: [PATCH 13/16] =?UTF-8?q?admin=E3=81=AEAPI=E4=BB=95=E6=A7=98?= =?UTF-8?q?=E6=9B=B8=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-docs/web-admin/api-specification.json | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json index abf0f1fda..2f0f1f12a 100644 --- a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json +++ b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json @@ -426,11 +426,7 @@ "content": { "application/json": { "schema": { -<<<<<<< HEAD "$ref": "#/components/schemas/GetCatalogItemResponse" -======= - "$ref": "#/components/schemas/CatalogItemResponse" ->>>>>>> develop/admin/dressca-admin-main } } }, @@ -627,7 +623,6 @@ "price", "productCode", "rowVersion" -<<<<<<< HEAD ] }, "GetLoginUserResponse": { @@ -646,8 +641,6 @@ "required": [ "roles", "userName" -======= ->>>>>>> develop/admin/dressca-admin-main ] }, "Link": { @@ -765,31 +758,8 @@ "price", "productCode", "rowVersion" -<<<<<<< HEAD -======= - ] - }, - "UserResponse": { - "type": "object", - "properties": { - "role": { - "type": "string" - }, - "userName": { - "type": "string" - } - }, - "required": [ - "role", - "userName" ->>>>>>> develop/admin/dressca-admin-main ] } } } -} -} -}, -"required": [ -"role", -"userName" \ No newline at end of file +} \ No newline at end of file From cdd7b7ad3bc964e65db246ea7c5cf8876dc4e236 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:37:58 +0900 Subject: [PATCH 14/16] =?UTF-8?q?admin=E3=81=AEPagedListOfCatalogItemRespo?= =?UTF-8?q?nse=E3=82=92PagedListOfGetCatalogItemResponse=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-docs/web-admin/api-specification.json | 4 ++-- .../web/admin/controller/CatalogItemsController.java | 9 +++++---- ...ponse.java => PagedListOfGetCatalogItemResponse.java} | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) rename samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/{PagedListOfCatalogItemResponse.java => PagedListOfGetCatalogItemResponse.java} (85%) diff --git a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json index 2f0f1f12a..53a41ea9f 100644 --- a/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json +++ b/samples/web-csr/dressca-backend/api-docs/web-admin/api-specification.json @@ -247,7 +247,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PagedListOfCatalogItemResponse" + "$ref": "#/components/schemas/PagedListOfGetCatalogItemResponse" } } }, @@ -654,7 +654,7 @@ } } }, - "PagedListOfCatalogItemResponse": { + "PagedListOfGetCatalogItemResponse": { "type": "object", "properties": { "hasNext": { diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java index cea7282c3..fda9c9fbf 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java @@ -16,7 +16,7 @@ import com.dressca.systemcommon.exception.OptimisticLockingFailureException; import com.dressca.systemcommon.exception.SystemException; import com.dressca.web.admin.controller.dto.catalog.GetCatalogItemResponse; -import com.dressca.web.admin.controller.dto.catalog.PagedListOfCatalogItemResponse; +import com.dressca.web.admin.controller.dto.catalog.PagedListOfGetCatalogItemResponse; import com.dressca.web.admin.controller.dto.catalog.PostCatalogItemRequest; import com.dressca.web.admin.controller.dto.catalog.PutCatalogItemRequest; import com.dressca.web.admin.mapper.CatalogItemMapper; @@ -100,14 +100,14 @@ public ResponseEntity getCatalogItem(@PathVariable("id") */ @Operation(summary = "カタログアイテムを検索して返します.", description = "カタログアイテムを検索して返します.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PagedListOfCatalogItemResponse.class))), + @ApiResponse(responseCode = "200", description = "成功。", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PagedListOfGetCatalogItemResponse.class))), @ApiResponse(responseCode = "400", description = "リクエストエラー。", content = @Content), @ApiResponse(responseCode = "401", description = "未認証。", content = @Content), @ApiResponse(responseCode = "404", description = "失敗。", content = @Content), @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content), }) @GetMapping - public ResponseEntity getByQuery( + public ResponseEntity getByQuery( @RequestParam(name = "brandId", defaultValue = "0") long brandId, @RequestParam(name = "categoryId", defaultValue = "0") long categoryId, @RequestParam(name = "page", defaultValue = "1") int page, @@ -118,7 +118,8 @@ public ResponseEntity getByQuery( .map(CatalogItemMapper::convert).collect(Collectors.toList()); int totalCount = this.service.countCatalogItems(brandId, categoryId); - PagedListOfCatalogItemResponse returnValue = new PagedListOfCatalogItemResponse(items, totalCount, page, pageSize); + PagedListOfGetCatalogItemResponse returnValue = new PagedListOfGetCatalogItemResponse(items, totalCount, page, + pageSize); return ResponseEntity.ok().body(returnValue); } diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfGetCatalogItemResponse.java similarity index 85% rename from samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java rename to samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfGetCatalogItemResponse.java index 61d036433..1cf4cf802 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfCatalogItemResponse.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/dto/catalog/PagedListOfGetCatalogItemResponse.java @@ -7,7 +7,7 @@ * 検索したカタログアイテムの情報を取得する際に用いるdtoクラスです。 */ @Data -public class PagedListOfCatalogItemResponse { +public class PagedListOfGetCatalogItemResponse { private List items; private int totalCount; private int page; @@ -24,7 +24,7 @@ public class PagedListOfCatalogItemResponse { * @param page 現在のページ番号。 * @param pageSize ページ数の合計。 */ - public PagedListOfCatalogItemResponse(List items, int totalCount, int page, int pageSize) { + public PagedListOfGetCatalogItemResponse(List items, int totalCount, int page, int pageSize) { this.items = items; this.totalCount = totalCount; this.page = page; From 273aee06eb607c2d3db87c1776d28b2a09cafb3d Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:40:12 +0900 Subject: [PATCH 15/16] =?UTF-8?q?admin=E3=81=A8consumer=E3=81=AEdependabot?= =?UTF-8?q?=20version=20update=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/dependabot.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 288801633..336933678 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -117,6 +117,30 @@ updates: - "gradle" - "dependencies" + - package-ecosystem: "gradle" + directory: "/samples/web-csr/dressca-backend/web-admin" + schedule: + interval: "daily" + open-pull-requests-limit: 20 + commit-message: + prefix: "gradle-web-admin" + labels: + - "target: Dressca" + - "gradle" + - "dependencies" + + - package-ecosystem: "gradle" + directory: "/samples/web-csr/dressca-backend/web-consumer" + schedule: + interval: "daily" + open-pull-requests-limit: 20 + commit-message: + prefix: "gradle-web-consumer" + labels: + - "target: Dressca" + - "gradle" + - "dependencies" + # Azure AD B2C - package-ecosystem: "npm" directory: "/samples/azure-ad-b2c-sample/auth-frontend" From 495fa2575fdd8466c41bca1620a6874496b82ac2 Mon Sep 17 00:00:00 2001 From: yoshidakenji <181298858+kenjiyoshid-a@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:22:56 +0900 Subject: [PATCH 16/16] =?UTF-8?q?=E6=8C=87=E6=91=98=E4=BA=8B=E9=A0=85?= =?UTF-8?q?=E3=81=B8=E3=81=AE=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/admin/controller/CatalogItemsController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java index fda9c9fbf..00e06a6d1 100644 --- a/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java +++ b/samples/web-csr/dressca-backend/web-admin/src/main/java/com/dressca/web/admin/controller/CatalogItemsController.java @@ -11,6 +11,7 @@ import com.dressca.applicationcore.catalog.CatalogCategoryNotFoundException; import com.dressca.applicationcore.catalog.CatalogItem; import com.dressca.applicationcore.catalog.CatalogNotFoundException; +import com.dressca.applicationcore.constant.UserRoleConstant; import com.dressca.systemcommon.constant.ExceptionIdConstant; import com.dressca.systemcommon.constant.SystemPropertyConstants; import com.dressca.systemcommon.exception.OptimisticLockingFailureException; @@ -50,7 +51,7 @@ @Tag(name = "CatalogItems", description = "カタログアイテムの情報にアクセスする API コントローラーです.") @RequestMapping("/api/catalog-items") @AllArgsConstructor -@PreAuthorize(value = "hasAuthority('ROLE_ADMIN')") +@PreAuthorize(value = "hasAuthority('" + UserRoleConstant.ADMIN + "')") public class CatalogItemsController { @Autowired @@ -93,7 +94,7 @@ public ResponseEntity getCatalogItem(@PathVariable("id") * * @param brandId ブランドID。未指定の場合は0。 * @param categoryId カテゴリID。未指定の場合は0。 - * @param page ページ番号。未指定の場合は0。 + * @param page ページ番号。未指定の場合は1。 * @param pageSize ページサイズ。未指定の場合は20。 * @return カタログアイテムの一覧。 * @throws PermissionDeniedException 認可エラー。 @@ -168,7 +169,7 @@ public ResponseEntity postCatalogItem(@RequestBody PostCatalogItemR @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content), }) @DeleteMapping("{catalogItemId}") - public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") long catalogItemId, + public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") long catalogItemId, @RequestParam LocalDateTime rowVersion) throws PermissionDeniedException, OptimisticLockingFailureException { try { @@ -200,7 +201,7 @@ public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemId") lon @ApiResponse(responseCode = "500", description = "サーバーエラー。", content = @Content), }) @PutMapping("{catalogItemId}") - public ResponseEntity putCatalogItem(@PathVariable("catalogItemId") long catalogItemId, + public ResponseEntity putCatalogItem(@PathVariable("catalogItemId") long catalogItemId, @RequestBody PutCatalogItemRequest putCatalogItemRequest) throws PermissionDeniedException, OptimisticLockingFailureException { try {