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

Commit

Permalink
#26 fix dto, migrations and forgotten tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Olya73 committed Dec 4, 2020
1 parent 4b9a207 commit 295b89b
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 77 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 @@ -23,11 +23,11 @@ public ImageConfiguration(EntityTypeBuilder<Image> entityBuilder)
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");
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.ExternalId, i.ServiceId }).IsUnique();
entityBuilder.HasIndex(i => new { i.ServiceId, i.ExternalId}).IsUnique();

entityBuilder.ToTable("images");
}
Expand Down
2 changes: 0 additions & 2 deletions ImageBase.WebApp/Data/Dtos/ImagesListItemDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public class ImagesListItemDto
{
public long Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string KeyWords { get; set; }
public string SmallPreviewUrl { get; set; }
public string LargePreviewUrl { get; set; }
public string OriginalUrl { 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>>();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions ImageBase.WebApp/Migrations/20201203144604_Init_12_3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "small_preview_url",
table: "images",
type: "text",
nullable: true);
nullable: false,
defaultValue: "");

migrationBuilder.AddColumn<int>(
name: "width",
Expand All @@ -61,9 +62,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
defaultValue: 0);

migrationBuilder.CreateIndex(
name: "IX_images_external_id_service_id",
name: "IX_images_service_id_external_id",
table: "images",
columns: new[] { "external_id", "service_id" },
columns: new[] { "service_id", "external_id" },
unique: true);

migrationBuilder.AddForeignKey(
Expand All @@ -82,7 +83,7 @@ protected override void Down(MigrationBuilder migrationBuilder)
table: "catalogs");

migrationBuilder.DropIndex(
name: "IX_images_external_id_service_id",
name: "IX_images_service_id_external_id",
table: "images");

migrationBuilder.DropColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.HasIndex("ExternalId", "ServiceId")
b.HasIndex("ServiceId", "ExternalId")
.IsUnique();

b.ToTable("images");
Expand Down
7 changes: 4 additions & 3 deletions ImageBase.WebApp/Services/Implementations/CatalogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public async Task<ServiceResponse<UpdateImageCatalogDto>> DeleteImageFromCatalog
ImageCatalog imageCatalog = await _repository.GetImageCatalogByIdFKAsync(imageCatalogDto.ImageId, imageCatalogDto.CatalogId);
_repository.DeleteImageFromCatalog(imageCatalog);
await _context.SaveChangesAsync();
serviceResponse.Data = imageCatalogDto;
}
else
{
Expand All @@ -131,14 +132,14 @@ public async Task<ServiceResponse<UpdateImageCatalogDto>> DeleteImageFromCatalog
return serviceResponse;
}

public async Task<ServiceResponse<PaginationListDto<ImageDto>>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null)
public async Task<ServiceResponse<PaginationListDto<ImagesListItemDto>>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null)
{
ServiceResponse<PaginationListDto<ImageDto>> serviceResponse = new ServiceResponse<PaginationListDto<ImageDto>>();
ServiceResponse<PaginationListDto<ImagesListItemDto>> serviceResponse = new ServiceResponse<PaginationListDto<ImagesListItemDto>>();

if (await _repository.HasCatalogWithUserIdAsync(id, userId))
{
PaginationListDto<Image> paginationListDto = await _repository.GetImagesByCatalogAsync(id, offset, limit);
serviceResponse.Data = _mapper.Map<PaginationListDto<Image>, PaginationListDto<ImageDto>>(paginationListDto);
serviceResponse.Data = _mapper.Map<PaginationListDto<Image>, PaginationListDto<ImagesListItemDto>>(paginationListDto);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion ImageBase.WebApp/Services/Interfaces/ICatalogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ICatalogService
Task<ServiceResponse<CatalogDto>> GetCatalogAsync(int id, string userId = null);
Task<ServiceResponse<CatalogDto>> UpdateCatalogAsync(CatalogDto catalogDto);
Task<ServiceResponse<UpdateImageCatalogDto>> DeleteImageFromCatalogAsync(UpdateImageCatalogDto imageCatalogDto, string userId = null);
Task<ServiceResponse<PaginationListDto<ImageDto>>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null);
Task<ServiceResponse<PaginationListDto<ImagesListItemDto>>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null);
Task<ServiceResponse<UpdateImageCatalogDto>> AddImageToCatalogAsync(UpdateImageCatalogDto imageCatalogDto, string userId = null);
Task<IEnumerable<CatalogDto>> GetCatalogsAsync(string userId = null);
Task<ServiceResponse<IEnumerable<CatalogDto>>> GetSubCatalogsAsync(int parentId, string userId = null);
Expand Down

0 comments on commit 295b89b

Please sign in to comment.