Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ca un utilizator ANABI vreau sa caut un bun (cautare avansata dupa decizie, dosar, inculpat) #142

Merged
merged 2 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Anabi/Features/Search/Models/SearchAssetCriteria.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Anabi.Features.Assets.Models;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Anabi.Features.Search.Models
{
public class SearchAssetCriteria : IRequest<List<SearchAssetResult>>
{
public string DecisionNumber { get; set; }
public string FileNumber { get; set; }
public string DefendantId { get; set; } //numeric personal code or fiscal unique registrain code
public string DefendantName { get; set; }

}
}
18 changes: 18 additions & 0 deletions Anabi/Features/Search/Models/SearchAssetResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Anabi.Features.Search.Models
{
public class SearchAssetResult
{
public int? Id { get; set; }
public string DefendantName { get; set; }
public string DecisionNumber { get; set; }
public string FileNumber { get; set; }
public string Stage { get; set; }
public int AssetId { get; set; }

}
}
47 changes: 47 additions & 0 deletions Anabi/Features/Search/SearchAssetHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Anabi.Domain;
using Anabi.Features.Assets.Models;
using MediatR;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using System.Threading;
using Anabi.Features.Search.Models;

namespace Anabi.Features.Search
{
public class SearchAssetHandler : BaseHandler, IRequestHandler<SearchAssetCriteria, List<SearchAssetResult>>
{
public SearchAssetHandler(BaseHandlerNeeds needs) : base(needs)
{
}

/**
* Method that returns a search result
* */
public async Task<List<SearchAssetResult>> Handle(SearchAssetCriteria message, CancellationToken cancellationToken)
{
var query = from historicalStages in context.HistoricalStages
join assets in context.Assets on historicalStages.AssetId equals assets.Id
join assetDefendant in context.AssetDefendants on assets.Id equals assetDefendant.AssetId
join person in context.Persons on assetDefendant.PersonId equals person.Id
join stages in context.Stages on historicalStages.StageId equals stages.Id

where historicalStages.DecisionNumber == message.DecisionNumber
where historicalStages.FileNumber == message.FileNumber
where historicalStages.Person.Identification == message.DefendantId //maybe should be changed
where historicalStages.Person.Name == message.DefendantName
select new SearchAssetResult
{
Id = historicalStages.DecizieId,
DefendantName = person.Name,
DecisionNumber = historicalStages.DecisionNumber,
FileNumber = historicalStages.FileNumber,
Stage = historicalStages.Stage.Name,
AssetId = assets.Id
};

return await query.ToListAsync(cancellationToken);
}
}
}
40 changes: 40 additions & 0 deletions Anabi/Features/Search/SearchController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Anabi.Features.Assets.Models;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Anabi.Controllers;
using Anabi.Domain.Asset.Commands;
using Anabi.Middleware;
using Anabi.Common.ViewModels;
using Anabi.Domain.Core.Asset.Commands;

using Anabi.Features.Search.Models;
namespace Anabi.Features.Search
{
[AllowAnonymous]
[Produces("application/json")]
[Route("api/search")]
public class SearchController : BaseController
{
private readonly IMediator mediator;

public SearchController(IMediator _mediator)
{
mediator = _mediator;
}

[HttpGet("asset")]
[ProducesResponseType(typeof(IEnumerable<SearchAssetResult>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> SearchAsset(SearchAssetCriteria assetCriteria)
{
var results = await mediator.Send(assetCriteria);

return Ok();

}
}
}