Add controllers for the Get method #9
@ -1,9 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Mirea.Api.Endpoint.Models;
|
using Mirea.Api.Dto.Responses;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Common.Extensions;
|
namespace Mirea.Api.Endpoint.Common.Attributes;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
|
||||||
public class BadRequestResponseAttribute() : ProducesResponseTypeAttribute(typeof(ErrorResponseVm), StatusCodes.Status400BadRequest);
|
public class BadRequestResponseAttribute() : ProducesResponseTypeAttribute(typeof(ErrorResponse), StatusCodes.Status400BadRequest);
|
@ -1,9 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Mirea.Api.Endpoint.Models;
|
using Mirea.Api.Dto.Responses;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Common.Extensions;
|
namespace Mirea.Api.Endpoint.Common.Attributes;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
|
||||||
public class NotFoundResponseAttribute() : ProducesResponseTypeAttribute(typeof(ErrorResponseVm), StatusCodes.Status404NotFound);
|
public class NotFoundResponseAttribute() : ProducesResponseTypeAttribute(typeof(ErrorResponse), StatusCodes.Status404NotFound);
|
@ -3,7 +3,10 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||||
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
||||||
using Mirea.Api.Endpoint.Common.Extensions;
|
using Mirea.Api.Dto.Responses;
|
||||||
|
using Mirea.Api.Endpoint.Common.Attributes;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Controllers.V1
|
namespace Mirea.Api.Endpoint.Controllers.V1
|
||||||
@ -16,11 +19,18 @@ namespace Mirea.Api.Endpoint.Controllers.V1
|
|||||||
/// <returns>Basic information about campuses.</returns>
|
/// <returns>Basic information about campuses.</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public async Task<ActionResult<CampusBasicInfoVm>> GetBasicInfo()
|
public async Task<ActionResult<List<CampusBasicInfoResponse>>> GetBasicInfo()
|
||||||
{
|
{
|
||||||
var result = await mediator.Send(new GetCampusBasicInfoListQuery());
|
var result = await mediator.Send(new GetCampusBasicInfoListQuery());
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result.Campuses
|
||||||
|
.Select(c => new CampusBasicInfoResponse()
|
||||||
|
{
|
||||||
|
Id = c.Id,
|
||||||
|
CodeName = c.CodeName,
|
||||||
|
FullName = c.FullName
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -32,14 +42,20 @@ namespace Mirea.Api.Endpoint.Controllers.V1
|
|||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[BadRequestResponse]
|
[BadRequestResponse]
|
||||||
[NotFoundResponse]
|
[NotFoundResponse]
|
||||||
public async Task<ActionResult<CampusDetailsVm>> GetDetails(int id)
|
public async Task<ActionResult<CampusDetailsResponse>> GetDetails(int id)
|
||||||
{
|
{
|
||||||
var result = await mediator.Send(new GetCampusDetailsQuery()
|
var result = await mediator.Send(new GetCampusDetailsQuery()
|
||||||
{
|
{
|
||||||
Id = id
|
Id = id
|
||||||
});
|
});
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(new CampusDetailsResponse()
|
||||||
|
{
|
||||||
|
Id = result.Id,
|
||||||
|
CodeName = result.CodeName,
|
||||||
|
FullName = result.FullName,
|
||||||
|
Address = result.Address
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
|
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
|
||||||
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
|
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
|
||||||
using Mirea.Api.Endpoint.Common.Extensions;
|
using Mirea.Api.Dto.Responses;
|
||||||
|
using Mirea.Api.Endpoint.Common.Attributes;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Controllers.V1
|
namespace Mirea.Api.Endpoint.Controllers.V1
|
||||||
@ -19,7 +22,7 @@ namespace Mirea.Api.Endpoint.Controllers.V1
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[BadRequestResponse]
|
[BadRequestResponse]
|
||||||
public async Task<ActionResult<DisciplineListVm>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
|
public async Task<ActionResult<List<DisciplineResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
|
||||||
{
|
{
|
||||||
var result = await mediator.Send(new GetDisciplineListQuery()
|
var result = await mediator.Send(new GetDisciplineListQuery()
|
||||||
{
|
{
|
||||||
@ -27,27 +30,36 @@ namespace Mirea.Api.Endpoint.Controllers.V1
|
|||||||
PageSize = pageSize
|
PageSize = pageSize
|
||||||
});
|
});
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result.Disciplines
|
||||||
|
.Select(d => new DisciplineResponse()
|
||||||
|
{
|
||||||
|
Id = d.Id,
|
||||||
|
Name = d.Name
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets details of a specific discipline by ID.
|
/// Gets details of a specific discipline by ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">Discipline ID.</param>
|
/// <param name="id">Discipline ID.</param>
|
||||||
/// <returns>Details of the specified discipline.
|
/// <returns>Details of the specified discipline.</returns>
|
||||||
/// </returns>
|
|
||||||
[HttpGet("{id:int}")]
|
[HttpGet("{id:int}")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[BadRequestResponse]
|
[BadRequestResponse]
|
||||||
[NotFoundResponse]
|
[NotFoundResponse]
|
||||||
public async Task<ActionResult<DisciplineInfoVm>> GetDetails(int id)
|
public async Task<ActionResult<DisciplineResponse>> GetDetails(int id)
|
||||||
{
|
{
|
||||||
var result = await mediator.Send(new GetDisciplineInfoQuery()
|
var result = await mediator.Send(new GetDisciplineInfoQuery()
|
||||||
{
|
{
|
||||||
Id = id
|
Id = id
|
||||||
});
|
});
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(new DisciplineResponse()
|
||||||
|
{
|
||||||
|
Id = result.Id,
|
||||||
|
Name = result.Name
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ApiDto\ApiDto.csproj" />
|
||||||
<ProjectReference Include="..\Domain\Domain.csproj" />
|
<ProjectReference Include="..\Domain\Domain.csproj" />
|
||||||
<ProjectReference Include="..\Persistence\Persistence.csproj" />
|
<ProjectReference Include="..\Persistence\Persistence.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
namespace Mirea.Api.Endpoint.Models;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A class for providing information about an error
|
|
||||||
/// </summary>
|
|
||||||
public class ErrorResponseVm
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The text or translation code of the error. This field may not contain information in specific scenarios.
|
|
||||||
/// For example, it might be empty for HTTP 204 responses where no content is returned or if the validation texts have not been configured.
|
|
||||||
/// </summary>
|
|
||||||
public required string Error { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// In addition to returning the response code in the header, it is also duplicated in this field.
|
|
||||||
/// Represents the HTTP response code.
|
|
||||||
/// </summary>
|
|
||||||
public required int Code { get; set; }
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user