Skip to content

Commit

Permalink
Merge pull request #9514 from abpframework/auto-merge/rel-4-4/469
Browse files Browse the repository at this point in the history
  • Loading branch information
maliming committed Jul 6, 2021
2 parents b5d3f8d + 18257de commit ba4e558
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,9 @@ public class DocumentDto : EntityDto<Guid>
public virtual string LanguageCode { get; set; }

public virtual string FileName { get; set; }

public virtual string Content { get; set; }


public virtual string Format { get; set; }

public virtual string EditLink { get; set; }

public virtual string RootUrl { get; set; }

public virtual string RawRootUrl { get; set; }

public virtual string LocalDirectory { get; set; }


public virtual DateTime CreationTime { get; set; }

public virtual DateTime LastUpdatedTime { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Volo.Abp.Application.Dtos;

namespace Volo.Docs.Admin.Documents
{
public class DocumentWithoutDetailsDto : EntityDto<Guid>
{
public virtual string Version { get; set; }

public virtual string LanguageCode { get; set; }

public virtual string Format { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public DocsAdminApplicationAutoMapperProfile()
{
CreateMap<Project, ProjectDto>();
CreateMap<Document, DocumentDto>();
CreateMap<DocumentWithoutContent, DocumentDto>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task<PagedResultDto<DocumentDto>> GetAllAsync(GetAllInput input)
return new PagedResultDto<DocumentDto>
{
TotalCount = totalCount,
Items = ObjectMapper.Map<List<Document>, List<DocumentDto>>(docs)
Items = ObjectMapper.Map<List<DocumentWithoutContent>, List<DocumentDto>>(docs)
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ public async Task<List<string>> GetUrlsAsync(string prefix)

foreach (var project in projects)
{
var documents = await _documentRepository.GetListByProjectId(project.Id);
var documentWithoutDetailsList = await _documentRepository.GetListWithoutDetailsByProjectId(project.Id);

foreach (var document in documents)
foreach (var document in documentWithoutDetailsList)
{
try
{
Expand All @@ -223,7 +223,7 @@ public async Task<List<string>> GetUrlsAsync(string prefix)
return documentUrls;
}

private async Task AddDocumentToUrls(string prefix, Project project, Document document,
private async Task AddDocumentToUrls(string prefix, Project project, DocumentWithoutDetails document,
List<string> documentUrls)
{
var navigationNodes = await GetNavigationNodesAsync(prefix, project, document);
Expand All @@ -234,7 +234,7 @@ public async Task<List<string>> GetUrlsAsync(string prefix)
List<NavigationNode> navigationNodes,
List<string> documentUrls,
Project project,
Document document)
DocumentWithoutDetails document)
{
navigationNodes?.ForEach(node =>
{
Expand All @@ -245,7 +245,7 @@ public async Task<List<string>> GetUrlsAsync(string prefix)
}

private async Task<List<NavigationNode>> GetNavigationNodesAsync(string prefix, Project project,
Document document)
DocumentWithoutDetails document)
{
var version = GetProjectVersionPrefixIfExist(project) + document.Version;
var navigationDocument = await GetDocumentWithDetailsDtoAsync(
Expand All @@ -266,7 +266,7 @@ public async Task<List<string>> GetUrlsAsync(string prefix)
}

private List<string> GetDocumentLinks(NavigationNode node, List<string> documentUrls, string prefix,
string shortName, Document document)
string shortName, DocumentWithoutDetails document)
{
if (!IsExternalLink(node.Path))
{
Expand All @@ -283,7 +283,7 @@ public async Task<List<string>> GetUrlsAsync(string prefix)
return documentUrls;
}

private string NormalizePath(string prefix, string path, string shortName, Document document)
private string NormalizePath(string prefix, string path, string shortName, DocumentWithoutDetails document)
{
var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, document.Format);
var normalizedPath = prefix + document.LanguageCode + "/" + shortName + "/" + document.Version + "/" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Volo.Docs.Documents
{
public class DocumentWithoutContent
{
public Guid Id { get; set; }

public virtual Guid ProjectId { get; set; }

public virtual string Name { get; set; }

public virtual string Version { get; set; }

public virtual string LanguageCode { get; set; }

public virtual string FileName { get; set; }

public virtual string Format { get; set; }

public virtual DateTime CreationTime { get; set; }

public virtual DateTime LastUpdatedTime { get; set; }

public virtual DateTime? LastSignificantUpdateTime { get; set; }

public virtual DateTime LastCachedTime { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Volo.Docs.Documents
{
public class DocumentWithoutDetails
{
public Guid Id { get; set; }

public virtual string Version { get; set; }

public virtual string LanguageCode { get; set; }

public virtual string Format { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Volo.Docs.Documents
{
public interface IDocumentRepository : IBasicRepository<Document>
{
Task<List<DocumentWithoutDetails>> GetListWithoutDetailsByProjectId(Guid projectId, CancellationToken cancellationToken = default);

Task<List<Document>> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default);

Task<Document> FindAsync(Guid projectId,
Expand All @@ -23,7 +25,7 @@ public interface IDocumentRepository : IBasicRepository<Document>
string version,
CancellationToken cancellationToken = default);

Task<List<Document>> GetAllAsync(
Task<List<DocumentWithoutContent>> GetAllAsync(
Guid? projectId,
string name,
string version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,27 @@ public EFCoreDocumentRepository(IDbContextProvider<IDocsDbContext> dbContextProv
{
}

public async Task<List<DocumentWithoutDetails>> GetListWithoutDetailsByProjectId(Guid projectId, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(d => d.ProjectId == projectId)
.Select(x => new DocumentWithoutDetails
{
Id = x.Id,
Version = x.Version,
LanguageCode = x.LanguageCode,
Format = x.Format,
})
.ToListAsync(cancellationToken: cancellationToken);
}

public async Task<List<Document>> GetListByProjectId(Guid projectId,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken: cancellationToken);
}

public async Task<List<Document>> GetAllAsync(
public async Task<List<DocumentWithoutContent>> GetAllAsync(
Guid? projectId,
string name,
string version,
Expand Down Expand Up @@ -130,7 +144,7 @@ public async Task<Document> GetAsync(Guid id, CancellationToken cancellationToke
return await (await GetDbSetAsync()).Where(x => x.Id == id).SingleAsync(cancellationToken: cancellationToken);
}

protected virtual IQueryable<Document> ApplyFilterForGetAll(
protected virtual IQueryable<DocumentWithoutContent> ApplyFilterForGetAll(
IQueryable<Document> query,
Guid? projectId,
string name,
Expand Down Expand Up @@ -176,7 +190,21 @@ public async Task<Document> GetAsync(Guid id, CancellationToken cancellationToke
.WhereIf(lastCachedTimeMin.HasValue,
d => d.LastCachedTime.Date >= lastCachedTimeMin.Value.Date)
.WhereIf(lastCachedTimeMax.HasValue,
d => d.LastCachedTime.Date <= lastCachedTimeMax.Value.Date);
d => d.LastCachedTime.Date <= lastCachedTimeMax.Value.Date)
.Select(x => new DocumentWithoutContent
{
Id = x.Id,
ProjectId = x.ProjectId,
Name = x.Name,
Version = x.Version,
LanguageCode = x.LanguageCode,
FileName = x.FileName,
Format = x.Format,
CreationTime = x.CreationTime,
LastUpdatedTime = x.LastUpdatedTime,
LastSignificantUpdateTime = x.LastSignificantUpdateTime,
LastCachedTime = x.LastCachedTime
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ public MongoDocumentRepository(IMongoDbContextProvider<IDocsMongoDbContext> dbCo
{
}

public async Task<List<DocumentWithoutDetails>> GetListWithoutDetailsByProjectId(Guid projectId, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(d => d.ProjectId == projectId)
.Select(x => new DocumentWithoutDetails
{
Id = x.Id,
Version = x.Version,
LanguageCode = x.LanguageCode,
Format = x.Format
})
.ToListAsync(cancellationToken);
}

public async Task<List<Document>> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken);
Expand All @@ -43,7 +57,7 @@ public async Task<List<Document>> GetListByProjectId(Guid projectId, Cancellatio
x.Version == version, cancellationToken: cancellationToken);
}

public async Task<List<Document>> GetAllAsync(
public async Task<List<DocumentWithoutContent>> GetAllAsync(
Guid? projectId,
string name,
string version,
Expand Down Expand Up @@ -81,8 +95,8 @@ public async Task<List<Document>> GetListByProjectId(Guid projectId, Cancellatio
lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax,
lastCachedTimeMin: lastCachedTimeMin,
lastCachedTimeMax: lastCachedTimeMax)
.OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting).As<IMongoQueryable<Document>>()
.PageBy<Document, IMongoQueryable<Document>>(skipCount, maxResultCount)
.OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting).As<IMongoQueryable<DocumentWithoutContent>>()
.PageBy<DocumentWithoutContent, IMongoQueryable<DocumentWithoutContent>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}

Expand Down Expand Up @@ -135,7 +149,7 @@ public async Task<Document> GetAsync(Guid id, CancellationToken cancellationToke
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Id == id).SingleAsync(cancellationToken);
}

protected virtual IMongoQueryable<Document> ApplyFilterForGetAll(
protected virtual IMongoQueryable<DocumentWithoutContent> ApplyFilterForGetAll(
IMongoQueryable<Document> query,
Guid? projectId,
string name,
Expand Down Expand Up @@ -218,7 +232,20 @@ public async Task<Document> GetAsync(Guid id, CancellationToken cancellationToke
query = query.Where(d => d.LastCachedTime.Date <= lastCachedTimeMax.Value.Date);
}

return query;
return query.Select(x => new DocumentWithoutContent
{
Id = x.Id,
ProjectId = x.ProjectId,
Name = x.Name,
Version = x.Version,
LanguageCode = x.LanguageCode,
FileName = x.FileName,
Format = x.Format,
CreationTime = x.CreationTime,
LastUpdatedTime = x.LastUpdatedTime,
LastSignificantUpdateTime = x.LastSignificantUpdateTime,
LastCachedTime = x.LastCachedTime
});
}
}
}

0 comments on commit ba4e558

Please sign in to comment.