Add Intermediate AutoGetterDeleteCotnroller

This commit is contained in:
honzapatCZ 2026-10-27 15:50:31 +01:00
parent ebd8f5be92
commit 386ef6fa54

View File

@ -33,7 +33,7 @@ namespace NejCommon.Controllers
/// <typeparam name="TRequest">The request type</typeparam> /// <typeparam name="TRequest">The request type</typeparam>
/// <typeparam name="TResponse">The response type</typeparam> /// <typeparam name="TResponse">The response type</typeparam>
[ApiController] [ApiController]
public abstract partial class AutoController<TOwner, TType, TGetAllResponse, TCreateRequest, TCreateResponse, TGetResponse, TUpdateRequest, TUpdateResponse> : AutoGetterController<TOwner, TType, TGetAllResponse, TGetResponse> public abstract partial class AutoController<TOwner, TType, TGetAllResponse, TCreateRequest, TCreateResponse, TGetResponse, TUpdateRequest, TUpdateResponse> : AutoGetterDeleteController<TOwner, TType, TGetAllResponse, TGetResponse>
where TType : class where TType : class
where TGetAllResponse : class, IAutomappedAttribute<TType, TGetAllResponse>, new() where TGetAllResponse : class, IAutomappedAttribute<TType, TGetAllResponse>, new()
where TCreateRequest : class, IAutomappedAttribute<TType, TCreateRequest>, new() where TCreateRequest : class, IAutomappedAttribute<TType, TCreateRequest>, new()
@ -87,21 +87,6 @@ namespace NejCommon.Controllers
return await db.ApiSaveChangesAsyncCreate<TType, TCreateResponse>(providers, entity, true, (TCreateResponse)GetResponseType(RequestedResponseType.Create, entity)); return await db.ApiSaveChangesAsyncCreate<TType, TCreateResponse>(providers, entity, true, (TCreateResponse)GetResponseType(RequestedResponseType.Create, entity));
} }
/// <summary>
/// Delete company.
/// </summary>
/// <param name="entity"></param>
/// <response code="200">Success</response>
/// <response code="0">There was an error</response>
[HttpDelete]
[Route("{id}/")]
public virtual async Task<Results<BadRequest<Error>, Ok>> Delete([FromServices][ModelBinder(Name = "id")] TType entity)
{
db.Remove(entity!);
return await db.ApiSaveChangesAsync(TypedResults.Ok());
}
/// <summary> /// <summary>
/// Update company. /// Update company.
/// </summary> /// </summary>
@ -125,6 +110,33 @@ namespace NejCommon.Controllers
} }
} }
[ApiController] [ApiController]
public abstract class AutoGetterDeleteController<TOwner, TType, TGetAllResponse, TGetResponse> : AutoGetterController<TOwner, TType, TGetAllResponse, TGetResponse>
where TType : class
where TGetAllResponse : IAutomappedAttribute<TType, TGetAllResponse>, new()
where TGetResponse : IAutomappedAttribute<TType, TGetResponse>, new()
{
public AutoGetterDeleteController(CommonDbContext appDb, IServiceProvider providers) : base(appDb, providers)
{
}
/// <summary>
/// Delete company.
/// </summary>
/// <param name="entity"></param>
/// <response code="200">Success</response>
/// <response code="0">There was an error</response>
[HttpDelete]
[Route("{id}/")]
public virtual async Task<Results<BadRequest<Error>, Ok>> Delete([FromServices][ModelBinder(Name = "id")] TType entity)
{
db.Remove(entity!);
return await db.ApiSaveChangesAsync(TypedResults.Ok());
}
}
[ApiController]
public abstract class AutoGetterController<TOwner, TType, TGetAllResponse, TGetResponse> : ControllerBase public abstract class AutoGetterController<TOwner, TType, TGetAllResponse, TGetResponse> : ControllerBase
where TType : class where TType : class
where TGetAllResponse : IAutomappedAttribute<TType, TGetAllResponse>, new() where TGetAllResponse : IAutomappedAttribute<TType, TGetAllResponse>, new()