forked from itsecd/cloud-development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectController.cs
More file actions
33 lines (28 loc) · 1.26 KB
/
ProjectController.cs
File metadata and controls
33 lines (28 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using ProjectApp.Domain.Entities;
using Microsoft.AspNetCore.Mvc;
using ProjectApp.Api.Services;
namespace ProjectApp.Api.Controllers;
[Route("api/[controller]")]
[ApiController]
public class ProjectController(ProgramProjectGeneratorService generatorService, ILogger<ProjectController> logger) : ControllerBase
{
/// <summary>
/// Возвращает проект по идентификатору или генерирует новый, если он не найден в кэше
/// </summary>
/// <param name="id">Идентификатор проекта</param>
/// <param name="cancellationToken">Токен отмены</param>
/// <returns>Программный проект</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ProgramProject>> GetById([FromQuery] int id, CancellationToken cancellationToken)
{
if (id < 0)
{
return BadRequest("id must be a positive integer.");
}
logger.LogInformation("Received request to retrieve/generate project {Id}", id);
var project = await generatorService.GetByIdAsync(id, cancellationToken);
return Ok(project);
}
}