b3612f5bec
- Strip /api prefix from all endpoint routes - Make Show.CityId nullable (no longer required FK) - Drop CityId FK constraint and alter column to NULL at startup via raw SQL - Add migration MakeCityIdNullable for schema consistency - Update Show DTOs to reflect nullable CityId Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using FastEndpoints;
|
|
using PyroFetes.DTO.Sound.Request;
|
|
using PyroFetes.DTO.Sound.Response;
|
|
|
|
namespace PyroFetes.Endpoints.Sound;
|
|
|
|
public class CreateSoundEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateSoundDto, ReadSoundDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/sounds");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateSoundDto req, CancellationToken ct)
|
|
{
|
|
var sound = new PyroFetes.Models.Sound
|
|
{
|
|
Name = req.Name ?? string.Empty,
|
|
Type = req.Type,
|
|
Artist = req.Artist,
|
|
Duration = int.TryParse(req.Duration, out var duration) ? duration : null,
|
|
Kind = req.Kind,
|
|
Format = req.Format,
|
|
CreationDate = req.CreationDate,
|
|
SoundCategoryId = int.TryParse(req.SoundCategoryId, out var categoryId) ? categoryId : 0
|
|
};
|
|
|
|
pyroFetesDbContext.Sounds.Add(sound);
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
var result = new ReadSoundDto
|
|
{
|
|
Id = sound.Id,
|
|
Name = sound.Name,
|
|
Type = sound.Type,
|
|
Artist = sound.Artist,
|
|
Duration = sound.Duration?.ToString(),
|
|
Kind = sound.Kind,
|
|
Format = sound.Format,
|
|
CreationDate = sound.CreationDate,
|
|
SoundCategoryId = sound.SoundCategoryId.ToString()
|
|
};
|
|
|
|
await Send.OkAsync(result, ct);
|
|
}
|
|
}
|