diff --git a/.gitignore b/.gitignore index a53bdc8..635d286 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.db +back/data/ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## diff --git a/back/.config/dotnet-tools.json b/back/.config/dotnet-tools.json new file mode 100644 index 0000000..837b189 --- /dev/null +++ b/back/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "9.0.8", + "commands": [ + "dotnet-ef" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/back/Constants.cs b/back/Constants.cs new file mode 100644 index 0000000..f6d845e --- /dev/null +++ b/back/Constants.cs @@ -0,0 +1,4 @@ +public static class Constants +{ + public const string Data = "data"; +} diff --git a/back/DTO/PhotoFormModel.cs b/back/DTO/PhotoFormModel.cs new file mode 100644 index 0000000..7562d2f --- /dev/null +++ b/back/DTO/PhotoFormModel.cs @@ -0,0 +1,12 @@ +namespace back.DTO; + +public class PhotoFormModel +{ + public required string Title { get; set; } + public string? Description { get; set; } + public string? Tags { get; set; } + public string? People { get; set; } + public IFormFile? Image { get; set; } + public string? Ubicacion { get; set; } + public string? Evento { get; set; } +} diff --git a/back/Program.cs b/back/Program.cs index f5d2168..2cf0cf5 100644 --- a/back/Program.cs +++ b/back/Program.cs @@ -9,13 +9,22 @@ public class Program { var builder = WebApplication.CreateBuilder(args); + Directory.CreateDirectory(Constants.Data); // Add services to the container. - builder.Services.AddDbContext(options =>options.UseSqlite("Data Source=photos.db")); + builder.Services.AddDbContext(options => options.UseSqlite($"Data Source={Constants.Data}/photos.db")); builder.Services.AddControllers(); // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddSwaggerGen(); + builder.Services.AddCors(options => + { + options.AddPolicy("AllowAll", + builder => builder.AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader()); + }); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -29,6 +38,7 @@ public class Program app.UseAuthorization(); + app.UseCors("AllowAll"); app.MapControllers(); diff --git a/back/controllers/PhotoController.cs b/back/controllers/PhotosController.cs similarity index 77% rename from back/controllers/PhotoController.cs rename to back/controllers/PhotosController.cs index 8d108df..373caee 100644 --- a/back/controllers/PhotoController.cs +++ b/back/controllers/PhotosController.cs @@ -1,24 +1,14 @@ using back.ApiService.context; using back.ApiService.models; +using back.DTO; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; namespace back.controllers; -public class PhotoFormModel -{ - public required string Title { get; set; } - public string? Description { get; set; } - public string? Tags { get; set; } - public string? People { get; set; } - public IFormFile? Image { get; set; } - public string? Ubicacion { get; set; } - public string? Evento { get; set; } -} - [Route("api/[controller]")] [ApiController] -public class PhotoController(PhotoContext photoContext) : ControllerBase +public class PhotosController(PhotoContext photoContext) : ControllerBase { private readonly PhotoContext _photoContext = photoContext; @@ -37,18 +27,33 @@ public class PhotoController(PhotoContext photoContext) : ControllerBase .ToListAsync(); Response.Headers.Append("X-Total-Count", totalItems.ToString()); - + return Ok(photos); } // GET api//5 - [HttpGet("{id}")] - public async Task> Get(Guid id) + [HttpGet("{id}/{res}")] + public async Task Get(Guid id, string res = "low") { var photo = await _photoContext.Photos.FindAsync(id); if (photo == null) return NotFound(); - return photo; + + string? filePath = res.ToLower() switch + { + "low" => photo.LowResUrl, + "mid" => photo.MidResUrl, + "high" => photo.HighResUrl, + _ => null + }; + + if (filePath == null || !System.IO.File.Exists(Path.Combine(Constants.Data, filePath))) + return NotFound(); + + var fileBytes = await System.IO.File.ReadAllBytesAsync(Path.Combine(Constants.Data, filePath)); + var contentType = "image/jpeg"; // Cambia si usas otro formato + + return File(fileBytes, contentType); } // POST api/ diff --git a/back/models/Photo.cs b/back/models/Photo.cs index a5e5098..c8e37d5 100644 --- a/back/models/Photo.cs +++ b/back/models/Photo.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.AspNetCore.Identity; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; @@ -10,29 +11,33 @@ public class PhotoBuilder public static Photo Build(string? title, string? description, List? tags, List? personsIn, IFormFile image) { // Genera un nombre de archivo único - var fileName = $"{Guid.NewGuid()}{Path.GetExtension(image.FileName)}"; - var photo = new Photo(title, description, tags, personsIn, fileName); + var id = Guid.NewGuid(); + var fileName = $"{id}{Path.GetExtension(image.FileName)}"; + var photo = new Photo(title, description, tags, personsIn, fileName) + { + Id = id + }; // Asegura que los directorios existen - Directory.CreateDirectory(Photo.LowResFolder); - Directory.CreateDirectory(Photo.MidResFolder); - Directory.CreateDirectory(Photo.HighResFolder); + Directory.CreateDirectory(Path.Join(Constants.Data, Photo.LowResFolder)); + Directory.CreateDirectory(Path.Join(Constants.Data, Photo.MidResFolder)); + Directory.CreateDirectory(Path.Join(Constants.Data, Photo.HighResFolder)); // Procesa y guarda las imágenes using var stream = image.OpenReadStream(); using var img = Image.Load(stream); // Baja resolución (480px) img.Mutate(x => x.Resize(new ResizeOptions { Size = new Size(480, 0), Mode = ResizeMode.Max })); - img.Save(photo.LowResUrl); + img.Save(Path.Join(Constants.Data, photo.LowResUrl)); // Media resolución (720px) img.Mutate(x => x.Resize(new ResizeOptions { Size = new Size(720, 0), Mode = ResizeMode.Max })); - img.Save(photo.MidResUrl); + img.Save(Path.Join(Constants.Data, photo.MidResUrl)); // Original stream.Position = 0; using var original = Image.Load(stream); - original.Save(photo.HighResUrl); + original.Save(Path.Join(Constants.Data, photo.HighResUrl)); return photo; } @@ -45,7 +50,7 @@ public class Photo public const string MidResFolder = "imgs/mid"; public const string HighResFolder = "imgs/high"; - [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key] public Guid Id { get; set; } public string? Title { get; set; } public string? Description { get; set; } diff --git a/back/photos.db-shm b/back/photos.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/back/photos.db-shm differ diff --git a/back/photos.db-wal b/back/photos.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/front/public/assets/config.json b/front/public/assets/config.json new file mode 100644 index 0000000..757918f --- /dev/null +++ b/front/public/assets/config.json @@ -0,0 +1,3 @@ +{ + "bff": "https://localhost:7273" +} \ No newline at end of file diff --git a/front/public/assets/fotosPrueba/1.jpg b/front/public/assets/fotosPrueba/1.jpg deleted file mode 100644 index 33f9dd3..0000000 Binary files a/front/public/assets/fotosPrueba/1.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/10.jpg b/front/public/assets/fotosPrueba/10.jpg deleted file mode 100644 index f734031..0000000 Binary files a/front/public/assets/fotosPrueba/10.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/11.jpg b/front/public/assets/fotosPrueba/11.jpg deleted file mode 100644 index e248cab..0000000 Binary files a/front/public/assets/fotosPrueba/11.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/12.jpg b/front/public/assets/fotosPrueba/12.jpg deleted file mode 100644 index 552bd45..0000000 Binary files a/front/public/assets/fotosPrueba/12.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/13.jpg b/front/public/assets/fotosPrueba/13.jpg deleted file mode 100644 index 5351963..0000000 Binary files a/front/public/assets/fotosPrueba/13.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/14.jpg b/front/public/assets/fotosPrueba/14.jpg deleted file mode 100644 index fb1f157..0000000 Binary files a/front/public/assets/fotosPrueba/14.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/15.jpg b/front/public/assets/fotosPrueba/15.jpg deleted file mode 100644 index 6e8da57..0000000 Binary files a/front/public/assets/fotosPrueba/15.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/16.jpg b/front/public/assets/fotosPrueba/16.jpg deleted file mode 100644 index 12b916f..0000000 Binary files a/front/public/assets/fotosPrueba/16.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/17.jpg b/front/public/assets/fotosPrueba/17.jpg deleted file mode 100644 index 7504e85..0000000 Binary files a/front/public/assets/fotosPrueba/17.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/18.jpg b/front/public/assets/fotosPrueba/18.jpg deleted file mode 100644 index 56f9aa0..0000000 Binary files a/front/public/assets/fotosPrueba/18.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/19.jpg b/front/public/assets/fotosPrueba/19.jpg deleted file mode 100644 index e14cbbb..0000000 Binary files a/front/public/assets/fotosPrueba/19.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/2.jpg b/front/public/assets/fotosPrueba/2.jpg deleted file mode 100644 index 37534e0..0000000 Binary files a/front/public/assets/fotosPrueba/2.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/20.jpg b/front/public/assets/fotosPrueba/20.jpg deleted file mode 100644 index 22e7c15..0000000 Binary files a/front/public/assets/fotosPrueba/20.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/21.jpg b/front/public/assets/fotosPrueba/21.jpg deleted file mode 100644 index fd38e0c..0000000 Binary files a/front/public/assets/fotosPrueba/21.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/22.jpg b/front/public/assets/fotosPrueba/22.jpg deleted file mode 100644 index 3d8686e..0000000 Binary files a/front/public/assets/fotosPrueba/22.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/23.jpg b/front/public/assets/fotosPrueba/23.jpg deleted file mode 100644 index 495b6a9..0000000 Binary files a/front/public/assets/fotosPrueba/23.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/24.jpg b/front/public/assets/fotosPrueba/24.jpg deleted file mode 100644 index be83906..0000000 Binary files a/front/public/assets/fotosPrueba/24.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/25.jpg b/front/public/assets/fotosPrueba/25.jpg deleted file mode 100644 index 4e975a2..0000000 Binary files a/front/public/assets/fotosPrueba/25.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/26.jpg b/front/public/assets/fotosPrueba/26.jpg deleted file mode 100644 index 8e3e421..0000000 Binary files a/front/public/assets/fotosPrueba/26.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/27.jpg b/front/public/assets/fotosPrueba/27.jpg deleted file mode 100644 index 607c33c..0000000 Binary files a/front/public/assets/fotosPrueba/27.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/28.jpg b/front/public/assets/fotosPrueba/28.jpg deleted file mode 100644 index 99b2247..0000000 Binary files a/front/public/assets/fotosPrueba/28.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/29.jpg b/front/public/assets/fotosPrueba/29.jpg deleted file mode 100644 index ff62356..0000000 Binary files a/front/public/assets/fotosPrueba/29.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/3.jpg b/front/public/assets/fotosPrueba/3.jpg deleted file mode 100644 index 0278945..0000000 Binary files a/front/public/assets/fotosPrueba/3.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/30.jpg b/front/public/assets/fotosPrueba/30.jpg deleted file mode 100644 index c4a2bbe..0000000 Binary files a/front/public/assets/fotosPrueba/30.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/31.jpg b/front/public/assets/fotosPrueba/31.jpg deleted file mode 100644 index faf129e..0000000 Binary files a/front/public/assets/fotosPrueba/31.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/32.jpg b/front/public/assets/fotosPrueba/32.jpg deleted file mode 100644 index 833121c..0000000 Binary files a/front/public/assets/fotosPrueba/32.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/33.jpg b/front/public/assets/fotosPrueba/33.jpg deleted file mode 100644 index f9e03c4..0000000 Binary files a/front/public/assets/fotosPrueba/33.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/4.jpg b/front/public/assets/fotosPrueba/4.jpg deleted file mode 100644 index 002d9d3..0000000 Binary files a/front/public/assets/fotosPrueba/4.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/5.jpg b/front/public/assets/fotosPrueba/5.jpg deleted file mode 100644 index 1e78ffb..0000000 Binary files a/front/public/assets/fotosPrueba/5.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/6.jpg b/front/public/assets/fotosPrueba/6.jpg deleted file mode 100644 index 5216342..0000000 Binary files a/front/public/assets/fotosPrueba/6.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/7.jpg b/front/public/assets/fotosPrueba/7.jpg deleted file mode 100644 index df333b7..0000000 Binary files a/front/public/assets/fotosPrueba/7.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/8.jpg b/front/public/assets/fotosPrueba/8.jpg deleted file mode 100644 index d90c75d..0000000 Binary files a/front/public/assets/fotosPrueba/8.jpg and /dev/null differ diff --git a/front/public/assets/fotosPrueba/9.jpg b/front/public/assets/fotosPrueba/9.jpg deleted file mode 100644 index 8ad3851..0000000 Binary files a/front/public/assets/fotosPrueba/9.jpg and /dev/null differ diff --git a/front/src/app/app.html b/front/src/app/app.html index b104211..54911af 100644 --- a/front/src/app/app.html +++ b/front/src/app/app.html @@ -1,7 +1,7 @@
-