Skip to content

Commit

Permalink
reduce data size of custom properties in category view model;
Browse files Browse the repository at this point in the history
  • Loading branch information
anobaka committed Nov 1, 2024
1 parent bda6e24 commit f8a2be1
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 41 deletions.
14 changes: 9 additions & 5 deletions src/Bakabase.Service/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -25,18 +28,19 @@ IMediaLibraryService mediaLibraryService
{
[HttpGet("{id:int}")]
[SwaggerOperation(OperationId = "GetCategory")]
public async Task<SingletonResponse<Category?>> Get(int id,
public async Task<SingletonResponse<CategoryViewModel?>> Get(int id,
[FromQuery] CategoryAdditionalItem additionalItems = CategoryAdditionalItem.None)
{
return new SingletonResponse<Category?>(await service.Get(id, additionalItems));
return new SingletonResponse<CategoryViewModel?>((await service.Get(id, additionalItems))?.ToViewModel());
}

[HttpGet]
[SwaggerOperation(OperationId = "GetAllCategories")]
public async Task<ListResponse<Category>> GetAll(
public async Task<ListResponse<CategoryViewModel>> GetAll(
[FromQuery] CategoryAdditionalItem additionalItems = CategoryAdditionalItem.None)
{
return new ListResponse<Category>(await service.GetAll(null, additionalItems));
return new ListResponse<CategoryViewModel>(
(await service.GetAll(null, additionalItems))?.Select(x => x.ToViewModel()));
}

[HttpPost]
Expand All @@ -53,7 +57,7 @@ public async Task<BaseResponse> Duplicate(int id, [FromBody] CategoryDuplicateIn
return await service.Duplicate(id, model);
}

[HttpPut("{id}")]
[HttpPatch("{id}")]
[SwaggerOperation(OperationId = "PatchCategory")]
public async Task<BaseResponse> Patch(int id, [FromBody] CategoryPatchInputModel model)
{
Expand Down
27 changes: 27 additions & 0 deletions src/Bakabase.Service/Extensions/CategoryExtensions.cs
Original file line number Diff line number Diff line change
@@ -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()
};
}
}
30 changes: 30 additions & 0 deletions src/Bakabase.Service/Models/View/CategoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -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<CustomPropertyViewModel>? CustomProperties { get; set; }
public List<CategoryEnhancerOptions>? EnhancerOptions { get; set; }

public record CustomPropertyViewModel
{
public int Id { get; set; }
public string Name { get; set; } = null!;
}
}
60 changes: 42 additions & 18 deletions src/ClientApp/src/sdk/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3850,7 +3874,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
},
params: RequestParams = {},
) =>
this.request<BootstrapModelsResponseModelsSingletonResponse1BakabaseAbstractionsModelsDomainCategory, any>({
this.request<BootstrapModelsResponseModelsSingletonResponse1BakabaseServiceModelsViewCategoryViewModel, any>({
path: `/category/${id}`,
method: "GET",
query: query,
Expand All @@ -3863,7 +3887,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
*
* @tags Category
* @name PatchCategory
* @request PUT:/category/{id}
* @request PATCH:/category/{id}
*/
patchCategory: (
id: number,
Expand All @@ -3872,7 +3896,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
) =>
this.request<BootstrapModelsResponseModelsBaseResponse, any>({
path: `/category/${id}`,
method: "PUT",
method: "PATCH",
body: data,
type: ContentType.Json,
format: "json",
Expand Down Expand Up @@ -3908,7 +3932,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
},
params: RequestParams = {},
) =>
this.request<BootstrapModelsResponseModelsListResponse1BakabaseAbstractionsModelsDomainCategory, any>({
this.request<BootstrapModelsResponseModelsListResponse1BakabaseServiceModelsViewCategoryViewModel, any>({
path: `/category`,
method: "GET",
query: query,
Expand Down
4 changes: 2 additions & 2 deletions src/ClientApp/src/sdk/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
32 changes: 16 additions & 16 deletions src/ClientApp/src/sdk/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit f8a2be1

Please sign in to comment.