Skip to content

Commit

Permalink
Make docs module shortName unique
Browse files Browse the repository at this point in the history
  • Loading branch information
realLiangshiwei committed Apr 11, 2020
1 parent 28cc892 commit a18c190
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public async Task<ProjectDto> GetAsync(Guid id)
[Authorize(DocsAdminPermissions.Projects.Create)]
public async Task<ProjectDto> CreateAsync(CreateProjectDto input)
{
if (await _projectRepository.ShortNameExistsAsync(input.ShortName))
{
throw new ProjectShortNameAlreadyExistsException(input.ShortName);
}

var project = new Project(_guidGenerator.Create(),
input.Name,
input.ShortName,
Expand All @@ -64,9 +69,9 @@ public async Task<ProjectDto> CreateAsync(CreateProjectDto input)

foreach (var extraProperty in input.ExtraProperties)
{
project.ExtraProperties.Add(extraProperty.Key,extraProperty.Value);
project.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
}

project = await _projectRepository.InsertAsync(project);

return ObjectMapper.Map<Project, ProjectDto>(project);
Expand Down Expand Up @@ -101,5 +106,6 @@ public async Task DeleteAsync(Guid id)
{
await _projectRepository.DeleteAsync(id);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Volo.Abp.Localization;
using Volo.Abp.Localization.ExceptionHandling;
using Volo.Abp.Modularity;
using Volo.Docs.Localization;

Expand All @@ -13,6 +14,11 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
options.Resources.Add<DocsResource>("en");
});

Configure<AbpExceptionLocalizationOptions>(options =>
{
options.MapCodeNamespace("Volo.Docs.Domain", typeof(DocsResource));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"New": "New",
"Upd": "Upd",
"NewExplanation": "Created in the last two weeks.",
"UpdatedExplanation": "Updated in the last two weeks."
"UpdatedExplanation": "Updated in the last two weeks.",
"Volo.Docs.Domain:010002": "ShortName {ShortName} already exists."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"New": "新文档",
"Upd": "更新",
"NewExplanation": "在最近两周内创建.",
"UpdatedExplanation": "在最近两周内更新."
"UpdatedExplanation": "在最近两周内更新.",
"Volo.Docs.Domain:010002": "简称 {ShortName} 已经存在."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
"DocumentNotFoundInSelectedLanguage": "本文件不適用於所選語系,將以預設語系顯示.",
"FilterTopics": "過濾主題",
"FullSearch": "搜索文件",
"Volo.Docs.Domain:010001": "Elastic search未啟用.",
"New": "新文檔",
"Upd": "更新",
"NewExplanation": "在最近兩周內創建.",
"UpdatedExplanation": "在最近兩周內更新."
"UpdatedExplanation": "在最近兩周內更新.",
"Volo.Docs.Domain:010002": "簡稱 {ShortName} 已經存在."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public interface IProjectRepository : IBasicRepository<Project, Guid>
Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount);

Task<Project> GetByShortNameAsync(string shortName);

Task<bool> ShortNameExistsAsync(string shortName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Volo.Abp;

namespace Volo.Docs.Projects
{
public class ProjectShortNameAlreadyExistsException : BusinessException
{
public ProjectShortNameAlreadyExistsException(string shortName)
: base("Volo.Docs.Domain:010002")
{
WithData("ShortName", shortName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ namespace Volo.Docs.Projects
{
public class EfCoreProjectRepository : EfCoreRepository<IDocsDbContext, Project, Guid>, IProjectRepository
{
public EfCoreProjectRepository(IDbContextProvider<IDocsDbContext> dbContextProvider)
public EfCoreProjectRepository(IDbContextProvider<IDocsDbContext> dbContextProvider)
: base(dbContextProvider)
{

}

public async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount)
Expand All @@ -39,5 +38,10 @@ public async Task<Project> GetByShortNameAsync(string shortName)

return project;
}

public async Task<bool> ShortNameExistsAsync(string shortName)
{
return await DbSet.AnyAsync(x => x.ShortName == shortName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace Volo.Docs.Projects
{
public class MongoProjectRepository : MongoDbRepository<IDocsMongoDbContext, Project, Guid>, IProjectRepository
{
public MongoProjectRepository(IMongoDbContextProvider<IDocsMongoDbContext> dbContextProvider) : base(dbContextProvider)
public MongoProjectRepository(IMongoDbContextProvider<IDocsMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{
}

Expand All @@ -38,5 +39,10 @@ public async Task<Project> GetByShortNameAsync(string shortName)

return project;
}

public async Task<bool> ShortNameExistsAsync(string shortName)
{
return await GetMongoQueryable().AnyAsync(x => x.ShortName == shortName);
}
}
}
}

0 comments on commit a18c190

Please sign in to comment.