From 295b89bbc4c6bea17dd54f605a0fd63e9596c7b0 Mon Sep 17 00:00:00 2001 From: Olya73 Date: Fri, 4 Dec 2020 13:22:19 +0300 Subject: [PATCH] #26 fix dto, migrations and forgotten tests --- .../CatalogServiceTests.cs | 229 +++++++++++++----- .../Controllers/PrivateCatalogsController.cs | 4 +- .../Controllers/PublicCatalogsController.cs | 4 +- .../ImageConfiguration.cs | 4 +- .../Data/Dtos/ImagesListItemDto.cs | 2 - .../Data/Profiles/CatalogProfile.cs | 1 + .../20201203144604_Init_12_3.Designer.cs | 2 +- .../Migrations/20201203144604_Init_12_3.cs | 9 +- .../AspPostgreSQLContextModelSnapshot.cs | 2 +- .../Implementations/CatalogService.cs | 7 +- .../Services/Interfaces/ICatalogService.cs | 2 +- 11 files changed, 189 insertions(+), 77 deletions(-) diff --git a/ImageBase.WebApp.UnitTests/CatalogServiceTests.cs b/ImageBase.WebApp.UnitTests/CatalogServiceTests.cs index fe83f0d..49153a5 100644 --- a/ImageBase.WebApp.UnitTests/CatalogServiceTests.cs +++ b/ImageBase.WebApp.UnitTests/CatalogServiceTests.cs @@ -36,7 +36,7 @@ public CatalogServiceTests() } [Fact] - public async Task GetCatalogAsyncReturnsCatalogDto() + public async Task GetCatalogAsyncCallsMethOfRepositoryAndReturnsServiceResponse_IfCatalogWithUserExists() { var catalog = new Catalog() { @@ -45,39 +45,50 @@ public async Task GetCatalogAsyncReturnsCatalogDto() UserId = "some user" }; _catalogRepositoryMock.Setup(r => r.GetAsync(It.IsAny())).Returns(Task.FromResult(catalog)); + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); - ServiceResponse catalogDto = await _service.GetCatalogAsync(1); + ServiceResponse serviceResponse = await _service.GetCatalogAsync(1); - Assert.NotNull(catalogDto); - Assert.IsAssignableFrom(catalogDto); - Assert.Equal(catalogDto.Data.Id, catalog.Id); - Assert.Equal(catalogDto.Data.Name, catalog.Name); - Assert.Equal(catalogDto.Data.UserId, catalog.UserId); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.Equal(serviceResponse.Data.Id, catalog.Id); + Assert.Equal(serviceResponse.Data.Name, catalog.Name); + Assert.Equal(serviceResponse.Data.UserId, catalog.UserId); } + [Fact] - public async Task CreateCatalogAsyncCallsMethodOfRepository_And_SavesChanges() - { - await _service.CreateCatalogAsync(new CatalogDto()); + public async Task GetCatalogAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithUserDoesntExist() + { + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); - _catalogRepositoryMock.Verify(r => r.Add(It.IsAny()), Times.Once); - _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); + ServiceResponse serviceResponse = await _service.GetCatalogAsync(1); + + _catalogRepositoryMock.Verify(r => r.GetAsync(It.IsAny()), Times.Never); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.False(serviceResponse.Success); + Assert.NotNull(serviceResponse.Message); } [Fact] - public async Task CreateCatalogAsyncReturnsServiceResponse_IfCatalogWithNameExists() + public async Task CreateCatalogAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithNameExists() { CatalogDto catalogDto = new CatalogDto(); _catalogRepositoryMock.Setup(r => r.HasChildWithNameAsync(It.IsAny())) .Returns(Task.FromResult(true)); ServiceResponse serviceResponse = await _service.CreateCatalogAsync(catalogDto); - + + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); Assert.False(serviceResponse.Success); Assert.NotNull(serviceResponse.Message); - } + } [Fact] - public async Task CreateCatalogAsyncReturnsServiceResponse_IfCatalogWithNameDoesntExsist() + public async Task CreateCatalogAsyncCallsMethOfRepositoryAndReturnsServiceResponse_IfCatalogWithNameDoesntExsist() { CatalogDto catalogDto = new CatalogDto(); _catalogRepositoryMock.Setup(r => r.HasChildWithNameAsync(It.IsAny())) @@ -85,32 +96,53 @@ public async Task CreateCatalogAsyncReturnsServiceResponse_IfCatalogWithNameDoes ServiceResponse serviceResponse = await _service.CreateCatalogAsync(catalogDto); + _catalogRepositoryMock.Verify(r => r.Add(It.IsAny()), Times.Once); + _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.True(serviceResponse.Success); + Assert.Equal(catalogDto, serviceResponse.Data); + } + + [Fact] + public async Task DeleteCatalogAsyncCallsMethOfRepositoryAndReturnsServiceResponse_IfCatalogWithUserExists() + { + int id = 1; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); + + ServiceResponse serviceResponse = await _service.DeleteCatalogAsync(id); + + _catalogRepositoryMock.Verify(r => r.DeleteAsync(It.IsAny()), Times.Once); + _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); Assert.True(serviceResponse.Success); - Assert.Equal(serviceResponse.Data, catalogDto); + Assert.Equal(id, serviceResponse.Data); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async Task DeleteCatalogAsyncCallsMethodOfRepository_And_ReturnsBool(bool flag) + [Fact] + public async Task DeleteCatalogAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithUserDoesntExist() { int id = 1; - _catalogRepositoryMock.Setup(r => r.DeleteAsync(It.IsAny())).Returns(Task.FromResult(flag)); + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); ServiceResponse serviceResponse = await _service.DeleteCatalogAsync(id); - Assert.Equal(flag, serviceResponse.Success); - if (flag) - _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); - else - _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Never); + _catalogRepositoryMock.Verify(r => r.DeleteAsync(It.IsAny()), Times.Never); + _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Never); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.False(serviceResponse.Success); + Assert.NotNull(serviceResponse.Message); } [Fact] public async Task GetCatalogsAsyncReturnsIEnumerableCatalogDto() { var catalogs = new Catalog[4]; - _catalogRepositoryMock.Setup(r => r.GetAllAsync()).Returns(Task.FromResult((IEnumerable)catalogs)); + _catalogRepositoryMock.Setup(r => r.GetCatalogsAsync(It.IsAny())).Returns(Task.FromResult((IEnumerable)catalogs)); IEnumerable catalogDtos = await _service.GetCatalogsAsync(); @@ -119,112 +151,191 @@ public async Task GetCatalogsAsyncReturnsIEnumerableCatalogDto() } [Fact] - public async Task UpdateCatalogAsyncCallsMethodOfRepository_And_SavesChanges() + public async Task UpdateCatalogAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithNameExists() + { + _catalogRepositoryMock.Setup(r => r.HasChildWithNameAsync(It.IsAny())) + .Returns(Task.FromResult(true)); + + ServiceResponse serviceResponse = await _service.UpdateCatalogAsync(new CatalogDto()); + + _catalogRepositoryMock.Verify(r => r.Update(It.IsAny()), Times.Never); + _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Never); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.False(serviceResponse.Success); + Assert.NotNull(serviceResponse.Message); + } + + [Fact] + public async Task DeleteImageFromCatalogAsyncCallsMethOfRepositoryAndReturnsServiceResponse_IfCatalogWithUserExists() { - var catalog = new CatalogDto() + var imageCatalog = new UpdateImageCatalogDto() { - Name = "catalog 1", + CatalogId = 1, + ImageId = 1 }; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); - ServiceResponse serviceResponse = await _service.UpdateCatalogAsync(catalog); + ServiceResponse serviceResponse = await _service.DeleteImageFromCatalogAsync(imageCatalog); - _catalogRepositoryMock.Verify(r => r.Update(It.IsAny()), Times.Once); + _catalogRepositoryMock.Verify(r => r.DeleteImageFromCatalog(It.IsAny()), Times.Once); _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.True(serviceResponse.Success); + Assert.Equal(imageCatalog, serviceResponse.Data); } [Fact] - public async Task DeleteImageFromCatalogAsyncCallsMethodOfRepository_And_SavesChanges() + public async Task DeleteImageFromCatalogAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithUserDoesntExist() { var imageCatalog = new UpdateImageCatalogDto() { CatalogId = 1, ImageId = 1 }; - ImageCatalog ic = new ImageCatalog(); + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); - await _service.DeleteImageFromCatalogAsync(imageCatalog); + ServiceResponse serviceResponse = await _service.DeleteImageFromCatalogAsync(imageCatalog); - _catalogRepositoryMock.Verify(r => r.DeleteImageFromCatalog(It.IsAny()), Times.Once); - _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); + _catalogRepositoryMock.Verify(r => r.DeleteImageFromCatalog(It.IsAny()), Times.Never); + _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Never); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.False(serviceResponse.Success); + Assert.Null(serviceResponse.Data); + Assert.NotNull(serviceResponse.Message); } [Fact] - public async Task GetImagesByCatalogAsyncReturnsPaginationListDtoImages() + public async Task GetImagesByCatalogAsyncCallsMethOfRepositoryAndReturnsServiceResponse_IfCatalogWithUserExists() { int id = 1; int limit = 4; int offset = 0; PaginationListDto paginationList = new PaginationListDto() { Items = new Image[4]}; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); _catalogRepositoryMock.Setup(r => r.GetImagesByCatalogAsync(id, It.IsAny(), It.IsAny())) .Returns(Task.FromResult(paginationList)); - ServiceResponse> serviceResponse = await _service.GetImagesFromCatalogAsync(id, offset, limit); + ServiceResponse> serviceResponse = await _service.GetImagesFromCatalogAsync(id, offset, limit); _catalogRepositoryMock.Verify(r => r.GetImagesByCatalogAsync(id, offset, limit), Times.Once); Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>>(serviceResponse); + Assert.True(serviceResponse.Success); Assert.Equal(paginationList.Items.Count, serviceResponse.Data.Items.Count); } [Fact] - public async Task AddImageToCatalogAsyncCallsMethodOfRepository_And_SavesChanges() + public async Task GetImagesByCatalogAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithUserDoesntExist() + { + int id = 1; + int limit = 4; + int offset = 0; + PaginationListDto paginationList = new PaginationListDto() { Items = new Image[4] }; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); + + ServiceResponse> serviceResponse = await _service.GetImagesFromCatalogAsync(id, offset, limit); + + _catalogRepositoryMock.Verify(r => r.GetImagesByCatalogAsync(id, offset, limit), Times.Never); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>>(serviceResponse); + Assert.False(serviceResponse.Success); + Assert.Null(serviceResponse.Data); + Assert.NotNull(serviceResponse.Message); + } + + [Fact] + public async Task AddImageToCatalogAsyncCallsMethOfRepositoryAndReturnsServiceResponse_IfCatalogWithUserExists() { var updateImageCatalog = new UpdateImageCatalogDto() { CatalogId = 1, ImageId = 1 }; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); Expression> ex = i => i.ImageId == updateImageCatalog.ImageId && i.CatalogId == updateImageCatalog.CatalogId; - await _service.AddImageToCatalogAsync(updateImageCatalog); + ServiceResponse serviceResponse = await _service.AddImageToCatalogAsync(updateImageCatalog); _catalogRepositoryMock.Verify(r => r.AddImageToCatalog(It.Is(ex)), Times.Once); _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>(serviceResponse); + Assert.True(serviceResponse.Success); + Assert.Equal(updateImageCatalog, serviceResponse.Data); } [Fact] - public async Task GetSubCatalogsAsyncCallsMethodOfRepository_And_ReturnsCatalogsDto() + public async Task AddImageToCatalogAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithUserDoesntExist() { - int id = 1; + var updateImageCatalog = new UpdateImageCatalogDto() + { + CatalogId = 1, + ImageId = 1 + }; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); + Expression> ex = i => i.ImageId == updateImageCatalog.ImageId && i.CatalogId == updateImageCatalog.CatalogId; - ServiceResponse> serviceResponse = await _service.GetSubCatalogsAsync(id); + ServiceResponse serviceResponse = await _service.AddImageToCatalogAsync(updateImageCatalog); + _catalogRepositoryMock.Verify(r => r.AddImageToCatalog(It.Is(ex)), Times.Never); + _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Never); Assert.NotNull(serviceResponse); - _catalogRepositoryMock.Verify(r => r.GetSubCatalogsAsync(id), Times.Once); + Assert.IsAssignableFrom>(serviceResponse); + Assert.False(serviceResponse.Success); + Assert.Null(serviceResponse.Data); + Assert.NotNull(serviceResponse.Message); } [Fact] - public async Task GetCatalogsByUserAsyncCallsMethodOfRepository_And_ReturnsCatalogsDto() + public async Task GetSubCatalogsAsyncCallsMethOfRepositoryAndReturnsServiceResponse_IfCatalogWithUserExists() { - var id = "user id"; + int id = 1; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); - IEnumerable catalogsDto = await _service.GetCatalogsAsync(id); + ServiceResponse> serviceResponse = await _service.GetSubCatalogsAsync(id); - Assert.NotNull(catalogsDto); - _catalogRepositoryMock.Verify(r => r.GetCatalogsAsync(id), Times.Once); + _catalogRepositoryMock.Verify(r => r.GetSubCatalogsAsync(id), Times.Once); + Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>>(serviceResponse); + Assert.True(serviceResponse.Success); } [Fact] - public async Task GetSubCatalogsByUserAsync_IfCatalogDoesntExist() + public async Task GetSubCatalogsAsyncReturnsUnsuccesfullServiceResponse_IfCatalogWithUserDoesntExist() { - _catalogRepositoryMock.Setup(c => c.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); + int id = 1; + _catalogRepositoryMock.Setup(r => r.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(false)); - ServiceResponse> serviceResponse = await _service.GetSubCatalogsAsync(It.IsAny(), It.IsAny()); + ServiceResponse> serviceResponse = await _service.GetSubCatalogsAsync(id); + _catalogRepositoryMock.Verify(r => r.GetSubCatalogsAsync(id), Times.Never); Assert.NotNull(serviceResponse); + Assert.IsAssignableFrom>>(serviceResponse); Assert.False(serviceResponse.Success); + Assert.Null(serviceResponse.Data); Assert.NotNull(serviceResponse.Message); } [Fact] - public async Task GetSubCatalogsByUserAsync_IfCatalogExists() + public async Task GetCatalogsAsyncCallsMethodOfRepository_And_ReturnsCatalogsDto() { - _catalogRepositoryMock.Setup(c => c.HasCatalogWithUserIdAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); + var id = "user id"; - ServiceResponse> serviceResponse = await _service.GetSubCatalogsAsync(It.IsAny(), It.IsAny()); + IEnumerable catalogsDto = await _service.GetCatalogsAsync(id); - Assert.NotNull(serviceResponse); - Assert.True(serviceResponse.Success); + Assert.NotNull(catalogsDto); + _catalogRepositoryMock.Verify(r => r.GetCatalogsAsync(id), Times.Once); } } } diff --git a/ImageBase.WebApp/Controllers/PrivateCatalogsController.cs b/ImageBase.WebApp/Controllers/PrivateCatalogsController.cs index 81a65f4..a181490 100644 --- a/ImageBase.WebApp/Controllers/PrivateCatalogsController.cs +++ b/ImageBase.WebApp/Controllers/PrivateCatalogsController.cs @@ -48,9 +48,9 @@ public async Task>> GetSubCatalogsAsync(int } [HttpGet("image/{id:int}")] - public async Task>> GetImagesByCatalog(int id, int offset = 0, int limit = 4) + public async Task>> GetImagesByCatalog(int id, int offset = 0, int limit = 4) { - ServiceResponse> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit, await CurrentUser()); + ServiceResponse> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit, await CurrentUser()); if (serviceGetImagesByCatalog.Success == false) { return Forbid(serviceGetImagesByCatalog.Message); diff --git a/ImageBase.WebApp/Controllers/PublicCatalogsController.cs b/ImageBase.WebApp/Controllers/PublicCatalogsController.cs index dc34c10..a31894d 100644 --- a/ImageBase.WebApp/Controllers/PublicCatalogsController.cs +++ b/ImageBase.WebApp/Controllers/PublicCatalogsController.cs @@ -51,9 +51,9 @@ public async Task>> GetSubCatalogsAsync(int } [HttpGet("image/{id:int}")] - public async Task>> GetImagesByCatalog(int id, int offset = 0, int limit = 4) + public async Task>> GetImagesByCatalog(int id, int offset = 0, int limit = 4) { - ServiceResponse> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit); + ServiceResponse> serviceGetImagesByCatalog = await _catalogService.GetImagesFromCatalogAsync(id, offset, limit); if (serviceGetImagesByCatalog.Success == false) { return Forbid(serviceGetImagesByCatalog.Message); diff --git a/ImageBase.WebApp/Data/ConfigurationDataBase/ConfigurationPostgreSQL/ImageConfiguration.cs b/ImageBase.WebApp/Data/ConfigurationDataBase/ConfigurationPostgreSQL/ImageConfiguration.cs index be17ea0..193d6c9 100644 --- a/ImageBase.WebApp/Data/ConfigurationDataBase/ConfigurationPostgreSQL/ImageConfiguration.cs +++ b/ImageBase.WebApp/Data/ConfigurationDataBase/ConfigurationPostgreSQL/ImageConfiguration.cs @@ -23,11 +23,11 @@ public ImageConfiguration(EntityTypeBuilder 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"); } diff --git a/ImageBase.WebApp/Data/Dtos/ImagesListItemDto.cs b/ImageBase.WebApp/Data/Dtos/ImagesListItemDto.cs index d5534b1..247673d 100644 --- a/ImageBase.WebApp/Data/Dtos/ImagesListItemDto.cs +++ b/ImageBase.WebApp/Data/Dtos/ImagesListItemDto.cs @@ -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; } diff --git a/ImageBase.WebApp/Data/Profiles/CatalogProfile.cs b/ImageBase.WebApp/Data/Profiles/CatalogProfile.cs index 23eda86..ad323f2 100644 --- a/ImageBase.WebApp/Data/Profiles/CatalogProfile.cs +++ b/ImageBase.WebApp/Data/Profiles/CatalogProfile.cs @@ -19,6 +19,7 @@ public CatalogProfile() CreateMap() .ForMember(map => map.CatalogId, map => map.MapFrom(c => c)); CreateMap, PaginationListDto>(); + CreateMap, PaginationListDto>(); } } } diff --git a/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.Designer.cs b/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.Designer.cs index 4c53c21..21d5270 100644 --- a/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.Designer.cs +++ b/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.Designer.cs @@ -189,7 +189,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ExternalId", "ServiceId") + b.HasIndex("ServiceId", "ExternalId") .IsUnique(); b.ToTable("images"); diff --git a/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.cs b/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.cs index 69be55f..594356a 100644 --- a/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.cs +++ b/ImageBase.WebApp/Migrations/20201203144604_Init_12_3.cs @@ -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( name: "width", @@ -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( @@ -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( diff --git a/ImageBase.WebApp/Migrations/AspPostgreSQLContextModelSnapshot.cs b/ImageBase.WebApp/Migrations/AspPostgreSQLContextModelSnapshot.cs index 20e28d1..ff6f84d 100644 --- a/ImageBase.WebApp/Migrations/AspPostgreSQLContextModelSnapshot.cs +++ b/ImageBase.WebApp/Migrations/AspPostgreSQLContextModelSnapshot.cs @@ -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"); diff --git a/ImageBase.WebApp/Services/Implementations/CatalogService.cs b/ImageBase.WebApp/Services/Implementations/CatalogService.cs index c38d115..48f53db 100644 --- a/ImageBase.WebApp/Services/Implementations/CatalogService.cs +++ b/ImageBase.WebApp/Services/Implementations/CatalogService.cs @@ -121,6 +121,7 @@ public async Task> DeleteImageFromCatalog ImageCatalog imageCatalog = await _repository.GetImageCatalogByIdFKAsync(imageCatalogDto.ImageId, imageCatalogDto.CatalogId); _repository.DeleteImageFromCatalog(imageCatalog); await _context.SaveChangesAsync(); + serviceResponse.Data = imageCatalogDto; } else { @@ -131,14 +132,14 @@ public async Task> DeleteImageFromCatalog return serviceResponse; } - public async Task>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null) + public async Task>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null) { - ServiceResponse> serviceResponse = new ServiceResponse>(); + ServiceResponse> serviceResponse = new ServiceResponse>(); if (await _repository.HasCatalogWithUserIdAsync(id, userId)) { PaginationListDto paginationListDto = await _repository.GetImagesByCatalogAsync(id, offset, limit); - serviceResponse.Data = _mapper.Map, PaginationListDto>(paginationListDto); + serviceResponse.Data = _mapper.Map, PaginationListDto>(paginationListDto); } else { diff --git a/ImageBase.WebApp/Services/Interfaces/ICatalogService.cs b/ImageBase.WebApp/Services/Interfaces/ICatalogService.cs index 7857a16..e51c75d 100644 --- a/ImageBase.WebApp/Services/Interfaces/ICatalogService.cs +++ b/ImageBase.WebApp/Services/Interfaces/ICatalogService.cs @@ -14,7 +14,7 @@ public interface ICatalogService Task> GetCatalogAsync(int id, string userId = null); Task> UpdateCatalogAsync(CatalogDto catalogDto); Task> DeleteImageFromCatalogAsync(UpdateImageCatalogDto imageCatalogDto, string userId = null); - Task>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null); + Task>> GetImagesFromCatalogAsync(int id, int offset, int limit, string userId = null); Task> AddImageToCatalogAsync(UpdateImageCatalogDto imageCatalogDto, string userId = null); Task> GetCatalogsAsync(string userId = null); Task>> GetSubCatalogsAsync(int parentId, string userId = null);