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" 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 cb3a3a2b9..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 @@ -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": "カタログカテゴリの一覧を取得します.", @@ -229,20 +247,23 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PagedListOfCatalogItemResponse" + "$ref": "#/components/schemas/PagedListOfGetCatalogItemResponse" } } }, - "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": { @@ -576,7 +654,7 @@ } } }, - "PagedListOfCatalogItemResponse": { + "PagedListOfGetCatalogItemResponse": { "type": "object", "properties": { "hasNext": { @@ -588,7 +666,7 @@ "items": { "type": "array", "items": { - "$ref": "#/components/schemas/CatalogItemResponse" + "$ref": "#/components/schemas/GetCatalogItemResponse" } }, "page": { @@ -681,21 +759,6 @@ "productCode", "rowVersion" ] - }, - "UserResponse": { - "type": "object", - "properties": { - "role": { - "type": "string" - }, - "userName": { - "type": "string" - } - }, - "required": [ - "role", - "userName" - ] } } } 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..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,6 +21,7 @@ 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.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/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/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/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/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/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} 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<>(); } /** 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 f6f146a4d..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 @@ -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; @@ -10,12 +11,13 @@ 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; import com.dressca.systemcommon.exception.SystemException; -import com.dressca.web.admin.controller.dto.catalog.CatalogItemResponse; -import com.dressca.web.admin.controller.dto.catalog.PagedListOfCatalogItemResponse; +import com.dressca.web.admin.controller.dto.catalog.GetCatalogItemResponse; +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; @@ -49,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 @@ -62,16 +64,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,84 +85,95 @@ 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 brandId ブランドID。未指定の場合は0。 + * @param categoryId カテゴリID。未指定の場合は0。 * @param page ページ番号。未指定の場合は1。 * @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 = 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, @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); - PagedListOfCatalogItemResponse returnValue = new PagedListOfCatalogItemResponse(items, totalCount, page, pageSize); + PagedListOfGetCatalogItemResponse returnValue = new PagedListOfGetCatalogItemResponse(items, totalCount, page, + pageSize); return ResponseEntity.ok().body(returnValue); } /** * カタログにアイテムを追加します。 * - * @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,18 +188,20 @@ public ResponseEntity deleteCatalogItem(@PathVariable("catalogItemI * @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, + public ResponseEntity putCatalogItem(@PathVariable("catalogItemId") long catalogItemId, @RequestBody PutCatalogItemRequest putCatalogItemRequest) throws PermissionDeniedException, OptimisticLockingFailureException { try { 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); } 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/PagedListOfGetCatalogItemResponse.java similarity index 81% 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 10daf3ec9..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,8 +7,8 @@ * 検索したカタログアイテムの情報を取得する際に用いるdtoクラスです。 */ @Data -public class PagedListOfCatalogItemResponse { - private List items; +public class PagedListOfGetCatalogItemResponse { + private List items; private int totalCount; private int page; private int pageSize; @@ -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; 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/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()); 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()); }