diff --git a/src/Bakabase.Service/Controllers/CategoryController.cs b/src/Bakabase.Service/Controllers/CategoryController.cs index 9e35cb6..62c2355 100644 --- a/src/Bakabase.Service/Controllers/CategoryController.cs +++ b/src/Bakabase.Service/Controllers/CategoryController.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using System.Linq; using System.Threading.Tasks; using Bakabase.Abstractions.Models.Domain; using Bakabase.Abstractions.Models.Input; @@ -8,6 +9,8 @@ using Bakabase.InsideWorld.Models.RequestModels; using Bakabase.Modules.Enhancer.Abstractions.Services; using Bakabase.Modules.Enhancer.Models.Input; +using Bakabase.Service.Extensions; +using Bakabase.Service.Models.View; using Bootstrap.Components.Miscellaneous.ResponseBuilders; using Bootstrap.Models.ResponseModels; using Microsoft.AspNetCore.Mvc; @@ -25,18 +28,19 @@ IMediaLibraryService mediaLibraryService { [HttpGet("{id:int}")] [SwaggerOperation(OperationId = "GetCategory")] - public async Task> Get(int id, + public async Task> Get(int id, [FromQuery] CategoryAdditionalItem additionalItems = CategoryAdditionalItem.None) { - return new SingletonResponse(await service.Get(id, additionalItems)); + return new SingletonResponse((await service.Get(id, additionalItems))?.ToViewModel()); } [HttpGet] [SwaggerOperation(OperationId = "GetAllCategories")] - public async Task> GetAll( + public async Task> GetAll( [FromQuery] CategoryAdditionalItem additionalItems = CategoryAdditionalItem.None) { - return new ListResponse(await service.GetAll(null, additionalItems)); + return new ListResponse( + (await service.GetAll(null, additionalItems))?.Select(x => x.ToViewModel())); } [HttpPost] @@ -53,7 +57,7 @@ public async Task Duplicate(int id, [FromBody] CategoryDuplicateIn return await service.Duplicate(id, model); } - [HttpPut("{id}")] + [HttpPatch("{id}")] [SwaggerOperation(OperationId = "PatchCategory")] public async Task Patch(int id, [FromBody] CategoryPatchInputModel model) { diff --git a/src/Bakabase.Service/Extensions/CategoryExtensions.cs b/src/Bakabase.Service/Extensions/CategoryExtensions.cs new file mode 100644 index 0000000..da5a47f --- /dev/null +++ b/src/Bakabase.Service/Extensions/CategoryExtensions.cs @@ -0,0 +1,27 @@ +using System.Linq; +using Bakabase.Abstractions.Models.Domain; +using Bakabase.Service.Models.View; + +namespace Bakabase.Service.Extensions; + +public static class CategoryExtensions +{ + public static CategoryViewModel ToViewModel(this Category model) + { + return new CategoryViewModel + { + Id = model.Id, + Name = model.Name, + Color = model.Color, + ComponentsData = model.ComponentsData, + CoverSelectionOrder = model.CoverSelectionOrder, + CreateDt = model.CreateDt, + GenerateNfo = model.GenerateNfo, + EnhancerOptions = model.EnhancerOptions, + Order = model.Order, + ResourceDisplayNameTemplate = model.ResourceDisplayNameTemplate, + CustomProperties = model.CustomProperties?.Select(c => new CategoryViewModel.CustomPropertyViewModel + {Id = c.Id, Name = c.Name}).ToList() + }; + } +} \ No newline at end of file diff --git a/src/Bakabase.Service/Models/View/CategoryViewModel.cs b/src/Bakabase.Service/Models/View/CategoryViewModel.cs new file mode 100644 index 0000000..a313124 --- /dev/null +++ b/src/Bakabase.Service/Models/View/CategoryViewModel.cs @@ -0,0 +1,30 @@ +using Bakabase.InsideWorld.Models.Constants; +using System.Collections.Generic; +using System; +using Bakabase.Abstractions.Models.Db; +using CategoryEnhancerOptions = Bakabase.Abstractions.Models.Domain.CategoryEnhancerOptions; + +namespace Bakabase.Service.Models.View; + +public record CategoryViewModel +{ + public int Id { get; set; } + public string Name { get; set; } = null!; + public string? Color { get; set; } + public DateTime CreateDt { get; set; } + + public int Order { get; set; } + public CategoryComponent[]? ComponentsData { get; set; } + public CoverSelectOrder CoverSelectionOrder { get; set; } + public bool GenerateNfo { get; set; } + public string? ResourceDisplayNameTemplate { get; set; } + + public List? CustomProperties { get; set; } + public List? EnhancerOptions { get; set; } + + public record CustomPropertyViewModel + { + public int Id { get; set; } + public string Name { get; set; } = null!; + } +} \ No newline at end of file diff --git a/src/ClientApp/src/sdk/Api.ts b/src/ClientApp/src/sdk/Api.ts index 49ed172..669b059 100644 --- a/src/ClientApp/src/sdk/Api.ts +++ b/src/ClientApp/src/sdk/Api.ts @@ -1641,6 +1641,30 @@ export interface BakabaseServiceModelsInputSavedSearchAddInputModel { name: string; } +export interface BakabaseServiceModelsViewCategoryViewModel { + /** @format int32 */ + id: number; + name: string; + color?: string; + /** @format date-time */ + createDt: string; + /** @format int32 */ + order: number; + componentsData?: BakabaseAbstractionsModelsDbCategoryComponent[]; + /** [1: FilenameAscending, 2: FileModifyDtDescending] */ + coverSelectionOrder: BakabaseInsideWorldModelsConstantsCoverSelectOrder; + generateNfo: boolean; + resourceDisplayNameTemplate?: string; + customProperties?: BakabaseServiceModelsViewCategoryViewModelCustomPropertyViewModel[]; + enhancerOptions?: BakabaseAbstractionsModelsDomainCategoryEnhancerOptions[]; +} + +export interface BakabaseServiceModelsViewCategoryViewModelCustomPropertyViewModel { + /** @format int32 */ + id: number; + name: string; +} + export interface BakabaseServiceModelsViewCustomPropertyViewModel { /** [1: Internal, 2: Reserved, 4: Custom, 7: All] */ pool: BakabaseAbstractionsModelsDomainConstantsPropertyPool; @@ -1796,13 +1820,6 @@ export interface BootstrapModelsResponseModelsBaseResponse { message?: string; } -export interface BootstrapModelsResponseModelsListResponse1BakabaseAbstractionsModelsDomainCategory { - /** @format int32 */ - code: number; - message?: string; - data?: BakabaseAbstractionsModelsDomainCategory[]; -} - export interface BootstrapModelsResponseModelsListResponse1BakabaseAbstractionsModelsDomainComponentDescriptor { /** @format int32 */ code: number; @@ -1908,6 +1925,13 @@ export interface BootstrapModelsResponseModelsListResponse1BakabaseModulesThirdP data?: BakabaseModulesThirdPartyThirdPartiesBilibiliModelsFavorites[]; } +export interface BootstrapModelsResponseModelsListResponse1BakabaseServiceModelsViewCategoryViewModel { + /** @format int32 */ + code: number; + message?: string; + data?: BakabaseServiceModelsViewCategoryViewModel[]; +} + export interface BootstrapModelsResponseModelsListResponse1BakabaseServiceModelsViewCustomPropertyViewModel { /** @format int32 */ code: number; @@ -2030,13 +2054,6 @@ export interface BootstrapModelsResponseModelsSingletonResponse1BakabaseAbstract data?: BakabaseAbstractionsModelsDomainCategoryEnhancerOptions; } -export interface BootstrapModelsResponseModelsSingletonResponse1BakabaseAbstractionsModelsDomainCategory { - /** @format int32 */ - code: number; - message?: string; - data?: BakabaseAbstractionsModelsDomainCategory; -} - export interface BootstrapModelsResponseModelsSingletonResponse1BakabaseAbstractionsModelsDomainComponentDescriptor { /** @format int32 */ code: number; @@ -2262,6 +2279,13 @@ export interface BootstrapModelsResponseModelsSingletonResponse1BakabaseModulesP data?: BakabaseModulesPropertyModelsViewCustomPropertyTypeConversionPreviewViewModel; } +export interface BootstrapModelsResponseModelsSingletonResponse1BakabaseServiceModelsViewCategoryViewModel { + /** @format int32 */ + code: number; + message?: string; + data?: BakabaseServiceModelsViewCategoryViewModel; +} + export interface BootstrapModelsResponseModelsSingletonResponse1BakabaseServiceModelsViewCustomPropertyViewModel { /** @format int32 */ code: number; @@ -3850,7 +3874,7 @@ export class Api extends HttpClient - this.request({ + this.request({ path: `/category/${id}`, method: "GET", query: query, @@ -3863,7 +3887,7 @@ export class Api extends HttpClient extends HttpClient this.request({ path: `/category/${id}`, - method: "PUT", + method: "PATCH", body: data, type: ContentType.Json, format: "json", @@ -3908,7 +3932,7 @@ export class Api extends HttpClient - this.request({ + this.request({ path: `/category`, method: "GET", query: query, diff --git a/src/ClientApp/src/sdk/apis.js b/src/ClientApp/src/sdk/apis.js index 9177b2c..365fc89 100644 --- a/src/ClientApp/src/sdk/apis.js +++ b/src/ClientApp/src/sdk/apis.js @@ -1481,13 +1481,13 @@ export const PatchCategory = function(parameters = {}) { queryParameters[parameterName] = parameters.$queryParameters[parameterName] }); } - return request('put', domain + path, body, queryParameters, form, config) + return request('patch', domain + path, body, queryParameters, form, config) } export const PatchCategory_RAW_URL = function() { return '/category/{id}' } export const PatchCategory_TYPE = function() { - return 'put' + return 'patch' } export const PatchCategoryURL = function(parameters = {}) { let queryParameters = {} diff --git a/src/ClientApp/src/sdk/constants.ts b/src/ClientApp/src/sdk/constants.ts index 3b50de7..3ca8dcb 100644 --- a/src/ClientApp/src/sdk/constants.ts +++ b/src/ClientApp/src/sdk/constants.ts @@ -82,22 +82,6 @@ export enum SpecialTextType {Useless = 1, Wrapper = 3, Standardization = 4, Volu export const specialTextTypes = Object.keys(SpecialTextType).filter(k => typeof SpecialTextType[k] === 'number').map(t => ({label: t, value: SpecialTextType[t]})); export enum StandardValueType {String = 1, ListString = 2, Decimal = 3, Link = 4, Boolean = 5, DateTime = 6, Time = 7, ListListString = 8, ListTag = 9} export const standardValueTypes = Object.keys(StandardValueType).filter(k => typeof StandardValueType[k] === 'number').map(t => ({label: t, value: StandardValueType[t]})); -export enum EnhancerId {Bakabase = 1, ExHentai = 2, Bangumi = 3, DLsite = 4, Regex = 5} -export const enhancerIds = Object.keys(EnhancerId).filter(k => typeof EnhancerId[k] === 'number').map(t => ({label: t, value: EnhancerId[t]})); -export enum RegexEnhancerTarget {CaptureGroups = 0} -export const regexEnhancerTargets = Object.keys(RegexEnhancerTarget).filter(k => typeof RegexEnhancerTarget[k] === 'number').map(t => ({label: t, value: RegexEnhancerTarget[t]})); -export enum ExHentaiEnhancerTarget {Name = 1, Introduction = 2, Rating = 3, Tags = 4, Cover = 5} -export const exHentaiEnhancerTargets = Object.keys(ExHentaiEnhancerTarget).filter(k => typeof ExHentaiEnhancerTarget[k] === 'number').map(t => ({label: t, value: ExHentaiEnhancerTarget[t]})); -export enum DLsiteEnhancerTarget {Name = 0, Cover = 1, PropertiesOnTheRightSideOfCover = 2, Introduction = 3, Rating = 4} -export const dLsiteEnhancerTargets = Object.keys(DLsiteEnhancerTarget).filter(k => typeof DLsiteEnhancerTarget[k] === 'number').map(t => ({label: t, value: DLsiteEnhancerTarget[t]})); -export enum BangumiEnhancerTarget {Name = 1, Tags = 2, Introduction = 3, Rating = 4, OtherPropertiesInLeftPanel = 5, Cover = 6} -export const bangumiEnhancerTargets = Object.keys(BangumiEnhancerTarget).filter(k => typeof BangumiEnhancerTarget[k] === 'number').map(t => ({label: t, value: BangumiEnhancerTarget[t]})); -export enum BakabaseEnhancerTarget {Name = 1, Publisher = 2, ReleaseDt = 3, VolumeName = 4, VolumeTitle = 5, Originals = 6, Language = 7, Cover = 8} -export const bakabaseEnhancerTargets = Object.keys(BakabaseEnhancerTarget).filter(k => typeof BakabaseEnhancerTarget[k] === 'number').map(t => ({label: t, value: BakabaseEnhancerTarget[t]})); -export enum EnhancementAdditionalItem {None = 0, GeneratedPropertyValue = 1} -export const enhancementAdditionalItems = Object.keys(EnhancementAdditionalItem).filter(k => typeof EnhancementAdditionalItem[k] === 'number').map(t => ({label: t, value: EnhancementAdditionalItem[t]})); -export enum EnhancerTargetOptionsItem {AutoBindProperty = 1, AutoMatchMultilevelString = 2, CoverSelectOrder = 3} -export const enhancerTargetOptionsItems = Object.keys(EnhancerTargetOptionsItem).filter(k => typeof EnhancerTargetOptionsItem[k] === 'number').map(t => ({label: t, value: EnhancerTargetOptionsItem[t]})); export enum CoverDiscoverResultType {LocalFile = 1, FromAdditionalSource = 2, Icon = 3} export const coverDiscoverResultTypes = Object.keys(CoverDiscoverResultType).filter(k => typeof CoverDiscoverResultType[k] === 'number').map(t => ({label: t, value: CoverDiscoverResultType[t]})); export enum ResourceExistence {Exist = 1, Maybe = 2, New = 3} @@ -194,6 +178,22 @@ export enum TagAdditionalItem {None = 0, GroupName = 1, PreferredAlias = 2} export const tagAdditionalItems = Object.keys(TagAdditionalItem).filter(k => typeof TagAdditionalItem[k] === 'number').map(t => ({label: t, value: TagAdditionalItem[t]})); export enum TagGroupAdditionalItem {Tags = 1, PreferredAlias = 2, TagNamePreferredAlias = 4} export const tagGroupAdditionalItems = Object.keys(TagGroupAdditionalItem).filter(k => typeof TagGroupAdditionalItem[k] === 'number').map(t => ({label: t, value: TagGroupAdditionalItem[t]})); +export enum EnhancerId {Bakabase = 1, ExHentai = 2, Bangumi = 3, DLsite = 4, Regex = 5} +export const enhancerIds = Object.keys(EnhancerId).filter(k => typeof EnhancerId[k] === 'number').map(t => ({label: t, value: EnhancerId[t]})); +export enum RegexEnhancerTarget {CaptureGroups = 0} +export const regexEnhancerTargets = Object.keys(RegexEnhancerTarget).filter(k => typeof RegexEnhancerTarget[k] === 'number').map(t => ({label: t, value: RegexEnhancerTarget[t]})); +export enum ExHentaiEnhancerTarget {Name = 1, Introduction = 2, Rating = 3, Tags = 4, Cover = 5} +export const exHentaiEnhancerTargets = Object.keys(ExHentaiEnhancerTarget).filter(k => typeof ExHentaiEnhancerTarget[k] === 'number').map(t => ({label: t, value: ExHentaiEnhancerTarget[t]})); +export enum DLsiteEnhancerTarget {Name = 0, Cover = 1, PropertiesOnTheRightSideOfCover = 2, Introduction = 3, Rating = 4} +export const dLsiteEnhancerTargets = Object.keys(DLsiteEnhancerTarget).filter(k => typeof DLsiteEnhancerTarget[k] === 'number').map(t => ({label: t, value: DLsiteEnhancerTarget[t]})); +export enum BangumiEnhancerTarget {Name = 1, Tags = 2, Introduction = 3, Rating = 4, OtherPropertiesInLeftPanel = 5, Cover = 6} +export const bangumiEnhancerTargets = Object.keys(BangumiEnhancerTarget).filter(k => typeof BangumiEnhancerTarget[k] === 'number').map(t => ({label: t, value: BangumiEnhancerTarget[t]})); +export enum BakabaseEnhancerTarget {Name = 1, Publisher = 2, ReleaseDt = 3, VolumeName = 4, VolumeTitle = 5, Originals = 6, Language = 7, Cover = 8} +export const bakabaseEnhancerTargets = Object.keys(BakabaseEnhancerTarget).filter(k => typeof BakabaseEnhancerTarget[k] === 'number').map(t => ({label: t, value: BakabaseEnhancerTarget[t]})); +export enum EnhancementAdditionalItem {None = 0, GeneratedPropertyValue = 1} +export const enhancementAdditionalItems = Object.keys(EnhancementAdditionalItem).filter(k => typeof EnhancementAdditionalItem[k] === 'number').map(t => ({label: t, value: EnhancementAdditionalItem[t]})); +export enum EnhancerTargetOptionsItem {AutoBindProperty = 1, AutoMatchMultilevelString = 2, CoverSelectOrder = 3} +export const enhancerTargetOptionsItems = Object.keys(EnhancerTargetOptionsItem).filter(k => typeof EnhancerTargetOptionsItem[k] === 'number').map(t => ({label: t, value: EnhancerTargetOptionsItem[t]})); export enum AliasExceptionType {ConflictAliasGroup = 1} export const aliasExceptionTypes = Object.keys(AliasExceptionType).filter(k => typeof AliasExceptionType[k] === 'number').map(t => ({label: t, value: AliasExceptionType[t]})); export enum CaptchaType {Image = 1, SmsMessage = 2}