doculinks changes for grouping
This commit is contained in:
parent
c7a2dc5910
commit
71d4b524e7
@ -16,7 +16,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
{
|
||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
var mockResponse = await MockData.getNoContentResponse();
|
||||
var mockResponse = await MockData.getNoContentResponses();
|
||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en",null)).ReturnsAsync(mockResponse);
|
||||
|
||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||
@ -30,7 +30,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
{
|
||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
var mockResponse = await MockData.getNoContentResponse();
|
||||
var mockResponse = await MockData.getNoContentResponses();
|
||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
|
||||
|
||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||
@ -43,7 +43,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
{
|
||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
var mockResponse = await MockData.getOkResponse();
|
||||
var mockResponse = await MockData.getOkResponses();
|
||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en", null)).ReturnsAsync(mockResponse);
|
||||
|
||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||
@ -56,7 +56,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
{
|
||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
var mockResponse = await MockData.getOkResponse();
|
||||
var mockResponse = await MockData.getOkResponses();
|
||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
|
||||
|
||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||
@ -65,6 +65,32 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "Get active Documents by linktypeid - Ok case")]
|
||||
public async Task GetActiveDocumentsLinkTypeIdAsync_ShouldReturnStatusCode200()
|
||||
{
|
||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
var mockResponse = await MockData.getOkResponses();
|
||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
|
||||
|
||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||
var result = (OkObjectResult)await DocumentProvider.GetDocumentsByActiveLinkTypeIdAsync(null, "en");
|
||||
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
}
|
||||
[Fact(DisplayName = "Get active Documents by linktypeid - NoContent Case")]
|
||||
public async Task GetDocumentsLinkTypeIdAsync_ShouldReturnStatusCode204()
|
||||
{
|
||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
var mockResponse = await MockData.getNoContentResponses();
|
||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
|
||||
|
||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||
var result = (NoContentResult)await DocumentProvider.GetDocumentsByActiveLinkTypeIdAsync(null, "");
|
||||
|
||||
Assert.Equal(204, result.StatusCode);
|
||||
}
|
||||
[Fact(DisplayName = "Get Document by Id - Ok case")]
|
||||
public async Task GetDocumentAsync_ShouldReturnStatusCode200()
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
public class MockData
|
||||
{
|
||||
|
||||
public static async Task<(bool, List<DocuLinks.Models.ResDoculink>, string)> getOkResponse()
|
||||
public static async Task<(bool, List<DocuLinks.Models.ResDoculinks>, string)> getOkResponses()
|
||||
{
|
||||
List<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
||||
|
||||
@ -46,6 +46,48 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
doclinksAttachments= doclinksAttachments
|
||||
});
|
||||
}
|
||||
List<ResDoculinks> doculinks = list.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList();
|
||||
return (true, doculinks, null);
|
||||
}
|
||||
|
||||
|
||||
public static async Task<(bool, List<DocuLinks.Models.ResDoculink>, string)> getOkResponse()
|
||||
{
|
||||
List<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
||||
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
Dictionary<string, string> dicttitle = new Dictionary<string, string>();
|
||||
Dictionary<string, string> dictdesc = new Dictionary<string, string>();
|
||||
dicttitle.Add("en", "test"); dicttitle.Add("fr", "tester");
|
||||
dictdesc.Add("en", "test"); dictdesc.Add("fr", "tester");
|
||||
List<DoculinkTranslation> DocuLinksTranslations = new List<DoculinkTranslation>();
|
||||
DocuLinksTranslations.Add(new DoculinkTranslation()
|
||||
{
|
||||
Language = "en",
|
||||
title = "tel" + i,
|
||||
description = "Sample" + i
|
||||
});
|
||||
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
||||
doclinksAttachments.Add(new DoculinkAttachments()
|
||||
{
|
||||
docName = "",
|
||||
Path = "www.google.com",
|
||||
IsAttachments = false,
|
||||
CustomOrder = 1
|
||||
});
|
||||
list.Add(new DocuLinks.Models.ResDoculink()
|
||||
{
|
||||
|
||||
Id = i,
|
||||
linkTypeId = i,
|
||||
IsActive = true,
|
||||
titles = dicttitle,
|
||||
description = dictdesc,
|
||||
CustomOrder = i,
|
||||
doclinksAttachments = doclinksAttachments
|
||||
});
|
||||
}
|
||||
return (true, list, null);
|
||||
}
|
||||
public static async Task<(bool, DocuLinks.Models.ResDoculink, string)> getOkResponse(int Id)
|
||||
@ -64,6 +106,11 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
{
|
||||
return (false, null, "Not Found");
|
||||
}
|
||||
public static async Task<(bool, IEnumerable<DocuLinks.Models.ResDoculinks>, string)> getNoContentResponses()
|
||||
{
|
||||
IEnumerable<DocuLinks.Models.ResDoculinks> list = new List<DocuLinks.Models.ResDoculinks>();
|
||||
return (false, list, null);
|
||||
}
|
||||
public static async Task<(bool, IEnumerable<DocuLinks.Models.ResDoculink>, string)> getNoContentResponse()
|
||||
{
|
||||
IEnumerable<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
||||
|
@ -136,7 +136,21 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all active Doculink.
|
||||
/// </summary>
|
||||
[Route("doculinks/active/{linktypeid:int}")]
|
||||
[Route("doculinks/active/{linktypeid:int}/{language:alpha}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetDocumentsByActiveLinkTypeIdAsync(int? linktypeid, string? language)
|
||||
{
|
||||
var result = await this.documentsProvider.GetdocumentsByLinkTypeIdAsync(linktypeid, language, true);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.documents);
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Get a Doculink by id.
|
||||
/// </summary>
|
||||
|
@ -7,7 +7,8 @@ namespace DamageAssesment.Api.DocuLinks.Interfaces
|
||||
Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> GetDocumentAsync(int id, string? linktype, string? language);
|
||||
Task<(bool IsSuccess, Models.Doculink Document, string ErrorMessage)> GetDocumentByidAsync(int id);
|
||||
// Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetDocumnetsAsync(string? language);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.ResDoculinks> documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.ResDoculinks> documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive);
|
||||
Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> PostDocumentAsync(Models.Doculink Document);
|
||||
Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> UpdateDocumentAsync(int id,Models.Doculink Document);
|
||||
Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> DeleteDocumentAsync(int id);
|
||||
|
@ -7,6 +7,11 @@ namespace DamageAssesment.Api.DocuLinks.Models
|
||||
{
|
||||
public List<DoculinkTranslation> documentsTranslations { get; set; }
|
||||
}
|
||||
public class ResDoculinks
|
||||
{
|
||||
public int linkTypeId { get; set; }
|
||||
public List<ResDoculink> doculinks { get; set; }
|
||||
}
|
||||
public class ResDoculink:BaseDoculink
|
||||
{
|
||||
public object titles { get; set; }
|
||||
|
@ -6,8 +6,10 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace DamageAssesment.Api.DocuLinks.Providers
|
||||
@ -63,12 +65,17 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
||||
int counter = 0;
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
int linkTypeId = 2;
|
||||
FileModel fileModel = new FileModel();
|
||||
if (i<3)
|
||||
fileModel = new FileModel() { FileName="Sample"+i,FileExtension=".txt",FileContent= "c2FtcGxl", IsAttachments = true, CustomOrder = 1 };
|
||||
if (i < 3)
|
||||
{
|
||||
linkTypeId = 1;
|
||||
|
||||
fileModel = new FileModel() { FileName = "Sample" + i, FileExtension = ".txt", FileContent = "c2FtcGxl", IsAttachments = true, CustomOrder = 1 };
|
||||
}
|
||||
else
|
||||
fileModel = new FileModel() { url = "www.google" + i + ".com", IsAttachments = false, CustomOrder = 1 };
|
||||
ReqDoculink documentInfo = new ReqDoculink() { linkTypeId = i, CustomOrder = i, Files = new List<FileModel>() { fileModel } };
|
||||
ReqDoculink documentInfo = new ReqDoculink() { linkTypeId = linkTypeId, CustomOrder = i, Files = new List<FileModel>() { fileModel } };
|
||||
Models.Doculink document = uploadservice.UploadDocument(counter, documentInfo);
|
||||
DocumentDbContext.Documents.Add(mapper.Map<Models.Doculink, Db.Doculink>(document));
|
||||
DocumentDbContext.SaveChanges();
|
||||
@ -163,7 +170,44 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
||||
MultiLanguage = dicttitle;
|
||||
return MultiLanguage;
|
||||
}
|
||||
public async Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive)
|
||||
|
||||
public async Task<(bool IsSuccess, IEnumerable<Models.ResDoculinks> documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
logger?.LogInformation("Query Question");
|
||||
var documents = new List<Db.Doculink>();
|
||||
if (linkTypeId==null)
|
||||
documents = await DocumentDbContext.Documents.AsNoTracking().Where(q => (isactive == null || q.IsActive == isactive.Value)).ToListAsync();
|
||||
else
|
||||
documents = await DocumentDbContext.Documents.AsNoTracking().Where(q => (isactive == null || q.IsActive == isactive.Value) &&
|
||||
q.linkTypeId == linkTypeId.Value).ToListAsync();
|
||||
if (documents != null)
|
||||
{
|
||||
var result = mapper.Map<List<Db.Doculink>, List<Models.ResDoculink>>(documents);
|
||||
foreach (var item in result)
|
||||
{
|
||||
var multilan = CreateMultiLanguageObject(GetDocumentTranslations(item.Id, language));
|
||||
item.titles = multilan.titles;
|
||||
item.description = multilan.description;
|
||||
item.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(item.linkTypeId, language));
|
||||
item.doclinksAttachments = mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
||||
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == item.Id).ToList());
|
||||
}
|
||||
List<ResDoculinks> doculinks = result.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList();
|
||||
return (true, doculinks, null);
|
||||
}
|
||||
return (false, null, "Not found");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger?.LogError(ex.ToString());
|
||||
return (false, null, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<(bool IsSuccess, IEnumerable<Models.ResDoculinks> documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive)
|
||||
{
|
||||
|
||||
try
|
||||
@ -187,7 +231,8 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
||||
item.doclinksAttachments = mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
||||
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == item.Id).ToList());
|
||||
}
|
||||
return (true, result, null);
|
||||
List<ResDoculinks> doculinks = result.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList();
|
||||
return (true, doculinks, null);
|
||||
}
|
||||
return (false, null, "Not found");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user