feat(api): ApplicationTypeController, GetAll. Application GetAll исправлен фильтр по TypeId
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
@@ -23,17 +22,14 @@ namespace PARR.API.Controllers.V1
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class ApplicationController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<ApplicationController> logger;
|
||||
private readonly IMapper mapper;
|
||||
private readonly IApplicationService applicationService;
|
||||
|
||||
public ApplicationController(
|
||||
ILogger<ApplicationController> logger,
|
||||
IMapper mapper,
|
||||
IApplicationService applicationService
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.mapper = mapper;
|
||||
this.applicationService = applicationService;
|
||||
}
|
||||
@@ -56,8 +52,8 @@ namespace PARR.API.Controllers.V1
|
||||
if (!string.IsNullOrWhiteSpace(filter.Name))
|
||||
query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
|
||||
|
||||
if (filter.Type.HasValue)
|
||||
query = query.Where(t => t.ApplicationType!.Name == filter.Type.Value.ToString());
|
||||
if (filter.TypeId.HasValue)
|
||||
query = query.Where(t => t.ApplicationTypeId == filter.TypeId);
|
||||
|
||||
|
||||
var apps = await applicationService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
53
PARR.API/Controllers/V1/ApplicationTypeController.cs
Normal file
53
PARR.API/Controllers/V1/ApplicationTypeController.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Управление типами приложений
|
||||
/// </summary>
|
||||
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class ApplicationTypeController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IApplicationTypeService applicationTypeService;
|
||||
|
||||
public ApplicationTypeController(
|
||||
IMapper mapper,
|
||||
IApplicationTypeService applicationTypeService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.applicationTypeService = applicationTypeService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Список типов приложений
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.ApplicationType.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var appTypes = await applicationTypeService.Get().OrderBy(t => t.Name)
|
||||
.ToListAsync();
|
||||
|
||||
if (!appTypes.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<ApplicationTypeResponse>>(appTypes);
|
||||
|
||||
return Ok(new Response<List<ApplicationTypeResponse>>(response, true));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user