diff --git a/docs/en/UI/Angular/Config-State-Service.md b/docs/en/UI/Angular/Config-State-Service.md index 11415eb771..c457184fc2 100644 --- a/docs/en/UI/Angular/Config-State-Service.md +++ b/docs/en/UI/Angular/Config-State-Service.md @@ -120,7 +120,7 @@ Please refer to `ApplicationConfigurationDto` type for all the properties you ca You can get the application configuration response and set the `ConfigStateService` state value as shown below: ```js -import {ApplicationConfigurationService, ConfigStateService} from '@abp/ng.core'; +import {AbpApplicationConfigurationService, ConfigStateService} from '@abp/ng.core'; constructor(private abpApplicationConfigurationService: AbpApplicationConfigurationService, private config: ConfigStateService) { this.abpApplicationConfigurationService.get().subscribe(config => { diff --git a/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpStringToEnumConverter.cs b/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpStringToEnumConverter.cs index c4720c92db..6b7f32807e 100644 --- a/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpStringToEnumConverter.cs +++ b/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpStringToEnumConverter.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; @@ -48,4 +47,14 @@ public class AbpStringToEnumConverter : JsonConverter JsonSerializer.Serialize(writer, value, _writeJsonSerializerOptions); } + + public override T ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return (T)Enum.Parse(typeToConvert, reader.GetString()); + } + + public override void WriteAsPropertyName(Utf8JsonWriter writer, T value, JsonSerializerOptions options) + { + writer.WritePropertyName(Enum.GetName(typeof(T), value)); + } } diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpStringToEnum_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpStringToEnum_Tests.cs index d3bba36534..8336b4ce7d 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpStringToEnum_Tests.cs +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpStringToEnum_Tests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text.Json; using Shouldly; using Volo.Abp.Json.SystemTextJson.JsonConverters; @@ -26,6 +27,16 @@ namespace Volo.Abp.Json testClass = JsonSerializer.Deserialize("{\"Day\": 1}", options); testClass.ShouldNotBeNull(); testClass.Day.ShouldBe(DayOfWeek.Monday); + + var dictionary = JsonSerializer.Deserialize>("{\"Monday\":\"Mo\"}", options); + dictionary.ShouldNotBeNull(); + dictionary.Keys.ShouldContain(DayOfWeek.Monday); + dictionary.Values.ShouldContain("Mo"); + + dictionary = JsonSerializer.Deserialize>("{\"1\":\"Mo\"}", options); + dictionary.ShouldNotBeNull(); + dictionary.Keys.ShouldContain(DayOfWeek.Monday); + dictionary.Values.ShouldContain("Mo"); } [Fact] @@ -45,6 +56,13 @@ namespace Volo.Abp.Json }); testClassJson.ShouldBe("{\"Day\":1}"); + + testClassJson = JsonSerializer.Serialize(new Dictionary + { + {DayOfWeek.Monday, "Mo"} + }, options); + + testClassJson.ShouldBe("{\"Monday\":\"Mo\"}"); } class TestClass diff --git a/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template b/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template index 78fb27c33d..1e1cc4564a 100644 --- a/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template +++ b/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template @@ -7,12 +7,18 @@ export class <%= name %>Service { apiName = '<%= apiName %>';<% for (let {body, signature} of methods) { %> + <% + const isBlob = body.isBlobMethod() ; + const responseType = isBlob ? "Blob":body.responseType; + %> <%= camel(signature.name) %> = (<%= serializeParameters(signature.parameters) %>) => - this.restService.request<<%= body.requestType %>, <%= body.responseType %>>({ - method: '<%= body.method %>',<% + this.restService.request<<%= body.requestType %>, <%= responseType %>>({ + method: '<%= body.method %>',<% if (body.responseType === 'string') { %> - responseType: 'text',<% } %> + responseType: 'text',<% } %><% + if (isBlob) { %> + responseType: 'blob',<% } %> url: <%= body.url %>,<% if (body.params.length) { %> params: { <%= body.params.join(', ') %> },<% } diff --git a/npm/ng-packs/packages/schematics/src/constants/volo.ts b/npm/ng-packs/packages/schematics/src/constants/volo.ts index 00fde72c79..d45a4b9e72 100644 --- a/npm/ng-packs/packages/schematics/src/constants/volo.ts +++ b/npm/ng-packs/packages/schematics/src/constants/volo.ts @@ -1 +1,2 @@ export const VOLO_REGEX = /^Volo\.Abp\.(Application\.Dtos|ObjectExtending)/; +export const VOLO_REMOTE_STREAM_CONTENT = 'Volo.Abp.Content.IRemoteStreamContent' diff --git a/npm/ng-packs/packages/schematics/src/models/method.ts b/npm/ng-packs/packages/schematics/src/models/method.ts index d8f56e383e..d54d4303b9 100644 --- a/npm/ng-packs/packages/schematics/src/models/method.ts +++ b/npm/ng-packs/packages/schematics/src/models/method.ts @@ -4,6 +4,7 @@ import { getParamName } from '../utils/methods'; import { ParameterInBody } from './api-definition'; import { Property } from './model'; import { Omissible } from './util'; +import {VOLO_REMOTE_STREAM_CONTENT} from "../constants"; // eslint-disable-next-line @typescript-eslint/no-var-requires const shouldQuote = require('should-quote'); @@ -39,6 +40,7 @@ export class Body { body?: string; method: string; params: string[] = []; + responseTypeWithNamespace: string; requestType = 'any'; responseType: string; url: string; @@ -77,6 +79,10 @@ export class Body { this.setUrlQuotes(); } + isBlobMethod(){ + return this.responseTypeWithNamespace === VOLO_REMOTE_STREAM_CONTENT + } + private setUrlQuotes() { this.url = /{/.test(this.url) ? `\`/${this.url}\`` : `'/${this.url}'`; } @@ -84,5 +90,5 @@ export class Body { export type BodyOptions = Omissible< Omit, - 'params' | 'requestType' + 'params' | 'requestType' | 'isBlobMethod' >; diff --git a/npm/ng-packs/packages/schematics/src/utils/service.ts b/npm/ng-packs/packages/schematics/src/utils/service.ts index 4e2fdc7c02..28ce82e3f7 100644 --- a/npm/ng-packs/packages/schematics/src/utils/service.ts +++ b/npm/ng-packs/packages/schematics/src/utils/service.ts @@ -22,6 +22,7 @@ import { } from './type'; import { eBindingSourceId } from '../enums'; import { camelizeHyphen } from './text'; +import {VOLO_REMOTE_STREAM_CONTENT} from "../constants"; export function serializeParameters(parameters: Property[]) { return parameters.map(p => p.name + p.optional + ': ' + p.type + p.default, '').join(', '); @@ -38,7 +39,8 @@ export function createControllerToServiceMapper({ const name = controller.controllerName; const namespace = parseNamespace(solution, controller.type); const actions = Object.values(controller.actions); - const imports = actions.reduce(createActionToImportsReducer(solution, types, namespace), []); + const typeWithoutIRemoteStreamContent = getTypesWithoutIRemoteStreamContent(types) + const imports = actions.reduce(createActionToImportsReducer(solution, typeWithoutIRemoteStreamContent, namespace), []); imports.push(new Import({ path: '@abp/ng.core', specifiers: ['RestService'] })); imports.push(new Import({ path: '@angular/core', specifiers: ['Injectable'] })); sortImports(imports); @@ -48,6 +50,11 @@ export function createControllerToServiceMapper({ }; } +function getTypesWithoutIRemoteStreamContent(types: Record) { + const newType = {...types} + delete newType[VOLO_REMOTE_STREAM_CONTENT] + return newType +} function sortMethods(methods: Method[]) { methods.sort((a, b) => (a.signature.name > b.signature.name ? 1 : -1)); } @@ -68,7 +75,8 @@ export function createActionToBodyMapper() { return ({ httpMethod, parameters, returnValue, url }: Action) => { const responseType = adaptType(returnValue.typeSimple); - const body = new Body({ method: httpMethod, responseType, url }); + const responseTypeWithNamespace = returnValue.typeSimple; + const body = new Body({ method: httpMethod, responseType, url ,responseTypeWithNamespace}); parameters.forEach(body.registerActionParameter);