Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30 from fornit1917/26-storing-images-from-foreign…
Browse files Browse the repository at this point in the history
…-services

#26 Prepare app for storing images from foreign services
  • Loading branch information
fornit1917 authored Dec 4, 2020
2 parents 2970683 + 295b89b commit 9bd1911
Show file tree
Hide file tree
Showing 15 changed files with 833 additions and 71 deletions.
229 changes: 170 additions & 59 deletions ImageBase.WebApp.UnitTests/CatalogServiceTests.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ImageBase.WebApp/Controllers/PrivateCatalogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public async Task<ActionResult<IEnumerable<CatalogDto>>> GetSubCatalogsAsync(int
}

[HttpGet("image/{id:int}")]
public async Task<ActionResult<IEnumerable<ImageDto>>> GetImagesByCatalog(int id, int offset = 0, int limit = 4)
public async Task<ActionResult<IEnumerable<ImagesListItemDto>>> GetImagesByCatalog(int id, int offset = 0, int limit = 4)
{
ServiceResponse<PaginationListDto<ImageDto>> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit, await CurrentUser());
ServiceResponse<PaginationListDto<ImagesListItemDto>> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit, await CurrentUser());
if (serviceGetImagesByCatalog.Success == false)
{
return Forbid(serviceGetImagesByCatalog.Message);
Expand Down
4 changes: 2 additions & 2 deletions ImageBase.WebApp/Controllers/PublicCatalogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public async Task<ActionResult<IEnumerable<CatalogDto>>> GetSubCatalogsAsync(int
}

[HttpGet("image/{id:int}")]
public async Task<ActionResult<IEnumerable<ImageDto>>> GetImagesByCatalog(int id, int offset = 0, int limit = 4)
public async Task<ActionResult<IEnumerable<ImagesListItemDto>>> GetImagesByCatalog(int id, int offset = 0, int limit = 4)
{
ServiceResponse<PaginationListDto<ImageDto>> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit);
ServiceResponse<PaginationListDto<ImagesListItemDto>> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit);
if (serviceGetImagesByCatalog.Success == false)
{
return Forbid(serviceGetImagesByCatalog.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public CatalogConfiguration(EntityTypeBuilder<Catalog> entityBuilder)
entityBuilder.HasKey(c => c.Id);
entityBuilder.Property(c => c.Id).HasColumnName("id");
entityBuilder.Property(c => c.Name).HasColumnName("name").HasMaxLength(30).IsRequired();
entityBuilder.HasOne(c => c.ParentCatalog).WithMany().OnDelete(DeleteBehavior.Cascade);
entityBuilder.Property(c => c.ParentCatalogId).HasColumnName("parent_catalog_id");
entityBuilder.Property(c => c.UserId).HasColumnName("user_id");
entityBuilder.Property(c => c.Id).ValueGeneratedOnAdd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ public ImageConfiguration(EntityTypeBuilder<Image> entityBuilder)
entityBuilder.Property(i => i.Title).HasColumnName("title").HasMaxLength(200).IsRequired();
entityBuilder.Property(i => i.Description).HasColumnName("description").HasColumnType("text");
entityBuilder.Property(i => i.KeyWords).HasColumnName("key_words").HasColumnType("text");
entityBuilder.Property(i => i.ServiceId).HasColumnName("service_id").IsRequired();
entityBuilder.Property(i => i.ExternalId).HasColumnName("external_id").HasColumnType("text");
entityBuilder.Property(i => i.FileSize).HasColumnName("file_size").IsRequired();
entityBuilder.Property(i => i.Height).HasColumnName("height").IsRequired();
entityBuilder.Property(i => i.Width).HasColumnName("width").IsRequired();
entityBuilder.Property(i => i.LargePreviewUrl).HasColumnName("large_preview_url").HasColumnType("text").IsRequired();
entityBuilder.Property(i => i.SmallPreviewUrl).HasColumnName("small_preview_url").HasColumnType("text").IsRequired();
entityBuilder.Property(i => i.OriginalUrl).HasColumnName("original_url").HasColumnType("text").IsRequired();
entityBuilder.Property(i => i.Id).ValueGeneratedOnAdd();

entityBuilder.HasIndex(i => new { i.ServiceId, i.ExternalId}).IsUnique();

entityBuilder.ToTable("images");
}
}
Expand Down
3 changes: 3 additions & 0 deletions ImageBase.WebApp/Data/Dtos/AddImageDto.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace ImageBase.WebApp.Data.Dtos
{
public class AddImageDto
{
[Required]
[StringLength(200, MinimumLength = 1, ErrorMessage = "Длина строки должна быть от 1 до 200 символов")]
public string Title { get; set; }
public string Description { get; set; }
public string KeyWords { get; set; }
Expand Down
2 changes: 0 additions & 2 deletions ImageBase.WebApp/Data/Dtos/ImageDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace ImageBase.WebApp.Data.Dtos
public class ImageDto
{
public long Id { get; set; }
[Required]
[StringLength(200, MinimumLength = 1, ErrorMessage = "Длина строки должна быть от 1 до 200 символов")]
public string Title { get; set; }
public string Description { get; set; }
}
Expand Down
16 changes: 16 additions & 0 deletions ImageBase.WebApp/Data/Dtos/ImagesListItemDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ImageBase.WebApp.Data.Dtos
{
public class ImagesListItemDto
{
public long Id { get; set; }
public string Title { get; set; }
public string SmallPreviewUrl { get; set; }
public string LargePreviewUrl { get; set; }
public string OriginalUrl { get; set; }
}
}
8 changes: 8 additions & 0 deletions ImageBase.WebApp/Data/Models/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ public class Image: BaseEntity<long>
public string Title { get; set; }
public string Description { get; set; }
public string KeyWords { get; set; }
public int ServiceId { get; set; }
public string ExternalId { get; set; }
public string SmallPreviewUrl { get; set; }
public string LargePreviewUrl { get; set; }
public string OriginalUrl { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int FileSize { get; set; }

public List<ImageCatalog> ImageCatalogs { get; set; }
}
Expand Down
1 change: 1 addition & 0 deletions ImageBase.WebApp/Data/Profiles/CatalogProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public CatalogProfile()
CreateMap<int, ImageCatalog>()
.ForMember(map => map.CatalogId, map => map.MapFrom(c => c));
CreateMap<PaginationListDto<Image>, PaginationListDto<ImageDto>>();
CreateMap<PaginationListDto<Image>, PaginationListDto<ImagesListItemDto>>();
}
}
}
Loading

0 comments on commit 9bd1911

Please sign in to comment.