using System.ComponentModel.DataAnnotations; using Luticate2.Utils.Dbo.Basic; using Luticate2.Utils.Dbo.FsFiles; using Luticate2.Utils.Dbo.PaginatedRequest; using Luticate2.Utils.Interfaces; using Luticate2.Utils.Utils; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; namespace Luticate2.Utils.Controllers { public class LuFsFilesCrudController : LuController where TBusiness : ILuCrudInterface { protected readonly TBusiness Business; public LuFsFilesCrudController(IOptions luUtilsOptionsDbo, TBusiness business) : base(luUtilsOptionsDbo) { Business = business; } [HttpGet] [Route("[controller]/{id}")] public virtual LuApiWrapperDbo GetSingleById([Required]string id) { return Handle(Business.GetSingleById(id)); } [HttpPost] [Route("[controller]")] public LuApiWrapperDbo AddDbo([Required]IFormFile file, string path) { return Handle(Business.AddDbo(new LuFsFilesAddDbo { File = file.OpenReadStream(), Path = string.IsNullOrEmpty(path) ? file.FileName : path })); } [HttpGet] [Route("[controller]")] public virtual LuApiWrapperDbo> GetMultiple([Required]LuPaginatedRequestDbo request) { return Handle(Business.GetMultiple(request)); } [HttpPost] [Route("[controller]/{id}")] public virtual LuApiWrapperDbo EditSingleByIdDbo([Required]string id, IFormFile file, string path) { return Handle(Business.EditSingleByIdDbo(id, new LuFsFilesAddDbo { File = file?.OpenReadStream(), Path = path })); } [HttpDelete] [Route("[controller]/{id}")] public virtual LuApiWrapperDbo Delete([Required]string id) { return Handle(Business.DeleteSingleByIdDbo(id)); } } }