mirror of
https://github.com/XFox111/MuiCharts.git
synced 2026-04-22 06:51:05 +03:00
- Added /Import endpoints
- Minor refactoring and improved validation
This commit is contained in:
@@ -61,6 +61,12 @@ public class PointsController(
|
||||
{
|
||||
Logger.LogInformation("Getting points with ids {Ids}", ids);
|
||||
|
||||
if (ids.Length < 1)
|
||||
{
|
||||
Logger.LogInformation("No point IDs provided");
|
||||
return Problem([Error.Validation()]);
|
||||
}
|
||||
|
||||
IQueryable<Point> query = await _repository.GetPointsRangeAsync();
|
||||
|
||||
PointResponse[] points = [
|
||||
@@ -181,6 +187,29 @@ public class PointsController(
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imports an array of points.
|
||||
/// </summary>
|
||||
/// <param name="points">The array of points to import.</param>
|
||||
/// <returns>An <see cref="IActionResult"/> representing the asynchronous operation result.</returns>
|
||||
[HttpPost("Import")]
|
||||
[ProducesResponseType<Point[]>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesDefaultResponseType(typeof(ProblemDetails))]
|
||||
public async Task<IActionResult> ImportPointsAsync(Point[] points)
|
||||
{
|
||||
Logger.LogInformation("Importing points");
|
||||
|
||||
ErrorOr<IEnumerable<Point>> importResult = await _repository.AddPointsRangeAsync(points);
|
||||
|
||||
if (importResult.IsError)
|
||||
return Problem(importResult.Errors);
|
||||
|
||||
Logger.LogInformation("Imported {Count} points", importResult.Value.Count());
|
||||
|
||||
return Ok(importResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a point with the specified ID.
|
||||
/// </summary>
|
||||
@@ -189,6 +218,7 @@ public class PointsController(
|
||||
[HttpDelete("{id:int}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status409Conflict)]
|
||||
[ProducesDefaultResponseType(typeof(ProblemDetails))]
|
||||
public async Task<IActionResult> DeletePointAsync(int id)
|
||||
{
|
||||
|
||||
@@ -138,6 +138,29 @@ public class TracksController(
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imports tracks.
|
||||
/// </summary>
|
||||
/// <param name="requests">The requests containing the track details.</param>
|
||||
/// <returns>An <see cref="IActionResult"/> representing the asynchronous operation result.</returns>
|
||||
[HttpPost("Import")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesDefaultResponseType(typeof(ProblemDetails))]
|
||||
public async Task<IActionResult> ImportTracksAsync(Track[] requests)
|
||||
{
|
||||
Logger.LogInformation("Importing tracks");
|
||||
|
||||
ErrorOr<IEnumerable<Track>> importResult = await _repository.AddTracksRangeAsync(requests);
|
||||
|
||||
if (importResult.IsError)
|
||||
return Problem(importResult.Errors);
|
||||
|
||||
Logger.LogInformation("Tracks imported");
|
||||
|
||||
return Ok(importResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a track with the specified first point ID and second point ID.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user