Skip to content

Commit

Permalink
Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
duguankui committed Feb 17, 2024
1 parent a28143e commit 3d68bf5
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 285 deletions.
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>1.0.2</Version>
<Version>1.0.4-beta2</Version>
<NoWarn>$(NoWarn);CS1591;CS0436</NoWarn>
<PackageIconUrl>https://dignite.com/assets/dignite_nupkg.png</PackageIconUrl>
<PackageProjectUrl>https://dignite.com/dignite-cms</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Text.Json;
using System;
using System.Text.Json;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Reflection;

namespace Dignite.Abp.Data;

Expand Down Expand Up @@ -29,14 +31,18 @@ public static TField GetField<TField>([NotNull] this IHasCustomFields source, [N
{
return source.GetProperty<TField>(name, defaultValue);
}
catch (AbpException)
catch (Exception exc)

Check warning on line 34 in src/Dignite.Cms.Domain.Shared/Dignite/Abp/Data/HasCustomFieldsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test

The variable 'exc' is declared but never used
{
var value = source.GetProperty(name);
if (value == null)
{
return defaultValue;
}
return JsonSerializer.Deserialize<TField>(value.ToString(), new JsonSerializerOptions(JsonSerializerDefaults.Web));

if (TypeHelper.IsPrimitiveExtended(typeof(TField)))
return ((JsonElement)value).Deserialize<TField>(JsonSerializerOptions.Default);
else
return JsonSerializer.Deserialize<TField>(value.ToString(), new JsonSerializerOptions(JsonSerializerDefaults.Web));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ public static class EntryConsts
/// </summary>
public static int MaxRevisionNotesLength { get; set; } = 512;

/// <summary>
/// Default value: index
/// </summary>
public static string DefaultSlug { get; set; } = "index";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public interface ISectionPublicAppService : IApplicationService
///
/// </summary>
/// <param name="siteId"></param>
/// <param name="url">
///
/// <param name="entryPath">
/// The entry path does not contain culture.
/// </param>
/// <returns></returns>
Task<SectionDto> FindByUrlAsync(Guid siteId, string url);
Task<SectionDto> FindByEntryPathAsync(Guid siteId, string entryPath);

Task<SectionDto> GetDefaultAsync(Guid siteId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dignite.Cms.Fields;
using Dignite.Cms.Entries;
using Dignite.Cms.Fields;
using Dignite.Cms.Sections;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -35,32 +36,34 @@ public async Task<SectionDto> FindByNameAsync(Guid siteId, string name)
await _sectionRepository.FindByNameAsync(siteId, name)
);

await FillSectionFields( dto );
await FillSectionFields(dto);
return dto;
}


public async Task<SectionDto> FindByUrlAsync(Guid siteId, string url)
/// <summary>
///
/// </summary>
/// <param name="siteId"></param>
/// <param name="entryPath">
/// The entry path does not contain culture.
/// </param>
/// <returns></returns>
public async Task<SectionDto> FindByEntryPathAsync(Guid siteId, string entryPath)
{
url = url.RemovePreFix("/").RemovePostFix("/");
var allSections = await _sectionRepository.GetListAsync(siteId, null, true, true);
allSections.ForEach((s) => s.Route.RemovePreFix("/").RemovePostFix("/"));
var section = await MatchingSectionWithEntryPath(allSections, entryPath);

foreach ( var section in allSections.OrderByDescending(s => s.Route))
/**

Check warning on line 56 in src/Dignite.Cms.Public.Application/Dignite/Cms/Public/Sections/SectionPublicAppService.cs

View workflow job for this annotation

GitHub Actions / build-test

XML comment is not placed on a valid language element
* When no matching Section is found, add /index/ to the url to try again.
* The reason is that when the Section type is SectionType.Single, the url may not contain a slug, so the default slug (i.e. index) is used to match again.
* **/
if (section == null)
{
var route = section.Route.RemovePreFix("/").RemovePostFix("/");
var extractResult = FormattedStringValueExtracter.Extract(url, route, ignoreCase: true);
if (extractResult.IsMatch)
{
var dto = ObjectMapper.Map<Section, SectionDto>(
section
);
await FillSectionFields(dto);
return dto;
}
entryPath = entryPath.EnsureEndsWith('/') + EntryConsts.DefaultSlug;
section= await MatchingSectionWithEntryPath(allSections,entryPath);
}

return null;
return section;
}

public async Task<SectionDto> GetDefaultAsync(Guid siteId)
Expand All @@ -81,6 +84,26 @@ public async Task<SectionDto> GetDefaultAsync(Guid siteId)
}
}

protected async Task<SectionDto> MatchingSectionWithEntryPath(List<Section> sections, string entryPath)
{
entryPath = entryPath.RemovePreFix("/").RemovePostFix("/");
foreach (var section in sections.OrderByDescending(s => s.Route))
{
var route = section.Route.RemovePreFix("/").RemovePostFix("/");
var extractResult = FormattedStringValueExtracter.Extract(entryPath, route, ignoreCase: true);
if (extractResult.IsMatch)
{
var dto = ObjectMapper.Map<Section, SectionDto>(
section
);
await FillSectionFields(dto);
return dto;
}
}

return null;
}

protected async Task FillSectionFields(SectionDto dto)
{
var allFields = await _fieldRepository.GetListAsync(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public virtual async Task<SectionDto> FindByNameAsync(Guid siteId, string name)
});
}

public virtual async Task<SectionDto> FindByUrlAsync(Guid siteId, string url)
public virtual async Task<SectionDto> FindByEntryPathAsync(Guid siteId, string entryPath)
{
return await RequestAsync<SectionDto>(nameof(FindByUrlAsync), new ClientProxyRequestTypeValue
return await RequestAsync<SectionDto>(nameof(FindByEntryPathAsync), new ClientProxyRequestTypeValue
{
{ typeof(Guid), siteId },
{ typeof(string), url }
{ typeof(string), entryPath }
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public async Task<SectionDto> FindByNameAsync(Guid siteId, string name)
///
/// </summary>
/// <param name="siteId"></param>
/// <param name="url">
///
/// <param name="entryPath">
/// The entry path does not contain culture.
/// </param>
/// <returns></returns>
[HttpGet]
[Route("find-by-url")]
public async Task<SectionDto> FindByUrlAsync(Guid siteId, string url)
[Route("find-by-entry-path")]
public async Task<SectionDto> FindByEntryPathAsync(Guid siteId, string entryPath)
{
return await _sectionAppService.FindByUrlAsync(siteId, url);
return await _sectionAppService.FindByEntryPathAsync(siteId, entryPath);
}

[HttpGet]
Expand All @@ -49,7 +49,7 @@ public async Task<SectionDto> GetAsync(Guid sectionId)
}

[HttpGet]
[Route("get-default")]
[Route("get-default-by-siteId/{siteId:guid}")]
public async Task<SectionDto> GetDefaultAsync(Guid siteId)
{
return await _sectionAppService.GetDefaultAsync(siteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public static IApplicationBuilder UseCmsRoute(this IApplicationBuilder app)
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "cms-home",
name: RouteConsts.HomeRouteName,
pattern: "/",
defaults: new { controller = CmsController.ControllerName, action = "Index" });
endpoints.MapControllerRoute(
name: "cms-entry-by-culture",
pattern: "{"+ CultureRouteSegmentConstraint.RouteSegmentName + ":"+ CultureRouteSegmentConstraint.RouteConstraintName + "}/{*url}",
name: RouteConsts.EntryWithCultureRouteName,
pattern: "{"+ CultureRouteSegmentConstraint.RouteSegmentName + ":"+ CultureRouteSegmentConstraint.RouteConstraintName + "}/{*path}",
defaults: new { controller = CmsController.ControllerName, action = "EntryByCulture" });
endpoints.MapControllerRoute(
name: "cms-entry",
pattern: "{*url:regex(^(?!swagger/).*)}", //TODO: Use an options to configure the regular expression for the url
name: RouteConsts.EntryRouteName,
pattern: "{*path:regex(^(?!swagger/).*)}", //TODO: Use an options to configure the regular expression for the path
defaults: new { controller = CmsController.ControllerName, action = "Entry" });
});

Expand Down
Loading

0 comments on commit 3d68bf5

Please sign in to comment.