From 255bd7a76ad54ad3f90763f469ed3e6167a3dc74 Mon Sep 17 00:00:00 2001 From: OlhaHoliak <59091855+OlhaHoliak@users.noreply.github.com> Date: Thu, 1 Jul 2021 17:55:01 +0300 Subject: [PATCH] Olhaholiak/categories renaming (#181) * renamed entities * migrations * added swagger grouping * deleted dead usings, separated the interfase --- Config/SQLQuery_insert test values.sql | 60 +- .../Models/{Subsubcategory.cs => Class.cs} | 6 +- .../Models/{Subcategory.cs => Department.cs} | 8 +- .../Models/{Category.cs => Direction.cs} | 4 +- .../OutOfSchool.DataAccess/Models/Workshop.cs | 8 +- .../OutOfSchoolDbContext.cs | 6 +- .../Repository/ClassRepository.cs | 22 + .../Repository/DepartmentRepository.cs | 22 + .../Repository/IClassRepository.cs | 14 + .../Repository/IDepartmentRepository.cs | 14 + .../Repository/IExistable.cs | 12 + .../Repository/IProviderRepository.cs | 4 +- .../Repository/ISubcategoryRepository.cs | 14 - .../Repository/ISubsubcategoryRepository.cs | 14 - .../Repository/IWorkshopRepository.cs | 8 +- .../Repository/ProviderRepository.cs | 2 +- .../Repository/SubcategoryRepository.cs | 33 - .../Repository/SubsubcategoryRepository.cs | 33 - .../Repository/WorkshopRepository.cs | 2 +- ...0210630091927_RenameCategories.Designer.cs | 1021 +++++++++++++++++ .../20210630091927_RenameCategories.cs | 267 +++++ .../OutOfSchoolDbContextModelSnapshot.cs | 244 ++-- ...rollerTests.cs => ClassControllerTests.cs} | 108 +- ...rTests.cs => DepartmentControllerTests.cs} | 108 +- ...erTests.cs => DirectionControllerTests.cs} | 80 +- .../Controllers/WorkshopControllerTests.cs | 20 +- ...ryServiceTests.cs => ClassServiceTests.cs} | 66 +- ...viceTests.cs => DepartmentServiceTests.cs} | 60 +- ...rviceTests.cs => DirectionServiceTests.cs} | 28 +- .../UnitTests/WorkshopServiceTests.cs | 62 +- .../Services/WorkshopServiceTests.cs | 108 +- .../Controllers/CategoryController.cs | 150 --- .../Controllers/ClassController.cs | 208 ++++ .../Controllers/DepartmentController.cs | 208 ++++ .../Controllers/DirectionController.cs | 174 +++ .../Controllers/SubcategoryController.cs | 179 --- .../Controllers/SubsubcategoryController.cs | 179 --- .../Controllers/WorkshopController.cs | 6 +- .../Extensions/MappingExtensions.cs | 72 +- .../{SubsubcategoryDTO.cs => ClassDto.cs} | 4 +- .../{SubcategoryDTO.cs => DepartmentDto.cs} | 4 +- .../{CategoryDTO.cs => DirectionDto.cs} | 2 +- .../OutOfSchool.WebApi/Models/WorkshopDTO.cs | 6 +- .../Models/WorkshopFilter.cs | 6 +- .../Services/CategoryService.cs | 134 --- .../Services/ChildService.cs | 2 +- .../Services/ClassService.cs | 158 +++ .../Services/DepartmentService.cs | 170 +++ .../Services/DirectionService.cs | 134 +++ .../Services/ICategoryService.cs | 48 - .../Services/IClassService.cs | 58 + .../Services/IDepartmentService.cs | 58 + .../Services/IDirectionService.cs | 50 + .../Services/ISubcategoryService.cs | 55 - .../Services/ISubsubcategoryService.cs | 55 - .../Services/ProviderService.cs | 2 +- .../Services/SubcategoryService.cs | 170 --- .../Services/SubsubcategoryService.cs | 158 --- .../Services/WorkshopService.cs | 50 +- OutOfSchool/OutOfSchool.WebApi/Startup.cs | 35 +- 60 files changed, 3199 insertions(+), 1794 deletions(-) rename OutOfSchool/OutOfSchool.DataAccess/Models/{Subsubcategory.cs => Class.cs} (77%) rename OutOfSchool/OutOfSchool.DataAccess/Models/{Subcategory.cs => Department.cs} (69%) rename OutOfSchool/OutOfSchool.DataAccess/Models/{Category.cs => Direction.cs} (82%) create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/ClassRepository.cs create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/DepartmentRepository.cs create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/IClassRepository.cs create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/IDepartmentRepository.cs create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/IExistable.cs delete mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/ISubcategoryRepository.cs delete mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/ISubsubcategoryRepository.cs delete mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/SubcategoryRepository.cs delete mode 100644 OutOfSchool/OutOfSchool.DataAccess/Repository/SubsubcategoryRepository.cs create mode 100644 OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.Designer.cs create mode 100644 OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.cs rename OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/{SubcategoryControllerTests.cs => ClassControllerTests.cs} (57%) rename OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/{SubsubcategoryControllerTests.cs => DepartmentControllerTests.cs} (56%) rename OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/{CategoryControllerTests.cs => DirectionControllerTests.cs} (61%) rename OutOfSchool/OutOfSchool.WebApi.Tests/Services/{SubsubcategoryServiceTests.cs => ClassServiceTests.cs} (78%) rename OutOfSchool/OutOfSchool.WebApi.Tests/Services/{SubcategoryServiceTests.cs => DepartmentServiceTests.cs} (80%) rename OutOfSchool/OutOfSchool.WebApi.Tests/Services/{CategoryServiceTests.cs => DirectionServiceTests.cs} (88%) delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Controllers/ClassController.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Controllers/DepartmentController.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Controllers/DirectionController.cs delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs rename OutOfSchool/OutOfSchool.WebApi/Models/{SubsubcategoryDTO.cs => ClassDto.cs} (86%) rename OutOfSchool/OutOfSchool.WebApi/Models/{SubcategoryDTO.cs => DepartmentDto.cs} (85%) rename OutOfSchool/OutOfSchool.WebApi/Models/{CategoryDTO.cs => DirectionDto.cs} (93%) delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/ClassService.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/DepartmentService.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/DirectionService.cs delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/ICategoryService.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/IClassService.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/IDepartmentService.cs create mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/IDirectionService.cs delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/ISubcategoryService.cs delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/ISubsubcategoryService.cs delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs delete mode 100644 OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs diff --git a/Config/SQLQuery_insert test values.sql b/Config/SQLQuery_insert test values.sql index 99080f36b1..ba094928b9 100644 --- a/Config/SQLQuery_insert test values.sql +++ b/Config/SQLQuery_insert test values.sql @@ -139,16 +139,16 @@ INSERT INTO [dbo].[AspNetUserRoles] ,[RoleId]) VALUES ('16575ce5-38e3-4ae7-b991-4508ed488369' --UserId (test1) - ,'c2e1a3bd-bafd-4c94-bc63-d33791b6e3c8') --roleId (parent) + ,'12470199-4ac1-47b3-975d-bb4dca8b8d05') --roleId (parent) ,('7604a851-66db-4236-9271-1f037ffe3a81' --UserId (test2) - ,'c2e1a3bd-bafd-4c94-bc63-d33791b6e3c8') --roleId (parent) + ,'12470199-4ac1-47b3-975d-bb4dca8b8d05') --roleId (parent) ,('47802b21-2fb5-435e-9057-75c43d002cef' --UserId (test3) - ,'739f5d36-64da-42d9-a967-bec1695e0e61') --roleId (provider) + ,'dd8cb086-4f49-407c-82d2-f835289870b5') --roleId (provider) ,('5bff5f95-1848-4c87-9846-a567aeb407ea' --UserId (test4) - ,'739f5d36-64da-42d9-a967-bec1695e0e61') --roleId (provider) + ,'dd8cb086-4f49-407c-82d2-f835289870b5') --roleId (provider) GO --====================PARENTS AND CHILDREN================================ @@ -240,11 +240,11 @@ INSERT INTO [dbo].[BirthCertificates] GO --==================== PROVIDERS AND WORKSHOPS ================================ ---Categories -INSERT INTO Categories (Title, Description) VALUES ('Музика', 'Музика'), ('Танці', 'Танці'), ('Спорт', 'Спорт') +--Directions +INSERT INTO Directions (Title, Description) VALUES ('Музика', 'Музика'), ('Танці', 'Танці'), ('Спорт', 'Спорт') GO -INSERT INTO Subcategories (Title, Description, CategoryId) +INSERT INTO Departments (Title, Description, DirectionId) VALUES ('Народних інструментів', 'Народних інструментів', 1), ('Духових та ударних інструментів', 'Духових та ударних інструментів', 1), @@ -253,7 +253,7 @@ VALUES ('Неолімпійські види спорту', 'Неолімпійські види спорту', 3) GO -INSERT INTO SubSubcategories (Title, Description, SubcategoryId) +INSERT INTO Classes (Title, Description, DepartmentId) VALUES ('Бандура', 'Клас Бандури', 1), ('Акордеон', 'Клас Акордеону', 1), @@ -441,9 +441,9 @@ INSERT INTO [dbo].[Workshops] ,[IsPerMonth] ,[ProviderId] ,[AddressId] - ,[CategoryId] - ,[SubcategoryId] - ,[SubsubcategoryId]) + ,[DirectionId] + ,[DepartmentId] + ,[ClassId]) VALUES ('Уроки аккордиону' ,'1234567890' --Phone @@ -464,9 +464,9 @@ INSERT INTO [dbo].[Workshops] ,1 --IsPerMonth ,1 --ProviderId ,5 --AddressId - ,1 --categoryId - ,2 --subcategoryId - ,2) --SubsubcategoryId + ,1 --directionId + ,2 --departmentId + ,2) --classId ,('Уроки бандури' ,'1234567890' --Phone @@ -487,9 +487,9 @@ INSERT INTO [dbo].[Workshops] ,1 --IsPerMonth ,1 --ProviderId ,6 --AddressId - ,1 --categoryId - ,1 --subcategoryId - ,1) --SubsubcategoryId + ,1 --directionId + ,1 --departmentId + ,1) --classId ,('Гра на барабані' ,'1234567890' --Phone @@ -510,9 +510,9 @@ INSERT INTO [dbo].[Workshops] ,0 --IsPerMonth ,1 --ProviderId ,7 --AddressId - ,1 --categoryId - ,2 --subcategoryId - ,3) --SubsubcategoryId + ,1 --directionId + ,2 --departmentId + ,3) --classId ,('Уроки гри на флейті' ,'1234567890' --Phone @@ -523,7 +523,7 @@ INSERT INTO [dbo].[Workshops] ,5 --minAge ,100 --maxAge ,2 --days per week - ,0 --price + ,100 --price ,'Уроки гри на флейті' ,1 --WithDisabilityOptions ,'Немає конкретних обмежень' -- disability description @@ -533,9 +533,9 @@ INSERT INTO [dbo].[Workshops] ,0 --IsPerMonth ,1 --ProviderId ,8 --AddressId - ,1 --categoryId - ,2 --subcategoryId - ,4) --SubsubcategoryId + ,1 --directionId + ,2 --departmentId + ,4) --classId ,('Айкідо' ,'1234567890' --Phone @@ -556,9 +556,9 @@ INSERT INTO [dbo].[Workshops] ,1 --IsPerMonth ,2 --ProviderId ,9 --AddressId - ,3 --categoryId - ,5 --subcategoryId - ,9) --SubsubcategoryId + ,3 --directionId + ,5 --departmentId + ,9) --classId ,('Плавання' ,'1234567890' --Phone @@ -579,9 +579,9 @@ INSERT INTO [dbo].[Workshops] ,1 --IsPerMonth ,2 --ProviderId ,10 --AddressId - ,3 --categoryId - ,4 --subcategoryId - ,7) --SubsubcategoryId + ,3 --directionId + ,4 --departmentId + ,7) --classId GO --teachers diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Subsubcategory.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Class.cs similarity index 77% rename from OutOfSchool/OutOfSchool.DataAccess/Models/Subsubcategory.cs rename to OutOfSchool/OutOfSchool.DataAccess/Models/Class.cs index 4e7dd7ef79..6bb2231c6d 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Subsubcategory.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Class.cs @@ -5,7 +5,7 @@ namespace OutOfSchool.Services.Models { - public class Subsubcategory + public class Class { public long Id { get; set; } @@ -19,8 +19,8 @@ public class Subsubcategory public string Description { get; set; } = string.Empty; [Required] - public long SubcategoryId { get; set; } + public long DepartmentId { get; set; } - public virtual Subcategory Subcategory { get; set; } + public virtual Department Department { get; set; } } } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Subcategory.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Department.cs similarity index 69% rename from OutOfSchool/OutOfSchool.DataAccess/Models/Subcategory.cs rename to OutOfSchool/OutOfSchool.DataAccess/Models/Department.cs index 51211088ef..a200b6c2ed 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Subcategory.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Department.cs @@ -3,7 +3,7 @@ namespace OutOfSchool.Services.Models { - public class Subcategory + public class Department { public long Id { get; set; } @@ -17,10 +17,10 @@ public class Subcategory public string Description { get; set; } = string.Empty; [Required] - public long CategoryId { get; set; } + public long DirectionId { get; set; } - public virtual Category Category { get; set; } + public virtual Direction Direction { get; set; } - public virtual List Subsubcategories { get; set; } + public virtual List Classes { get; set; } } } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Category.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Direction.cs similarity index 82% rename from OutOfSchool/OutOfSchool.DataAccess/Models/Category.cs rename to OutOfSchool/OutOfSchool.DataAccess/Models/Direction.cs index 7e14f00b11..2677b19dd3 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Category.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Direction.cs @@ -3,7 +3,7 @@ namespace OutOfSchool.Services.Models { - public class Category + public class Direction { public long Id { get; set; } @@ -16,6 +16,6 @@ public class Category [MaxLength(500)] public string Description { get; set; } = string.Empty; - public virtual List Subcategories { get; set; } + public virtual List Departments { get; set; } } } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs index 333f4c78d9..5a3dd97d0b 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs @@ -84,19 +84,19 @@ public class Workshop public long AddressId { get; set; } [Required] - public long CategoryId { get; set; } + public long DirectionId { get; set; } [Required] - public long SubcategoryId { get; set; } + public long DepartmentId { get; set; } [Required] - public long SubsubcategoryId { get; set; } + public long ClassId { get; set; } public virtual Provider Provider { get; set; } public virtual Address Address { get; set; } - public virtual Subsubcategory Subsubcategory { get; set; } + public virtual Class Class { get; set; } public virtual List Teachers { get; set; } diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs index fd419a966a..35beafb134 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs @@ -22,11 +22,11 @@ public OutOfSchoolDbContext(DbContextOptions options) public DbSet Teachers { get; set; } - public DbSet Subcategories { get; set; } + public DbSet Departments { get; set; } - public DbSet Subsubcategories { get; set; } + public DbSet Classes { get; set; } - public DbSet Categories { get; set; } + public DbSet Directions { get; set; } public DbSet SocialGroups { get; set; } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/ClassRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/ClassRepository.cs new file mode 100644 index 0000000000..151cdbe39b --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/ClassRepository.cs @@ -0,0 +1,22 @@ +using System.Linq; +using OutOfSchool.Services.Models; + +namespace OutOfSchool.Services.Repository +{ + public class ClassRepository : EntityRepository, IClassRepository + { + private readonly OutOfSchoolDbContext db; + + public ClassRepository(OutOfSchoolDbContext dbContext) + : base(dbContext) + { + db = dbContext; + } + + /// + public bool SameExists(Class entity) => db.Classes.Any(x => (x.Title == entity.Title) && (x.DepartmentId == entity.DepartmentId)); + + /// + public bool DepartmentExists(long id) => db.Departments.Any(x => x.Id == id); + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/DepartmentRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/DepartmentRepository.cs new file mode 100644 index 0000000000..530fc340c0 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/DepartmentRepository.cs @@ -0,0 +1,22 @@ +using System.Linq; +using OutOfSchool.Services.Models; + +namespace OutOfSchool.Services.Repository +{ + public class DepartmentRepository : EntityRepository, IDepartmentRepository + { + private readonly OutOfSchoolDbContext db; + + public DepartmentRepository(OutOfSchoolDbContext dbContext) + : base(dbContext) + { + db = dbContext; + } + + /// + public bool SameExists(Department entity) => db.Departments.Any(x => (x.Title == entity.Title) && (x.DirectionId == entity.DirectionId)); + + /// + public bool DirectionExists(long id) => db.Directions.Any(x => x.Id == id); + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IClassRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IClassRepository.cs new file mode 100644 index 0000000000..84877501b3 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IClassRepository.cs @@ -0,0 +1,14 @@ +using OutOfSchool.Services.Models; + +namespace OutOfSchool.Services.Repository +{ + public interface IClassRepository : IEntityRepository, IExistable + { + /// + /// Checks entity departmentId existens. + /// + /// Department id. + /// Bool. + bool DepartmentExists(long id); + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IDepartmentRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IDepartmentRepository.cs new file mode 100644 index 0000000000..0ba6bb5c66 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IDepartmentRepository.cs @@ -0,0 +1,14 @@ +using OutOfSchool.Services.Models; + +namespace OutOfSchool.Services.Repository +{ + public interface IDepartmentRepository : IEntityRepository, IExistable + { + /// + /// Checks entity directionId existens. + /// + /// Direction id. + /// Bool. + bool DirectionExists(long id); + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IExistable.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IExistable.cs new file mode 100644 index 0000000000..31be901ba1 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IExistable.cs @@ -0,0 +1,12 @@ +namespace OutOfSchool.Services.Repository +{ + public interface IExistable + { + /// + /// Checks entity elements for uniqueness. + /// + /// Entity. + /// Bool. + bool SameExists(T entity); + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs index 9ff6ed52f1..b298360e67 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs @@ -2,10 +2,8 @@ namespace OutOfSchool.Services.Repository { - public interface IProviderRepository : IEntityRepository + public interface IProviderRepository : IEntityRepository, IExistable { - bool Exists(Provider entity); - bool ExistsUserId(string id); } } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/ISubcategoryRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/ISubcategoryRepository.cs deleted file mode 100644 index e50e7b2e49..0000000000 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/ISubcategoryRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OutOfSchool.Services.Models; - -namespace OutOfSchool.Services.Repository -{ - public interface ISubcategoryRepository : IEntityRepository - { - bool SameExists(Subcategory entity); - - bool CategoryExists(long id); - } -} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/ISubsubcategoryRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/ISubsubcategoryRepository.cs deleted file mode 100644 index 9c961bdde3..0000000000 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/ISubsubcategoryRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OutOfSchool.Services.Models; - -namespace OutOfSchool.Services.Repository -{ - public interface ISubsubcategoryRepository : IEntityRepository - { - bool SameExists(Subsubcategory entity); - - bool SubcategoryExists(long id); - } -} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IWorkshopRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IWorkshopRepository.cs index 09364e17cd..299faa4366 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/IWorkshopRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IWorkshopRepository.cs @@ -9,10 +9,10 @@ namespace OutOfSchool.Services.Repository public interface IWorkshopRepository : IEntityRepository { /// - /// Checks entity subcategoryId existence. + /// Checks entity classId existence. /// - /// Subcategory id. - /// True if Subsubcaategory exists, otherwise false. - bool SubsubcategoryExists(long id); + /// Class id. + /// True if Class exists, otherwise false. + bool ClassExists(long id); } } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs index 615dfda36a..f0b86ebda3 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs @@ -20,7 +20,7 @@ public ProviderRepository(OutOfSchoolDbContext dbContext) /// /// Entity. /// Bool. - public bool Exists(Provider entity) => db.Providers.Any(x => x.EdrpouIpn == entity.EdrpouIpn || x.Email == entity.Email); + public bool SameExists(Provider entity) => db.Providers.Any(x => x.EdrpouIpn == entity.EdrpouIpn || x.Email == entity.Email); /// /// Checks if the user is trying to create second account. diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/SubcategoryRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/SubcategoryRepository.cs deleted file mode 100644 index 7919d7a6b2..0000000000 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/SubcategoryRepository.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using OutOfSchool.Services.Models; - -namespace OutOfSchool.Services.Repository -{ - public class SubcategoryRepository : EntityRepository, ISubcategoryRepository - { - private readonly OutOfSchoolDbContext db; - - public SubcategoryRepository(OutOfSchoolDbContext dbContext) - : base(dbContext) - { - db = dbContext; - } - - /// - /// Checks entity elements for uniqueness. - /// - /// Entity. - /// Bool. - public bool SameExists(Subcategory entity) => db.Subcategories.Any(x => (x.Title == entity.Title) && (x.CategoryId == entity.CategoryId)); - - /// - /// Checks entity categoryId existens. - /// - /// Category id. - /// Bool. - public bool CategoryExists(long id) => db.Categories.Any(x => x.Id == id); - } -} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/SubsubcategoryRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/SubsubcategoryRepository.cs deleted file mode 100644 index 5a570184e1..0000000000 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/SubsubcategoryRepository.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using OutOfSchool.Services.Models; - -namespace OutOfSchool.Services.Repository -{ - public class SubsubcategoryRepository : EntityRepository, ISubsubcategoryRepository - { - private readonly OutOfSchoolDbContext db; - - public SubsubcategoryRepository(OutOfSchoolDbContext dbContext) - : base(dbContext) - { - db = dbContext; - } - - /// - /// Checks entity elements for uniqueness. - /// - /// Entity. - /// Bool. - public bool SameExists(Subsubcategory entity) => db.Subsubcategories.Any(x => (x.Title == entity.Title) && (x.SubcategoryId == entity.SubcategoryId)); - - /// - /// Checks entity subcategoryId existens. - /// - /// Subcategory id. - /// Bool. - public bool SubcategoryExists(long id) => db.Subcategories.Any(x => x.Id == id); - } -} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/WorkshopRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/WorkshopRepository.cs index ce41eb6ff1..997541f1f0 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/WorkshopRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/WorkshopRepository.cs @@ -44,6 +44,6 @@ public WorkshopRepository(OutOfSchoolDbContext dbContext) } /// - public bool SubsubcategoryExists(long id) => db.Subsubcategories.Any(x => x.Id == id); + public bool ClassExists(long id) => db.Classes.Any(x => x.Id == id); } } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.Designer.cs b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.Designer.cs new file mode 100644 index 0000000000..2d82afaaf6 --- /dev/null +++ b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.Designer.cs @@ -0,0 +1,1021 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OutOfSchool.Services; + +namespace OutOfSchool.IdentityServer.Data.Migrations.OutOfSchoolMigrations +{ + [DbContext(typeof(OutOfSchoolDbContext))] + [Migration("20210630091927_RenameCategories")] + partial class RenameCategories + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.2"); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("BuildingNumber") + .IsRequired() + .HasMaxLength(15) + .HasColumnType("nvarchar(15)"); + + b.Property("City") + .IsRequired() + .HasMaxLength(15) + .HasColumnType("nvarchar(15)"); + + b.Property("District") + .HasColumnType("nvarchar(max)"); + + b.Property("Latitude") + .HasColumnType("float"); + + b.Property("Longitude") + .HasColumnType("float"); + + b.Property("Region") + .HasColumnType("nvarchar(max)"); + + b.Property("Street") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.HasKey("Id"); + + b.ToTable("Addresses"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Application", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("ChildId") + .HasColumnType("bigint"); + + b.Property("CreationTime") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("WorkshopId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("ChildId"); + + b.HasIndex("UserId"); + + b.HasIndex("WorkshopId"); + + b.ToTable("Applications"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.BirthCertificate", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("SvidDate") + .HasColumnType("datetime2"); + + b.Property("SvidNum") + .HasColumnType("nvarchar(max)"); + + b.Property("SvidNumMD5") + .HasColumnType("nvarchar(max)"); + + b.Property("SvidSer") + .HasColumnType("nvarchar(max)"); + + b.Property("SvidWho") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("BirthCertificates"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("DateOfBirth") + .HasColumnType("datetime2"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Gender") + .HasColumnType("int"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("MiddleName") + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("SocialGroupId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex("SocialGroupId"); + + b.ToTable("Children"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Class", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("DepartmentId") + .HasColumnType("bigint"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.ToTable("Classes"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("DirectionId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("Id"); + + b.HasIndex("DirectionId"); + + b.ToTable("Departments"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Direction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("Id"); + + b.ToTable("Directions"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Parents"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Provider", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("ActualAddressId") + .HasColumnType("bigint"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Director") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("DirectorDateOfBirth") + .HasColumnType("datetime2"); + + b.Property("EdrpouIpn") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Facebook") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Founder") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FullTitle") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.Property("Instagram") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("LegalAddressId") + .HasColumnType("bigint"); + + b.Property("Ownership") + .HasColumnType("int"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("ShortTitle") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.Property("Status") + .HasColumnType("bit"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Website") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.HasIndex("ActualAddressId"); + + b.HasIndex("LegalAddressId"); + + b.HasIndex("UserId"); + + b.ToTable("Providers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("EntityId") + .HasColumnType("bigint"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Rate") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("Ratings"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SocialGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("SocialGroups"); + + b.HasData( + new + { + Id = 1L, + Name = "Діти із багатодітних сімей" + }, + new + { + Id = 2L, + Name = "Діти із малозабезпечених сімей" + }, + new + { + Id = 3L, + Name = "Діти з інвалідністю" + }, + new + { + Id = 4L, + Name = "Діти-сироти" + }, + new + { + Id = 5L, + Name = "Діти, позбавлені батьківського піклування" + }); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("DateOfBirth") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("Image") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("MiddleName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("WorkshopId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("WorkshopId"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatingTime") + .HasColumnType("datetime2"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsRegistered") + .HasColumnType("bit"); + + b.Property("LastLogin") + .HasColumnType("datetime2"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("Role") + .HasColumnType("nvarchar(max)"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Workshop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("AddressId") + .HasColumnType("bigint"); + + b.Property("ClassId") + .HasColumnType("bigint"); + + b.Property("DaysPerWeek") + .HasColumnType("int"); + + b.Property("DepartmentId") + .HasColumnType("bigint"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("DirectionId") + .HasColumnType("bigint"); + + b.Property("DisabilityOptionsDesc") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Facebook") + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("Head") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("HeadDateOfBirth") + .HasColumnType("datetime2"); + + b.Property("Instagram") + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("IsPerMonth") + .HasColumnType("bit"); + + b.Property("Logo") + .HasColumnType("nvarchar(max)"); + + b.Property("MaxAge") + .HasColumnType("int"); + + b.Property("MinAge") + .HasColumnType("int"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("ProviderId") + .HasColumnType("bigint"); + + b.Property("ProviderTitle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.Property("Website") + .HasColumnType("nvarchar(max)"); + + b.Property("WithDisabilityOptions") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.HasIndex("AddressId"); + + b.HasIndex("ClassId"); + + b.HasIndex("ProviderId"); + + b.ToTable("Workshops"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Application", b => + { + b.HasOne("OutOfSchool.Services.Models.Child", "Child") + .WithMany() + .HasForeignKey("ChildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany("Applications") + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Child"); + + b.Navigation("User"); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.BirthCertificate", b => + { + b.HasOne("OutOfSchool.Services.Models.Child", "Child") + .WithOne("BirthCertificate") + .HasForeignKey("OutOfSchool.Services.Models.BirthCertificate", "Id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Child"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + { + b.HasOne("OutOfSchool.Services.Models.Parent", "Parent") + .WithMany("Children") + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.SocialGroup", "SocialGroup") + .WithMany("Children") + .HasForeignKey("SocialGroupId"); + + b.Navigation("Parent"); + + b.Navigation("SocialGroup"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Class", b => + { + b.HasOne("OutOfSchool.Services.Models.Department", "Department") + .WithMany("Classes") + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.HasOne("OutOfSchool.Services.Models.Direction", "Direction") + .WithMany("Departments") + .HasForeignKey("DirectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Direction"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => + { + b.HasOne("OutOfSchool.Services.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Provider", b => + { + b.HasOne("OutOfSchool.Services.Models.Address", "ActualAddress") + .WithMany() + .HasForeignKey("ActualAddressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Address", "LegalAddress") + .WithMany() + .HasForeignKey("LegalAddressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ActualAddress"); + + b.Navigation("LegalAddress"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Rating", b => + { + b.HasOne("OutOfSchool.Services.Models.Parent", "Parent") + .WithMany() + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Teacher", b => + { + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany("Teachers") + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Workshop", b => + { + b.HasOne("OutOfSchool.Services.Models.Address", "Address") + .WithMany() + .HasForeignKey("AddressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Class", "Class") + .WithMany() + .HasForeignKey("ClassId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Provider", "Provider") + .WithMany("Workshops") + .HasForeignKey("ProviderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Address"); + + b.Navigation("Class"); + + b.Navigation("Provider"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + { + b.Navigation("BirthCertificate"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.Navigation("Classes"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Direction", b => + { + b.Navigation("Departments"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => + { + b.Navigation("Children"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Provider", b => + { + b.Navigation("Workshops"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SocialGroup", b => + { + b.Navigation("Children"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Workshop", b => + { + b.Navigation("Applications"); + + b.Navigation("Teachers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.cs b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.cs new file mode 100644 index 0000000000..2a62357f2a --- /dev/null +++ b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20210630091927_RenameCategories.cs @@ -0,0 +1,267 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace OutOfSchool.IdentityServer.Data.Migrations.OutOfSchoolMigrations +{ + public partial class RenameCategories : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Workshops_Subsubcategories_SubsubcategoryId", + table: "Workshops"); + + migrationBuilder.DropIndex( + name: "IX_Workshops_SubsubcategoryId", + table: "Workshops"); + + migrationBuilder.RenameColumn( + name: "SubsubcategoryId", + table: "Workshops", + newName: "ClassId"); + + migrationBuilder.RenameColumn( + name: "SubcategoryId", + table: "Workshops", + newName: "DepartmentId"); + + migrationBuilder.RenameColumn( + name: "CategoryId", + table: "Workshops", + newName: "DirectionId"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Subsubcategories", + table: "Subsubcategories"); + + migrationBuilder.DropForeignKey( + name: "FK_Subsubcategories_Subcategories_SubcategoryId", + table: "Subsubcategories"); + + migrationBuilder.DropIndex( + name: "IX_Subsubcategories_SubcategoryId", + table: "Subsubcategories"); + + migrationBuilder.RenameTable( + name: "Subsubcategories", + newName: "Classes"); + + migrationBuilder.RenameColumn( + name: "SubcategoryId", + table: "Classes", + newName: "DepartmentId"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Subcategories", + table: "Subcategories"); + + migrationBuilder.DropForeignKey( + name: "FK_Subcategories_Categories_CategoryId", + table: "Subcategories"); + + migrationBuilder.DropIndex( + name: "IX_Subcategories_CategoryId", + table: "Subcategories"); + + migrationBuilder.RenameTable( + name: "Subcategories", + newName: "Departments"); + + migrationBuilder.RenameColumn( + name: "CategoryId", + table: "Departments", + newName: "DirectionId"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Categories", + table: "Categories"); + + migrationBuilder.RenameTable( + name: "Categories", + newName: "Directions"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Directions", + table: "Directions", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Departments", + table: "Departments", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Classes", + table: "Classes", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Departments_Directions_DirectionId", + table: "Departments", + column: "DirectionId", + principalTable: "Directions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.CreateIndex( + name: "IX_Departments_DirectionId", + table: "Departments", + column: "DirectionId"); + + migrationBuilder.AddForeignKey( + name: "FK_Classes_Departments_DepartmentId", + table: "Classes", + column: "DepartmentId", + principalTable: "Departments", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.CreateIndex( + name: "IX_Classes_DepartmentId", + table: "Classes", + column: "DepartmentId"); + + migrationBuilder.AddForeignKey( + name: "FK_Workshops_Classes_ClassId", + table: "Workshops", + column: "ClassId", + principalTable: "Classes", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + + migrationBuilder.CreateIndex( + name: "IX_Workshops_ClassId", + table: "Workshops", + column: "ClassId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Workshops_Classes_ClassId", + table: "Workshops"); + + migrationBuilder.DropIndex( + name: "IX_Workshops_ClassId", + table: "Workshops"); + + migrationBuilder.RenameColumn( + name: "ClassId", + table: "Workshops", + newName: "SubsubcategoryId"); + + migrationBuilder.RenameColumn( + name: "DepartmentId", + table: "Workshops", + newName: "SubcategoryId"); + + migrationBuilder.RenameColumn( + name: "DirectionId", + table: "Workshops", + newName: "CategoryId"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Classes", + table: "Classes"); + + migrationBuilder.DropForeignKey( + name: "FK_Classes_Departments_DepartmentId", + table: "Classes"); + + migrationBuilder.DropIndex( + name: "IX_Classes_DepartmentId", + table: "Classes"); + + migrationBuilder.RenameTable( + name: "Classes", + newName: "Subsubcategories"); + + migrationBuilder.RenameColumn( + name: "DepartmentId", + table: "Subsubcategories", + newName: "SubcategoryId"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Departments", + table: "Departments"); + + migrationBuilder.DropForeignKey( + name: "FK_Departments_Directions_DirectionId", + table: "Departments"); + + migrationBuilder.DropIndex( + name: "IX_Departments_DirectionId", + table: "Departments"); + + migrationBuilder.RenameTable( + name: "Departments", + newName: "Subcategories"); + + migrationBuilder.RenameColumn( + name: "DirectionId", + table: "Subcategories", + newName: "CategoryId"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Directions", + table: "Directions"); + + migrationBuilder.RenameTable( + name: "Directions", + newName: "Categories"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Categories", + table: "Categories", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Subcategories", + table: "Subcategories", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Subsubcategories", + table: "Subsubcategories", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Subcategories_Categories_CategoryId", + table: "Subcategories", + column: "CategoryId", + principalTable: "Categories", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.CreateIndex( + name: "IX_Subcategories_CategoryId", + table: "Subcategories", + column: "CategoryId"); + + migrationBuilder.AddForeignKey( + name: "FK_Subsubcategories_Subcategories_SubcategoryId", + table: "Subsubcategories", + column: "SubcategoryId", + principalTable: "Subcategories", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.CreateIndex( + name: "IX_Subsubcategories_SubcategoryId", + table: "Subsubcategories", + column: "SubcategoryId"); + + migrationBuilder.AddForeignKey( + name: "FK_Workshops_Subsubcategories_SubsubcategoryId", + table: "Workshops", + column: "SubsubcategoryId", + principalTable: "Subsubcategories", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + + migrationBuilder.CreateIndex( + name: "IX_Workshops_SubsubcategoryId", + table: "Workshops", + column: "SubsubcategoryId"); + } + } +} diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs index 0b644e77d8..ae93f68551 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs @@ -247,27 +247,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("BirthCertificates"); }); - modelBuilder.Entity("OutOfSchool.Services.Models.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint") - .UseIdentityColumn(); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(60) - .HasColumnType("nvarchar(60)"); - - b.HasKey("Id"); - - b.ToTable("Categories"); - }); - modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => { b.Property("Id") @@ -310,6 +289,79 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Children"); }); + modelBuilder.Entity("OutOfSchool.Services.Models.Class", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("DepartmentId") + .HasColumnType("bigint"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.ToTable("Classes"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("DirectionId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("Id"); + + b.HasIndex("DirectionId"); + + b.ToTable("Departments"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Direction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("Id"); + + b.ToTable("Directions"); + }); + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => { b.Property("Id") @@ -482,58 +534,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) }); }); - modelBuilder.Entity("OutOfSchool.Services.Models.Subcategory", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint") - .UseIdentityColumn(); - - b.Property("CategoryId") - .HasColumnType("bigint"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(60) - .HasColumnType("nvarchar(60)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId"); - - b.ToTable("Subcategories"); - }); - - modelBuilder.Entity("OutOfSchool.Services.Models.Subsubcategory", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint") - .UseIdentityColumn(); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("SubcategoryId") - .HasColumnType("bigint"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(60) - .HasColumnType("nvarchar(60)"); - - b.HasKey("Id"); - - b.HasIndex("SubcategoryId"); - - b.ToTable("Subsubcategories"); - }); - modelBuilder.Entity("OutOfSchool.Services.Models.Teacher", b => { b.Property("Id") @@ -675,17 +675,23 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("AddressId") .HasColumnType("bigint"); - b.Property("CategoryId") + b.Property("ClassId") .HasColumnType("bigint"); b.Property("DaysPerWeek") .HasColumnType("int"); + b.Property("DepartmentId") + .HasColumnType("bigint"); + b.Property("Description") .IsRequired() .HasMaxLength(500) .HasColumnType("nvarchar(500)"); + b.Property("DirectionId") + .HasColumnType("bigint"); + b.Property("DisabilityOptionsDesc") .HasMaxLength(200) .HasColumnType("nvarchar(200)"); @@ -736,12 +742,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("SubcategoryId") - .HasColumnType("bigint"); - - b.Property("SubsubcategoryId") - .HasColumnType("bigint"); - b.Property("Title") .IsRequired() .HasMaxLength(60) @@ -757,9 +757,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("AddressId"); - b.HasIndex("ProviderId"); + b.HasIndex("ClassId"); - b.HasIndex("SubsubcategoryId"); + b.HasIndex("ProviderId"); b.ToTable("Workshops"); }); @@ -828,7 +828,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasForeignKey("UserId"); b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") - .WithMany() + .WithMany("Applications") .HasForeignKey("WorkshopId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -868,6 +868,28 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("SocialGroup"); }); + modelBuilder.Entity("OutOfSchool.Services.Models.Class", b => + { + b.HasOne("OutOfSchool.Services.Models.Department", "Department") + .WithMany("Classes") + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.HasOne("OutOfSchool.Services.Models.Direction", "Direction") + .WithMany("Departments") + .HasForeignKey("DirectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Direction"); + }); + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => { b.HasOne("OutOfSchool.Services.Models.User", "User") @@ -917,28 +939,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Parent"); }); - modelBuilder.Entity("OutOfSchool.Services.Models.Subcategory", b => - { - b.HasOne("OutOfSchool.Services.Models.Category", "Category") - .WithMany("Subcategories") - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - }); - - modelBuilder.Entity("OutOfSchool.Services.Models.Subsubcategory", b => - { - b.HasOne("OutOfSchool.Services.Models.Subcategory", "Subcategory") - .WithMany("Subsubcategories") - .HasForeignKey("SubcategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Subcategory"); - }); - modelBuilder.Entity("OutOfSchool.Services.Models.Teacher", b => { b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") @@ -958,33 +958,38 @@ protected override void BuildModel(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("OutOfSchool.Services.Models.Provider", "Provider") - .WithMany("Workshops") - .HasForeignKey("ProviderId") + b.HasOne("OutOfSchool.Services.Models.Class", "Class") + .WithMany() + .HasForeignKey("ClassId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("OutOfSchool.Services.Models.Subsubcategory", "Subsubcategory") - .WithMany() - .HasForeignKey("SubsubcategoryId") + b.HasOne("OutOfSchool.Services.Models.Provider", "Provider") + .WithMany("Workshops") + .HasForeignKey("ProviderId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Address"); + b.Navigation("Class"); + b.Navigation("Provider"); + }); - b.Navigation("Subsubcategory"); + modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + { + b.Navigation("BirthCertificate"); }); - modelBuilder.Entity("OutOfSchool.Services.Models.Category", b => + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => { - b.Navigation("Subcategories"); + b.Navigation("Classes"); }); - modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + modelBuilder.Entity("OutOfSchool.Services.Models.Direction", b => { - b.Navigation("BirthCertificate"); + b.Navigation("Departments"); }); modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => @@ -1002,13 +1007,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Children"); }); - modelBuilder.Entity("OutOfSchool.Services.Models.Subcategory", b => - { - b.Navigation("Subsubcategories"); - }); - modelBuilder.Entity("OutOfSchool.Services.Models.Workshop", b => { + b.Navigation("Applications"); + b.Navigation("Teachers"); }); #pragma warning restore 612, 618 diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/SubcategoryControllerTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/ClassControllerTests.cs similarity index 57% rename from OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/SubcategoryControllerTests.cs rename to OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/ClassControllerTests.cs index 20e22011d4..578375ad3e 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/SubcategoryControllerTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/ClassControllerTests.cs @@ -17,35 +17,35 @@ namespace OutOfSchool.WebApi.Tests.Controllers { [TestFixture] - public class SubcategoryControllerTests + public class ClassControllerTests { - private SubcategoryController controller; - private Mock service; + private ClassController controller; + private Mock service; private ClaimsPrincipal user; private Mock> localizer; - private IEnumerable categories; - private SubcategoryDTO category; + private IEnumerable classes; + private ClassDto classEntity; [SetUp] public void Setup() { - service = new Mock(); + service = new Mock(); localizer = new Mock>(); - controller = new SubcategoryController(service.Object, localizer.Object); + controller = new ClassController(service.Object, localizer.Object); user = new ClaimsPrincipal(new ClaimsIdentity()); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = user }; - categories = FakeSubcategories(); - category = FakeSubcategory(); + classes = FakeClasses(); + classEntity = FakeClass(); } [Test] - public async Task GetSubcategories_WhenCalled_ReturnsOkResultObject() + public async Task Get_WhenCalled_ReturnsOkResultObject() { // Arrange - service.Setup(x => x.GetAll()).ReturnsAsync(categories); + service.Setup(x => x.GetAll()).ReturnsAsync(classes); // Act var result = await controller.Get().ConfigureAwait(false) as OkObjectResult; @@ -57,10 +57,10 @@ public async Task GetSubcategories_WhenCalled_ReturnsOkResultObject() [Test] [TestCase(1)] - public async Task GetSubcategoriesById_WhenIdIsValid_ReturnsOkObjectResult(long id) + public async Task GetById_WhenIdIsValid_ReturnsOkObjectResult(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(classes.SingleOrDefault(x => x.Id == id)); // Act var result = await controller.GetById(id).ConfigureAwait(false) as OkObjectResult; @@ -72,10 +72,10 @@ public async Task GetSubcategoriesById_WhenIdIsValid_ReturnsOkObjectResult(long [Test] [TestCase(-1)] - public void GetSubcategoriesById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) + public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(classes.SingleOrDefault(x => x.Id == id)); // Act and Assert Assert.ThrowsAsync( @@ -84,10 +84,10 @@ public void GetSubcategoriesById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeExcepti [Test] [TestCase(10)] - public async Task GetSubcategoriesById_WhenIdIsInvalid_ReturnsNull(long id) + public async Task GetById_WhenIdIsInvalid_ReturnsNull(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(classes.SingleOrDefault(x => x.Id == id)); // Act var result = await controller.GetById(id).ConfigureAwait(false) as OkObjectResult; @@ -98,13 +98,13 @@ public async Task GetSubcategoriesById_WhenIdIsInvalid_ReturnsNull(long id) } [Test] - public async Task CreateSubcategory_WhenModelIsValid_ReturnsCreatedAtActionResult() + public async Task Create_WhenModelIsValid_ReturnsCreatedAtActionResult() { // Arrange - service.Setup(x => x.Create(category)).ReturnsAsync(category); + service.Setup(x => x.Create(classEntity)).ReturnsAsync(classEntity); // Act - var result = await controller.Create(category).ConfigureAwait(false) as CreatedAtActionResult; + var result = await controller.Create(classEntity).ConfigureAwait(false) as CreatedAtActionResult; // Assert Assert.That(result, Is.Not.Null); @@ -112,13 +112,13 @@ public async Task CreateSubcategory_WhenModelIsValid_ReturnsCreatedAtActionResul } [Test] - public async Task CreateSubcategory_WhenModelIsInvalid_ReturnsBadRequestObjectResult() + public async Task Create_WhenModelIsInvalid_ReturnsBadRequestObjectResult() { // Arrange - controller.ModelState.AddModelError("CreateCategory", "Invalid model state."); + controller.ModelState.AddModelError("CreateClass", "Invalid model state."); // Act - var result = await controller.Create(category).ConfigureAwait(false); + var result = await controller.Create(classEntity).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); @@ -126,19 +126,19 @@ public async Task CreateSubcategory_WhenModelIsInvalid_ReturnsBadRequestObjectRe } [Test] - public async Task UpdateSubcategory_WhenModelIsValid_ReturnsOkObjectResult() + public async Task Update_WhenModelIsValid_ReturnsOkObjectResult() { // Arrange - var changedSubcategory = new SubcategoryDTO() + var changedClass = new ClassDto() { Id = 1, Title = "ChangedTitle", - CategoryId = 1, + DepartmentId = 1, }; - service.Setup(x => x.Update(changedSubcategory)).ReturnsAsync(changedSubcategory); + service.Setup(x => x.Update(changedClass)).ReturnsAsync(changedClass); // Act - var result = await controller.Update(changedSubcategory).ConfigureAwait(false) as OkObjectResult; + var result = await controller.Update(changedClass).ConfigureAwait(false) as OkObjectResult; // Assert Assert.That(result, Is.Not.Null); @@ -146,13 +146,13 @@ public async Task UpdateSubcategory_WhenModelIsValid_ReturnsOkObjectResult() } [Test] - public async Task UpdateSubcategory_WhenModelIsInvalid_ReturnsBadRequestObjectResult() + public async Task Update_WhenModelIsInvalid_ReturnsBadRequestObjectResult() { // Arrange - controller.ModelState.AddModelError("UpdateCategory", "Invalid model state."); + controller.ModelState.AddModelError("UpdateClass", "Invalid model state."); // Act - var result = await controller.Update(category).ConfigureAwait(false); + var result = await controller.Update(classEntity).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); @@ -161,7 +161,7 @@ public async Task UpdateSubcategory_WhenModelIsInvalid_ReturnsBadRequestObjectRe [Test] [TestCase(1)] - public async Task DeleteSubcategory_WhenIdIsValid_ReturnsNoContentResult(long id) + public async Task Delete_WhenIdIsValid_ReturnsNoContentResult(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -176,7 +176,7 @@ public async Task DeleteSubcategory_WhenIdIsValid_ReturnsNoContentResult(long id [Test] [TestCase(0)] - public void DeleteSubcategory_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long id) + public void Delete_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -188,7 +188,7 @@ public void DeleteSubcategory_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long [Test] [TestCase(10)] - public async Task DeleteSubcategory_WhenIdIsInvalid_ReturnsNull(long id) + public async Task Delete_WhenIdIsInvalid_ReturnsNull(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -202,13 +202,13 @@ public async Task DeleteSubcategory_WhenIdIsInvalid_ReturnsNull(long id) [Test] [TestCase(3)] - public async Task GetByCategoryId_WhenIdIsInvalid_ReturnsNoContent(long id) + public async Task GetByDepartmentId_WhenIdIsInvalid_ReturnsNoContent(long id) { // Arrange - service.Setup(x => x.GetByCategoryId(id)).ReturnsAsync(categories.Where(x => x.CategoryId == id)); + service.Setup(x => x.GetByDepartmentId(id)).ReturnsAsync(classes.Where(x => x.DepartmentId == id)); // Act - var result = await controller.GetByCategoryId(id).ConfigureAwait(false) as OkObjectResult; + var result = await controller.GetByDepartmentId(id).ConfigureAwait(false) as OkObjectResult; // Assert Assert.That(result, Is.Null); @@ -216,13 +216,13 @@ public async Task GetByCategoryId_WhenIdIsInvalid_ReturnsNoContent(long id) [Test] [TestCase(1)] - public async Task GetByCategoryId_WhenIdIsValid_ReturnsOkObject(long id) + public async Task GetByDepartmentId_WhenIdIsValid_ReturnsOkObject(long id) { // Arrange - service.Setup(x => x.GetByCategoryId(id)).ReturnsAsync(categories.Where(x => x.CategoryId == id)); + service.Setup(x => x.GetByDepartmentId(id)).ReturnsAsync(classes.Where(x => x.DepartmentId == id)); // Act - var result = await controller.GetByCategoryId(id).ConfigureAwait(false) as OkObjectResult; + var result = await controller.GetByDepartmentId(id).ConfigureAwait(false) as OkObjectResult; // Assert Assert.That(result, Is.Not.Null); @@ -231,50 +231,50 @@ public async Task GetByCategoryId_WhenIdIsValid_ReturnsOkObject(long id) [Test] [TestCase(10)] - public async Task GetByCategoryId_WhenIdIsInvalid_ReturnsBadRequest(long id) + public async Task GetByDepartmentId_WhenIdIsInvalid_ReturnsBadRequest(long id) { // Arrange - service.Setup(x => x.GetByCategoryId(id)).ThrowsAsync(new ArgumentException("message")); + service.Setup(x => x.GetByDepartmentId(id)).ThrowsAsync(new ArgumentException("message")); // Act - var result = await controller.GetByCategoryId(id).ConfigureAwait(false); + var result = await controller.GetByDepartmentId(id).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); Assert.That((result as BadRequestObjectResult).StatusCode, Is.EqualTo(400)); } - private SubcategoryDTO FakeSubcategory() + private ClassDto FakeClass() { - return new SubcategoryDTO() + return new ClassDto() { Title = "Test1", Description = "Test1", - CategoryId = 1, + DepartmentId = 1, }; } - private IEnumerable FakeSubcategories() + private IEnumerable FakeClasses() { - return new List() + return new List() { - new SubcategoryDTO() + new ClassDto() { Title = "Test1", Description = "Test1", - CategoryId = 1, + DepartmentId = 1, }, - new SubcategoryDTO + new ClassDto { Title = "Test2", Description = "Test2", - CategoryId = 1, + DepartmentId = 1, }, - new SubcategoryDTO + new ClassDto { Title = "Test3", Description = "Test3", - CategoryId = 1, + DepartmentId = 1, }, }; } diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/SubsubcategoryControllerTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/DepartmentControllerTests.cs similarity index 56% rename from OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/SubsubcategoryControllerTests.cs rename to OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/DepartmentControllerTests.cs index a8780a1d55..1d508519a7 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/SubsubcategoryControllerTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/DepartmentControllerTests.cs @@ -17,35 +17,35 @@ namespace OutOfSchool.WebApi.Tests.Controllers { [TestFixture] - public class SubsubcategoryControllerTests + public class DepartmentControllerTests { - private SubsubcategoryController controller; - private Mock service; + private DepartmentController controller; + private Mock service; private ClaimsPrincipal user; private Mock> localizer; - private IEnumerable categories; - private SubsubcategoryDTO category; + private IEnumerable departments; + private DepartmentDto department; [SetUp] public void Setup() { - service = new Mock(); + service = new Mock(); localizer = new Mock>(); - controller = new SubsubcategoryController(service.Object, localizer.Object); + controller = new DepartmentController(service.Object, localizer.Object); user = new ClaimsPrincipal(new ClaimsIdentity()); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = user }; - categories = FakeSubsubcategories(); - category = FakeSubsubcategory(); + departments = FakeDepartments(); + department = FakeDepartment(); } [Test] - public async Task GetSubsubcategories_WhenCalled_ReturnsOkResultObject() + public async Task Get_WhenCalled_ReturnsOkResultObject() { // Arrange - service.Setup(x => x.GetAll()).ReturnsAsync(categories); + service.Setup(x => x.GetAll()).ReturnsAsync(departments); // Act var result = await controller.Get().ConfigureAwait(false) as OkObjectResult; @@ -57,10 +57,10 @@ public async Task GetSubsubcategories_WhenCalled_ReturnsOkResultObject() [Test] [TestCase(1)] - public async Task GetSubsubcategoriesById_WhenIdIsValid_ReturnsOkObjectResult(long id) + public async Task GetById_WhenIdIsValid_ReturnsOkObjectResult(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(departments.SingleOrDefault(x => x.Id == id)); // Act var result = await controller.GetById(id).ConfigureAwait(false) as OkObjectResult; @@ -72,10 +72,10 @@ public async Task GetSubsubcategoriesById_WhenIdIsValid_ReturnsOkObjectResult(lo [Test] [TestCase(-1)] - public void GetSubsubcategoriesById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) + public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(departments.SingleOrDefault(x => x.Id == id)); // Act and Assert Assert.ThrowsAsync( @@ -84,10 +84,10 @@ public void GetSubsubcategoriesById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeExce [Test] [TestCase(10)] - public async Task GetSubsubcategoriesById_WhenIdIsInvalid_ReturnsNull(long id) + public async Task GetById_WhenIdIsInvalid_ReturnsNull(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(departments.SingleOrDefault(x => x.Id == id)); // Act var result = await controller.GetById(id).ConfigureAwait(false) as OkObjectResult; @@ -98,13 +98,13 @@ public async Task GetSubsubcategoriesById_WhenIdIsInvalid_ReturnsNull(long id) } [Test] - public async Task CreateSubsubcategory_WhenModelIsValid_ReturnsCreatedAtActionResult() + public async Task Create_WhenModelIsValid_ReturnsCreatedAtActionResult() { // Arrange - service.Setup(x => x.Create(category)).ReturnsAsync(category); + service.Setup(x => x.Create(department)).ReturnsAsync(department); // Act - var result = await controller.Create(category).ConfigureAwait(false) as CreatedAtActionResult; + var result = await controller.Create(department).ConfigureAwait(false) as CreatedAtActionResult; // Assert Assert.That(result, Is.Not.Null); @@ -112,13 +112,13 @@ public async Task CreateSubsubcategory_WhenModelIsValid_ReturnsCreatedAtActionRe } [Test] - public async Task CreateSubsubcategory_WhenModelIsInvalid_ReturnsBadRequestObjectResult() + public async Task Create_WhenModelIsInvalid_ReturnsBadRequestObjectResult() { // Arrange - controller.ModelState.AddModelError("CreateCategory", "Invalid model state."); + controller.ModelState.AddModelError("CreateDepartment", "Invalid model state."); // Act - var result = await controller.Create(category).ConfigureAwait(false); + var result = await controller.Create(department).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); @@ -126,19 +126,19 @@ public async Task CreateSubsubcategory_WhenModelIsInvalid_ReturnsBadRequestObjec } [Test] - public async Task UpdateSubsubcategory_WhenModelIsValid_ReturnsOkObjectResult() + public async Task Update_WhenModelIsValid_ReturnsOkObjectResult() { // Arrange - var changedSubsubcategory = new SubsubcategoryDTO() + var changedDepartment = new DepartmentDto() { Id = 1, Title = "ChangedTitle", - SubcategoryId = 1, + DirectionId = 1, }; - service.Setup(x => x.Update(changedSubsubcategory)).ReturnsAsync(changedSubsubcategory); + service.Setup(x => x.Update(changedDepartment)).ReturnsAsync(changedDepartment); // Act - var result = await controller.Update(changedSubsubcategory).ConfigureAwait(false) as OkObjectResult; + var result = await controller.Update(changedDepartment).ConfigureAwait(false) as OkObjectResult; // Assert Assert.That(result, Is.Not.Null); @@ -146,13 +146,13 @@ public async Task UpdateSubsubcategory_WhenModelIsValid_ReturnsOkObjectResult() } [Test] - public async Task UpdateSubsubcategory_WhenModelIsInvalid_ReturnsBadRequestObjectResult() + public async Task Update_WhenModelIsInvalid_ReturnsBadRequestObjectResult() { // Arrange - controller.ModelState.AddModelError("UpdateCategory", "Invalid model state."); + controller.ModelState.AddModelError("UpdateDepartment", "Invalid model state."); // Act - var result = await controller.Update(category).ConfigureAwait(false); + var result = await controller.Update(department).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); @@ -161,7 +161,7 @@ public async Task UpdateSubsubcategory_WhenModelIsInvalid_ReturnsBadRequestObjec [Test] [TestCase(1)] - public async Task DeleteSubsubcategory_WhenIdIsValid_ReturnsNoContentResult(long id) + public async Task Delete_WhenIdIsValid_ReturnsNoContentResult(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -176,7 +176,7 @@ public async Task DeleteSubsubcategory_WhenIdIsValid_ReturnsNoContentResult(long [Test] [TestCase(0)] - public void DeleteSubsubcategory_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long id) + public void Delete_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -188,7 +188,7 @@ public void DeleteSubsubcategory_WhenIdIsInvalid_ReturnsBadRequestObjectResult(l [Test] [TestCase(10)] - public async Task DeleteSubsubcategory_WhenIdIsInvalid_ReturnsNull(long id) + public async Task Delete_WhenIdIsInvalid_ReturnsNull(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -202,13 +202,13 @@ public async Task DeleteSubsubcategory_WhenIdIsInvalid_ReturnsNull(long id) [Test] [TestCase(3)] - public async Task GetByCategoryId_WhenIdIsInvalid_ReturnsNoContent(long id) + public async Task GetByDirectionId_WhenIdIsInvalid_ReturnsNoContent(long id) { // Arrange - service.Setup(x => x.GetBySubcategoryId(id)).ReturnsAsync(categories.Where(x => x.SubcategoryId == id)); + service.Setup(x => x.GetByDirectionId(id)).ReturnsAsync(departments.Where(x => x.DirectionId == id)); // Act - var result = await controller.GetBySubcategoryId(id).ConfigureAwait(false) as OkObjectResult; + var result = await controller.GetByDirectionId(id).ConfigureAwait(false) as OkObjectResult; // Assert Assert.That(result, Is.Null); @@ -216,13 +216,13 @@ public async Task GetByCategoryId_WhenIdIsInvalid_ReturnsNoContent(long id) [Test] [TestCase(1)] - public async Task GetByCategoryId_WhenIdIsValid_ReturnsOkObject(long id) + public async Task GetByDirectionId_WhenIdIsValid_ReturnsOkObject(long id) { // Arrange - service.Setup(x => x.GetBySubcategoryId(id)).ReturnsAsync(categories.Where(x => x.SubcategoryId == id)); + service.Setup(x => x.GetByDirectionId(id)).ReturnsAsync(departments.Where(x => x.DirectionId == id)); // Act - var result = await controller.GetBySubcategoryId(id).ConfigureAwait(false) as OkObjectResult; + var result = await controller.GetByDirectionId(id).ConfigureAwait(false) as OkObjectResult; // Assert Assert.That(result, Is.Not.Null); @@ -231,50 +231,50 @@ public async Task GetByCategoryId_WhenIdIsValid_ReturnsOkObject(long id) [Test] [TestCase(10)] - public async Task GetByCategoryId_WhenIdIsInvalid_ReturnsBadRequest(long id) + public async Task GetByDirectionId_WhenIdIsInvalid_ReturnsBadRequest(long id) { // Arrange - service.Setup(x => x.GetBySubcategoryId(id)).ThrowsAsync(new ArgumentException("message")); + service.Setup(x => x.GetByDirectionId(id)).ThrowsAsync(new ArgumentException("message")); // Act - var result = await controller.GetBySubcategoryId(id).ConfigureAwait(false); + var result = await controller.GetByDirectionId(id).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); Assert.That((result as BadRequestObjectResult).StatusCode, Is.EqualTo(400)); } - private SubsubcategoryDTO FakeSubsubcategory() + private DepartmentDto FakeDepartment() { - return new SubsubcategoryDTO() + return new DepartmentDto() { Title = "Test1", Description = "Test1", - SubcategoryId = 1, + DirectionId = 1, }; } - private IEnumerable FakeSubsubcategories() + private IEnumerable FakeDepartments() { - return new List() + return new List() { - new SubsubcategoryDTO() + new DepartmentDto() { Title = "Test1", Description = "Test1", - SubcategoryId = 1, + DirectionId = 1, }, - new SubsubcategoryDTO + new DepartmentDto { Title = "Test2", Description = "Test2", - SubcategoryId = 1, + DirectionId = 1, }, - new SubsubcategoryDTO + new DepartmentDto { Title = "Test3", Description = "Test3", - SubcategoryId = 1, + DirectionId = 1, }, }; } diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/CategoryControllerTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/DirectionControllerTests.cs similarity index 61% rename from OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/CategoryControllerTests.cs rename to OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/DirectionControllerTests.cs index 4c11f4fb8d..bccdca7802 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/CategoryControllerTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/DirectionControllerTests.cs @@ -17,35 +17,35 @@ namespace OutOfSchool.WebApi.Tests.Controllers { [TestFixture] - public class CategoryControllerTests + public class DirectionControllerTests { - private CategoryController controller; - private Mock service; + private DirectionController controller; + private Mock service; private ClaimsPrincipal user; private Mock> localizer; - private IEnumerable categories; - private CategoryDTO category; + private IEnumerable directions; + private DirectionDto direction; [SetUp] public void Setup() { - service = new Mock(); + service = new Mock(); localizer = new Mock>(); - controller = new CategoryController(service.Object, localizer.Object); + controller = new DirectionController(service.Object, localizer.Object); user = new ClaimsPrincipal(new ClaimsIdentity()); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = user }; - categories = FakeCategories(); - category = FakeCategory(); + directions = FakeDirections(); + direction = FakeDirection(); } [Test] - public async Task GetCategories_WhenCalled_ReturnsOkResultObject() + public async Task Get_WhenCalled_ReturnsOkResultObject() { // Arrange - service.Setup(x => x.GetAll()).ReturnsAsync(categories); + service.Setup(x => x.GetAll()).ReturnsAsync(directions); // Act var result = await controller.Get().ConfigureAwait(false) as OkObjectResult; @@ -57,10 +57,10 @@ public async Task GetCategories_WhenCalled_ReturnsOkResultObject() [Test] [TestCase(1)] - public async Task GetCategoriesById_WhenIdIsValid_ReturnsOkObjectResult(long id) + public async Task GetById_WhenIdIsValid_ReturnsOkObjectResult(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(directions.SingleOrDefault(x => x.Id == id)); // Act var result = await controller.GetById(id).ConfigureAwait(false) as OkObjectResult; @@ -72,10 +72,10 @@ public async Task GetCategoriesById_WhenIdIsValid_ReturnsOkObjectResult(long id) [Test] [TestCase(-1)] - public void GetCategoriesById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) + public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(directions.SingleOrDefault(x => x.Id == id)); // Act and Assert Assert.ThrowsAsync( @@ -84,10 +84,10 @@ public void GetCategoriesById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException( [Test] [TestCase(10)] - public async Task GetCategoriesById_WhenIdIsInvalid_ReturnsNull(long id) + public async Task GetById_WhenIdIsInvalid_ReturnsNull(long id) { // Arrange - service.Setup(x => x.GetById(id)).ReturnsAsync(categories.SingleOrDefault(x => x.Id == id)); + service.Setup(x => x.GetById(id)).ReturnsAsync(directions.SingleOrDefault(x => x.Id == id)); // Act var result = await controller.GetById(id).ConfigureAwait(false) as OkObjectResult; @@ -98,13 +98,13 @@ public async Task GetCategoriesById_WhenIdIsInvalid_ReturnsNull(long id) } [Test] - public async Task CreateCategory_WhenModelIsValid_ReturnsCreatedAtActionResult() + public async Task Create_WhenModelIsValid_ReturnsCreatedAtActionResult() { // Arrange - service.Setup(x => x.Create(category)).ReturnsAsync(category); + service.Setup(x => x.Create(direction)).ReturnsAsync(direction); // Act - var result = await controller.Create(category).ConfigureAwait(false) as CreatedAtActionResult; + var result = await controller.Create(direction).ConfigureAwait(false) as CreatedAtActionResult; // Assert Assert.That(result, Is.Not.Null); @@ -112,13 +112,13 @@ public async Task CreateCategory_WhenModelIsValid_ReturnsCreatedAtActionResult() } [Test] - public async Task CreateCategory_WhenModelIsInvalid_ReturnsBadRequestObjectResult() + public async Task Create_WhenModelIsInvalid_ReturnsBadRequestObjectResult() { // Arrange - controller.ModelState.AddModelError("CreateCategory", "Invalid model state."); + controller.ModelState.AddModelError("CreateDirection", "Invalid model state."); // Act - var result = await controller.Create(category).ConfigureAwait(false); + var result = await controller.Create(direction).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); @@ -126,18 +126,18 @@ public async Task CreateCategory_WhenModelIsInvalid_ReturnsBadRequestObjectResul } [Test] - public async Task UpdateCategory_WhenModelIsValid_ReturnsOkObjectResult() + public async Task Update_WhenModelIsValid_ReturnsOkObjectResult() { // Arrange - var changedCategory = new CategoryDTO() + var changedDirection = new DirectionDto() { Id = 1, Title = "ChangedTitle", }; - service.Setup(x => x.Update(changedCategory)).ReturnsAsync(changedCategory); + service.Setup(x => x.Update(changedDirection)).ReturnsAsync(changedDirection); // Act - var result = await controller.Update(changedCategory).ConfigureAwait(false) as OkObjectResult; + var result = await controller.Update(changedDirection).ConfigureAwait(false) as OkObjectResult; // Assert Assert.That(result, Is.Not.Null); @@ -145,13 +145,13 @@ public async Task UpdateCategory_WhenModelIsValid_ReturnsOkObjectResult() } [Test] - public async Task UpdateCategory_WhenModelIsInvalid_ReturnsBadRequestObjectResult() + public async Task Update_WhenModelIsInvalid_ReturnsBadRequestObjectResult() { // Arrange - controller.ModelState.AddModelError("UpdateCategory", "Invalid model state."); + controller.ModelState.AddModelError("UpdateDirection", "Invalid model state."); // Act - var result = await controller.Update(category).ConfigureAwait(false); + var result = await controller.Update(direction).ConfigureAwait(false); // Assert Assert.That(result, Is.TypeOf()); @@ -160,7 +160,7 @@ public async Task UpdateCategory_WhenModelIsInvalid_ReturnsBadRequestObjectResul [Test] [TestCase(1)] - public async Task DeleteCategory_WhenIdIsValid_ReturnsNoContentResult(long id) + public async Task Delete_WhenIdIsValid_ReturnsNoContentResult(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -175,7 +175,7 @@ public async Task DeleteCategory_WhenIdIsValid_ReturnsNoContentResult(long id) [Test] [TestCase(0)] - public void DeleteCategory_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long id) + public void Delete_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -187,7 +187,7 @@ public void DeleteCategory_WhenIdIsInvalid_ReturnsBadRequestObjectResult(long id [Test] [TestCase(10)] - public async Task DeleteCategory_WhenIdIsInvalid_ReturnsNull(long id) + public async Task Delete_WhenIdIsInvalid_ReturnsNull(long id) { // Arrange service.Setup(x => x.Delete(id)); @@ -199,30 +199,30 @@ public async Task DeleteCategory_WhenIdIsInvalid_ReturnsNull(long id) Assert.That(result, Is.Null); } - private CategoryDTO FakeCategory() + private DirectionDto FakeDirection() { - return new CategoryDTO() + return new DirectionDto() { Title = "Test1", Description = "Test1", }; } - private IEnumerable FakeCategories() + private IEnumerable FakeDirections() { - return new List() + return new List() { - new CategoryDTO() + new DirectionDto() { Title = "Test1", Description = "Test1", }, - new CategoryDTO + new DirectionDto { Title = "Test2", Description = "Test2", }, - new CategoryDTO + new DirectionDto { Title = "Test3", Description = "Test3", diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/WorkshopControllerTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/WorkshopControllerTests.cs index 7594bbbf30..c48d49ea62 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/WorkshopControllerTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/WorkshopControllerTests.cs @@ -365,8 +365,9 @@ private WorkshopDTO FakeWorkshop() MinAge = 4, Logo = "image6", ProviderId = 1, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, + ClassId = 1, AddressId = 55, Address = new AddressDto { @@ -432,6 +433,9 @@ private IEnumerable FakeWorkshops() MaxAge = 10, MinAge = 4, Logo = "image1", + DirectionId = 1, + DepartmentId = 1, + ClassId = 1, }, new WorkshopDTO() { @@ -454,6 +458,9 @@ private IEnumerable FakeWorkshops() MaxAge = 10, MinAge = 4, Logo = "image2", + DirectionId = 1, + DepartmentId = 1, + ClassId = 1, }, new WorkshopDTO() { @@ -476,6 +483,9 @@ private IEnumerable FakeWorkshops() MaxAge = 10, MinAge = 4, Logo = "image3", + DirectionId = 1, + DepartmentId = 1, + ClassId = 1, }, new WorkshopDTO() { @@ -498,6 +508,9 @@ private IEnumerable FakeWorkshops() MaxAge = 10, MinAge = 4, Logo = "image4", + DirectionId = 1, + DepartmentId = 1, + ClassId = 1, }, new WorkshopDTO() { @@ -520,6 +533,9 @@ private IEnumerable FakeWorkshops() MaxAge = 10, MinAge = 4, Logo = "image5", + DirectionId = 1, + DepartmentId = 1, + ClassId = 1, }, }; } diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SubsubcategoryServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ClassServiceTests.cs similarity index 78% rename from OutOfSchool/OutOfSchool.WebApi.Tests/Services/SubsubcategoryServiceTests.cs rename to OutOfSchool/OutOfSchool.WebApi.Tests/Services/ClassServiceTests.cs index 86683cfa16..7a35ccf5e6 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SubsubcategoryServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ClassServiceTests.cs @@ -18,12 +18,12 @@ namespace OutOfSchool.WebApi.Tests.Services { [TestFixture] - public class SubsubcategoryServiceTests + public class ClassServiceTests { private DbContextOptions options; private OutOfSchoolDbContext context; - private ISubsubcategoryRepository repo; - private ISubsubcategoryService service; + private IClassRepository repo; + private IClassService service; private Mock> localizer; private Mock logger; @@ -37,10 +37,10 @@ public void SetUp() options = builder.Options; context = new OutOfSchoolDbContext(options); - repo = new SubsubcategoryRepository(context); + repo = new ClassRepository(context); localizer = new Mock>(); logger = new Mock(); - service = new SubsubcategoryService(repo, logger.Object, localizer.Object); + service = new ClassService(repo, logger.Object, localizer.Object); SeedDatabase(); } @@ -50,11 +50,11 @@ public void SetUp() public async Task Create_WhenEntityIsValid_ReturnsCreatedEntity() { // Arrange - var expected = new Subsubcategory() + var expected = new Class() { Title = "NewTitle", Description = "NewDescription", - SubcategoryId = 1, + DepartmentId = 1, }; // Act @@ -121,12 +121,12 @@ public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() { // Arrange - var changedEntity = new SubsubcategoryDTO() + var changedEntity = new ClassDto() { Id = 1, Title = "ChangedTitle1", Description = "Bla-bla", - SubcategoryId = 1, + DepartmentId = 1, }; // Act @@ -141,10 +141,10 @@ public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() public void Update_WhenEntityIsInvalid_ThrowsDbUpdateConcurrencyException() { // Arrange - var changedEntity = new SubsubcategoryDTO() + var changedEntity = new ClassDto() { Title = "NewTitle1", - SubcategoryId = 1, + DepartmentId = 1, }; // Act and Assert @@ -160,7 +160,7 @@ public async Task Delete_WhenIdIsValid_DeletesEntity(long id) // Act var countBeforeDeleting = (await service.GetAll().ConfigureAwait(false)).Count(); - context.Entry(await repo.GetById(id).ConfigureAwait(false)).State = EntityState.Detached; + context.Entry(await repo.GetById(id).ConfigureAwait(false)).State = EntityState.Detached; await service.Delete(id).ConfigureAwait(false); @@ -183,14 +183,14 @@ public void Delete_WhenIdIsInvalid_ThrowsDbUpdateConcurrencyException(long id) [Test] [Order(10)] [TestCase(1)] - public async Task GetBySubcategoryId_WhenIdIsValid_ReturnsEntities(long id) + public async Task GetByDepartmentId_WhenIdIsValid_ReturnsEntities(long id) { // Arrange var expected = await repo.GetAll().ConfigureAwait(false); - expected = expected.Where(x => x.SubcategoryId == id); + expected = expected.Where(x => x.DepartmentId == id); // Act - var entities = await service.GetBySubcategoryId(id); + var entities = await service.GetByDepartmentId(id); // Assert Assert.That(entities.Count(), Is.EqualTo(expected.Count())); @@ -199,11 +199,11 @@ public async Task GetBySubcategoryId_WhenIdIsValid_ReturnsEntities(long id) [Test] [Order(11)] [TestCase(10)] - public void GetBySubcategoryId_WhenIdIsInvalid_ThrowsArgumentException(long id) + public void GetByDepartmentId_WhenIdIsInvalid_ThrowsArgumentException(long id) { // Act and Assert Assert.ThrowsAsync( - async () => await service.GetBySubcategoryId(id).ConfigureAwait(false)); + async () => await service.GetByDepartmentId(id).ConfigureAwait(false)); } private void SeedDatabase() @@ -213,53 +213,53 @@ private void SeedDatabase() ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); - var subcategories = new List() + var departments = new List() { - new Subcategory() + new Department() { Title = "Test1", Description = "Test1", - CategoryId = 1, + DirectionId = 1, }, - new Subcategory + new Department { Title = "Test2", Description = "Test2", - CategoryId = 1, + DirectionId = 1, }, - new Subcategory + new Department { Title = "Test3", Description = "Test3", - CategoryId = 1, + DirectionId = 1, }, }; - ctx.Subcategories.AddRangeAsync(subcategories); + ctx.Departments.AddRangeAsync(departments); - var subsubcategories = new List() + var classes = new List() { - new Subsubcategory() + new Class() { Title = "Test1", Description = "Test1", - SubcategoryId = 1, + DepartmentId = 1, }, - new Subsubcategory + new Class { Title = "Test2", Description = "Test2", - SubcategoryId = 1, + DepartmentId = 1, }, - new Subsubcategory + new Class { Title = "Test3", Description = "Test3", - SubcategoryId = 1, + DepartmentId = 1, }, }; - ctx.Subsubcategories.AddRangeAsync(subsubcategories); + ctx.Classes.AddRangeAsync(classes); ctx.SaveChangesAsync(); } diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SubcategoryServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/DepartmentServiceTests.cs similarity index 80% rename from OutOfSchool/OutOfSchool.WebApi.Tests/Services/SubcategoryServiceTests.cs rename to OutOfSchool/OutOfSchool.WebApi.Tests/Services/DepartmentServiceTests.cs index c701f90c7c..9c8d12e72c 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SubcategoryServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/DepartmentServiceTests.cs @@ -18,12 +18,12 @@ namespace OutOfSchool.WebApi.Tests.Services { [TestFixture] - public class SubcategoryServiceTests + public class DepartmentServiceTests { private DbContextOptions options; private OutOfSchoolDbContext context; - private ISubcategoryRepository repo; - private ISubcategoryService service; + private IDepartmentRepository repo; + private IDepartmentService service; private Mock> localizer; private Mock logger; @@ -37,10 +37,10 @@ public void SetUp() options = builder.Options; context = new OutOfSchoolDbContext(options); - repo = new SubcategoryRepository(context); + repo = new DepartmentRepository(context); localizer = new Mock>(); logger = new Mock(); - service = new SubcategoryService(repo, logger.Object, localizer.Object); + service = new DepartmentService(repo, logger.Object, localizer.Object); SeedDatabase(); } @@ -50,11 +50,11 @@ public void SetUp() public async Task Create_WhenEntityIsValid_ReturnsCreatedEntity() { // Arrange - var expected = new Subcategory() + var expected = new Department() { Title = "NewTitle", Description = "NewDescription", - CategoryId = 1, + DirectionId = 1, }; // Act @@ -121,12 +121,12 @@ public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() { // Arrange - var changedEntity = new SubcategoryDTO() + var changedEntity = new DepartmentDto() { Id = 1, Title = "ChangedTitle1", Description = "Bla-bla", - CategoryId = 1, + DirectionId = 1, }; // Act @@ -141,10 +141,10 @@ public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() public void Update_WhenEntityIsInvalid_ThrowsDbUpdateConcurrencyException() { // Arrange - var changedEntity = new SubcategoryDTO() + var changedEntity = new DepartmentDto() { Title = "New", - CategoryId = 1, + DirectionId = 1, }; // Act and Assert @@ -160,7 +160,7 @@ public async Task Delete_WhenIdIsValid_DeletesEntity(long id) // Act var countBeforeDeleting = (await service.GetAll().ConfigureAwait(false)).Count(); - context.Entry(await repo.GetById(id).ConfigureAwait(false)).State = EntityState.Detached; + context.Entry(await repo.GetById(id).ConfigureAwait(false)).State = EntityState.Detached; await service.Delete(id).ConfigureAwait(false); @@ -183,14 +183,14 @@ public void Delete_WhenIdIsInvalid_ThrowsDbUpdateConcurrencyException(long id) [Test] [Order(10)] [TestCase(1)] - public async Task GetByCategoryId_WhenIdIsValid_ReturnsEntities(long id) + public async Task GetByDirectionId_WhenIdIsValid_ReturnsEntities(long id) { // Arrange var expected = await repo.GetAll().ConfigureAwait(false); - expected = expected.Where(x => x.CategoryId == id); + expected = expected.Where(x => x.DirectionId == id); // Act - var entities = await service.GetByCategoryId(id); + var entities = await service.GetByDirectionId(id); // Assert Assert.That(entities.Count(), Is.EqualTo(expected.Count())); @@ -199,11 +199,11 @@ public async Task GetByCategoryId_WhenIdIsValid_ReturnsEntities(long id) [Test] [Order(11)] [TestCase(10)] - public void GetByCategoryId_WhenIdIsInvalid_ThrowsArgumentException(long id) + public void GetByDirectionId_WhenIdIsInvalid_ThrowsArgumentException(long id) { // Act and Assert Assert.ThrowsAsync( - async () => await service.GetByCategoryId(id).ConfigureAwait(false)); + async () => await service.GetByDirectionId(id).ConfigureAwait(false)); } private void SeedDatabase() @@ -213,50 +213,50 @@ private void SeedDatabase() ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); - var categories = new List() + var directions = new List() { - new Category() + new Direction() { Title = "Test1", Description = "Test1", }, - new Category + new Direction { Title = "Test2", Description = "Test2", }, - new Category + new Direction { Title = "Test3", Description = "Test3", }, }; - ctx.Categories.AddRangeAsync(categories); + ctx.Directions.AddRangeAsync(directions); - var subcategories = new List() + var departments = new List() { - new Subcategory() + new Department() { Title = "Test1", Description = "Test1", - CategoryId = 1, + DirectionId = 1, }, - new Subcategory + new Department { Title = "Test2", Description = "Test2", - CategoryId = 1, + DirectionId = 1, }, - new Subcategory + new Department { Title = "Test3", Description = "Test3", - CategoryId = 1, + DirectionId = 1, }, }; - ctx.Subcategories.AddRangeAsync(subcategories); + ctx.Departments.AddRangeAsync(departments); ctx.SaveChangesAsync(); } diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/CategoryServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/DirectionServiceTests.cs similarity index 88% rename from OutOfSchool/OutOfSchool.WebApi.Tests/Services/CategoryServiceTests.cs rename to OutOfSchool/OutOfSchool.WebApi.Tests/Services/DirectionServiceTests.cs index c67585024e..0ba9c9bfaf 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/CategoryServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/DirectionServiceTests.cs @@ -18,12 +18,12 @@ namespace OutOfSchool.WebApi.Tests.Services { [TestFixture] - public class CategoryServiceTests + public class DirectionServiceTests { private DbContextOptions options; private OutOfSchoolDbContext context; - private IEntityRepository repo; - private ICategoryService service; + private IEntityRepository repo; + private IDirectionService service; private Mock> localizer; private Mock logger; @@ -37,10 +37,10 @@ public void SetUp() options = builder.Options; context = new OutOfSchoolDbContext(options); - repo = new EntityRepository(context); + repo = new EntityRepository(context); localizer = new Mock>(); logger = new Mock(); - service = new CategoryService(repo, logger.Object, localizer.Object); + service = new DirectionService(repo, logger.Object, localizer.Object); SeedDatabase(); } @@ -50,7 +50,7 @@ public void SetUp() public async Task Create_WhenEntityIsValid_ReturnsCreatedEntity() { // Arrange - var expected = new Category() + var expected = new Direction() { Title = "NewTitle", Description = "NewDescription", @@ -120,7 +120,7 @@ public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() { // Arrange - var changedEntity = new CategoryDTO() + var changedEntity = new DirectionDto() { Id = 1, Title = "ChangedTitle1", @@ -138,7 +138,7 @@ public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() public void Update_WhenEntityIsInvalid_ThrowsDbUpdateConcurrencyException() { // Arrange - var changedEntity = new CategoryDTO() + var changedEntity = new DirectionDto() { Title = "NewTitle1", }; @@ -156,7 +156,7 @@ public async Task Delete_WhenIdIsValid_DeletesEntity(long id) // Act var countBeforeDeleting = (await service.GetAll().ConfigureAwait(false)).Count(); - context.Entry(await repo.GetById(id).ConfigureAwait(false)).State = EntityState.Detached; + context.Entry(await repo.GetById(id).ConfigureAwait(false)).State = EntityState.Detached; await service.Delete(id).ConfigureAwait(false); @@ -183,26 +183,26 @@ private void SeedDatabase() ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); - var categories = new List() + var directions = new List() { - new Category() + new Direction() { Title = "Test1", Description = "Test1", }, - new Category + new Direction { Title = "Test2", Description = "Test2", }, - new Category + new Direction { Title = "Test3", Description = "Test3", }, }; - ctx.Categories.AddRangeAsync(categories); + ctx.Directions.AddRangeAsync(directions); ctx.SaveChangesAsync(); } } diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/UnitTests/WorkshopServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/UnitTests/WorkshopServiceTests.cs index c74c56f470..4ff05d22f8 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/UnitTests/WorkshopServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/UnitTests/WorkshopServiceTests.cs @@ -21,7 +21,7 @@ public class WorkshopServiceTests private IWorkshopService workshopService; private Mock workshopRepositoryMoq; - private Mock sscategoryRepositoryMoq; + private Mock classRepositoryMoq; private Mock> teacherRepositoryMoq; private Mock> addressRepositoryMoq; @@ -31,13 +31,13 @@ public class WorkshopServiceTests private Workshop newWorkshop; private List workshops; - private Subsubcategory sscategory; + private Class classEntity; [SetUp] public void SetUp() { workshopRepositoryMoq = new Mock(); - sscategoryRepositoryMoq = new Mock(); + classRepositoryMoq = new Mock(); teacherRepositoryMoq = new Mock>(); addressRepositoryMoq = new Mock>(); ratingService = new Mock(); @@ -46,7 +46,7 @@ public void SetUp() workshopService = new WorkshopService( workshopRepositoryMoq.Object, - sscategoryRepositoryMoq.Object, + classRepositoryMoq.Object, teacherRepositoryMoq.Object, addressRepositoryMoq.Object, ratingService.Object, @@ -62,8 +62,8 @@ public void SetUp() public async Task Create_WhenEntityIsValid_ShouldRunInTransaction() { // Arrange - sscategoryRepositoryMoq.Setup(x => x.GetById(It.IsAny())) - .ReturnsAsync(sscategory); + classRepositoryMoq.Setup(x => x.GetById(It.IsAny())) + .ReturnsAsync(classEntity); workshopRepositoryMoq.Setup(x => x.RunInTransaction(It.IsAny>>())) .ReturnsAsync(newWorkshop); @@ -193,9 +193,9 @@ public async Task Update_WhenEntityIsValid_ShouldRunInTransaction() MinAge = 4, Logo = "image1", ProviderId = 1, - CategoryId = 1, - SubsubcategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + ClassId = 1, + DepartmentId = 1, AddressId = 55, Address = new Address { @@ -241,8 +241,8 @@ public async Task Update_WhenEntityIsValid_ShouldRunInTransaction() IQueryable quer = new EnumerableQuery(workshops); workshopRepositoryMoq.Setup(z => z.GetByFilterNoTracking(It.IsAny>>(), It.IsAny())) .Returns(quer); - sscategoryRepositoryMoq.Setup(x => x.GetById(It.IsAny())) - .ReturnsAsync(sscategory); + classRepositoryMoq.Setup(x => x.GetById(It.IsAny())) + .ReturnsAsync(classEntity); workshopRepositoryMoq.Setup(x => x.RunInTransaction(It.IsAny>>())) .ReturnsAsync(changedFirstEntity); @@ -254,7 +254,7 @@ public async Task Update_WhenEntityIsValid_ShouldRunInTransaction() Assert.Multiple(() => { workshopRepositoryMoq.Verify(x => x.GetByFilterNoTracking(It.IsAny>>(), It.IsAny()), Times.Once()); - sscategoryRepositoryMoq.Verify(x => x.GetById(It.IsAny()), Times.Once()); + classRepositoryMoq.Verify(x => x.GetById(It.IsAny()), Times.Once()); workshopRepositoryMoq.Verify(x => x.RunInTransaction(It.IsAny>>()), Times.Once()); Assert.IsNotNull(result); @@ -328,9 +328,9 @@ private void FakeEntities() MinAge = 4, Logo = "image", ProviderId = 1, - CategoryId = 1, - SubsubcategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + ClassId = 1, + DepartmentId = 1, AddressId = 0, Address = new Address { @@ -389,9 +389,9 @@ private void FakeEntities() MinAge = 4, Logo = "image1", ProviderId = 1, - CategoryId = 1, - SubsubcategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + ClassId = 1, + DepartmentId = 1, AddressId = 55, Address = new Address { @@ -451,8 +451,8 @@ private void FakeEntities() MinAge = 4, Logo = "image2", ProviderId = 1, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 10, Address = new Address { @@ -511,8 +511,8 @@ private void FakeEntities() MinAge = 4, Logo = "image3", ProviderId = 1, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 11, Address = new Address { @@ -572,8 +572,8 @@ private void FakeEntities() MinAge = 4, Logo = "image4", ProviderId = 1, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 15, Address = new Address { @@ -633,8 +633,8 @@ private void FakeEntities() MinAge = 4, Logo = "image5", ProviderId = 1, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 17, Address = new Address { @@ -674,17 +674,17 @@ private void FakeEntities() }, }, }; - sscategory = new Subsubcategory() + classEntity = new Class() { Id = 1, Title = "new SSC", - SubcategoryId = 1, - Subcategory = new Subcategory() + DepartmentId = 1, + Department = new Department() { Id = 1, Title = "new SC", - CategoryId = 1, - Category = new Category() + DirectionId = 1, + Direction = new Direction() { Id = 1, Title = "new C", diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/WorkshopServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/WorkshopServiceTests.cs index 41029b2a14..87e7383508 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/WorkshopServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/WorkshopServiceTests.cs @@ -26,7 +26,7 @@ public class WorkshopServiceTests private OutOfSchoolDbContext dbContext; private IWorkshopRepository workshopRepository; - private Mock sscategoryRepositoryMoq; + private Mock classRepositoryMoq; private IEntityRepository teacherRepository; private IEntityRepository
addressRepository; @@ -35,7 +35,7 @@ public class WorkshopServiceTests private Mock> localizerMoq; private Workshop newWorkshop; - private Subsubcategory sscategory; + private Class classEntity; [SetUp] public void SetUp() @@ -49,7 +49,7 @@ public void SetUp() dbContext = new OutOfSchoolDbContext(options); workshopRepository = new WorkshopRepository(dbContext); - sscategoryRepositoryMoq = new Mock(); + classRepositoryMoq = new Mock(); teacherRepository = new EntityRepository(dbContext); addressRepository = new EntityRepository
(dbContext); @@ -59,7 +59,7 @@ public void SetUp() workshopService = new WorkshopService( workshopRepository, - sscategoryRepositoryMoq.Object, + classRepositoryMoq.Object, teacherRepository, addressRepository, ratingServiceMoq.Object, @@ -74,8 +74,8 @@ public void SetUp() public async Task Create_WhenEntityIsValid_ShouldCreateEntities() { // Arrange - sscategoryRepositoryMoq.Setup(x => x.GetById(It.IsAny())) - .ReturnsAsync(sscategory); + classRepositoryMoq.Setup(x => x.GetById(It.IsAny())) + .ReturnsAsync(classEntity); var teachersCount = dbContext.Teachers.Count(); var addressecCount = dbContext.Addresses.Count(); @@ -87,9 +87,9 @@ public async Task Create_WhenEntityIsValid_ShouldCreateEntities() Assert.AreEqual(6, result.Id); Assert.AreEqual(newWorkshop.Title, result.Title); - Assert.AreEqual(sscategory.Id, result.SubsubcategoryId); - Assert.AreEqual(sscategory.SubcategoryId, result.SubcategoryId); - Assert.AreEqual(sscategory.Subcategory.CategoryId, result.CategoryId); + Assert.AreEqual(classEntity.Id, result.ClassId); + Assert.AreEqual(classEntity.DepartmentId, result.DepartmentId); + Assert.AreEqual(classEntity.Department.DirectionId, result.DirectionId); Assert.AreEqual(newWorkshop.Teachers.Count, result.Teachers.Count()); Assert.AreEqual(dbContext.Teachers.Count(), teachersCount + 2); @@ -99,15 +99,15 @@ public async Task Create_WhenEntityIsValid_ShouldCreateEntities() } [Test] - public async Task Create_WhenCategoriesIdsSetWrong_ShouldCreateEntitiesWithRightCategoriesIds() + public async Task Create_WhenDirectionsIdsAreWrong_ShouldCreateEntitiesWithRightDirectionsIds() { // Arrange - sscategoryRepositoryMoq.Setup(x => x.GetById(It.IsAny())) - .ReturnsAsync(sscategory); + classRepositoryMoq.Setup(x => x.GetById(It.IsAny())) + .ReturnsAsync(classEntity); newWorkshop.Title = "newWorkshopTitle2"; newWorkshop.ProviderId = 7; - newWorkshop.SubcategoryId = 10; - newWorkshop.CategoryId = 90; + newWorkshop.DepartmentId = 10; + newWorkshop.DirectionId = 90; // Act var result = await workshopService.Create(newWorkshop.ToModel()).ConfigureAwait(false); @@ -117,16 +117,16 @@ public async Task Create_WhenCategoriesIdsSetWrong_ShouldCreateEntitiesWithRight Assert.AreEqual(6, result.Id); Assert.AreEqual(newWorkshop.Title, result.Title); - Assert.AreEqual(sscategory.Id, result.SubsubcategoryId); - Assert.AreEqual(sscategory.SubcategoryId, result.SubcategoryId); - Assert.AreEqual(sscategory.Subcategory.CategoryId, result.CategoryId); + Assert.AreEqual(classEntity.Id, result.ClassId); + Assert.AreEqual(classEntity.DepartmentId, result.DepartmentId); + Assert.AreEqual(classEntity.Department.DirectionId, result.DirectionId); } [Test] - public void Create_WhenSubsubcategoryIdSetWrong_ShouldThrowArgumentOutOfRangeException() + public void Create_WhenThereIsNoClassId_ShouldThrowArgumentOutOfRangeException() { // Arrange - sscategoryRepositoryMoq.Setup(x => x.GetById(It.IsAny())) + classRepositoryMoq.Setup(x => x.GetById(It.IsAny())) .ReturnsAsync(() => null); newWorkshop.Title = "newWorkshopTitle3"; @@ -187,8 +187,8 @@ public async Task GetById_WhenThereIsNoEntityWithId_ShouldReturnNull(long id) public async Task Update_WhenEntityIsValid_ShouldUpdateAllRelationalEntities() { // Arrange - sscategoryRepositoryMoq.Setup(x => x.GetById(It.IsAny())) - .ReturnsAsync(sscategory); + classRepositoryMoq.Setup(x => x.GetById(It.IsAny())) + .ReturnsAsync(classEntity); var changedFirstEntity = new Workshop() { Id = 1, @@ -210,9 +210,9 @@ public async Task Update_WhenEntityIsValid_ShouldUpdateAllRelationalEntities() MinAge = 4, Logo = "image1", ProviderId = 1, - CategoryId = 1, - SubsubcategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + ClassId = 1, + DepartmentId = 1, AddressId = 55, Address = new Address { @@ -262,9 +262,9 @@ public async Task Update_WhenEntityIsValid_ShouldUpdateAllRelationalEntities() // Assert Assert.AreEqual(changedFirstEntity.Title, result.Title); - Assert.AreEqual(sscategory.Id, result.SubsubcategoryId); - Assert.AreEqual(sscategory.SubcategoryId, result.SubcategoryId); - Assert.AreEqual(sscategory.Subcategory.CategoryId, result.CategoryId); + Assert.AreEqual(classEntity.Id, result.ClassId); + Assert.AreEqual(classEntity.DepartmentId, result.DepartmentId); + Assert.AreEqual(classEntity.Department.DirectionId, result.DirectionId); Assert.AreEqual(changedFirstEntity.Teachers.Count, result.Teachers.Count()); Assert.AreEqual(dbContext.Teachers.Where(x => x.WorkshopId == 1).Count(), result.Teachers.Count()); @@ -281,8 +281,8 @@ public async Task Update_WhenEntityIsValid_ShouldUpdateAllRelationalEntities() public void Update_WhenIdIsInvalid_ShouldThrowArgumentOutOfRangeException() { // Arrange - sscategoryRepositoryMoq.Setup(x => x.GetById(It.IsAny())) - .ReturnsAsync(sscategory); + classRepositoryMoq.Setup(x => x.GetById(It.IsAny())) + .ReturnsAsync(classEntity); var changedEntity = new WorkshopDTO() { Id = 99, @@ -360,9 +360,9 @@ private void SeedDatabase() MinAge = 4, Logo = "image", ProviderId = 6, - CategoryId = 1, - SubsubcategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + ClassId = 1, + DepartmentId = 1, AddressId = 0, Address = new Address { @@ -398,17 +398,17 @@ private void SeedDatabase() }, }, }; - sscategory = new Subsubcategory() + classEntity = new Class() { Id = 1, Title = "new SSC", - SubcategoryId = 1, - Subcategory = new Subcategory() + DepartmentId = 1, + Department = new Department() { Id = 1, Title = "new SC", - CategoryId = 1, - Category = new Category() + DirectionId = 1, + Direction = new Direction() { Id = 1, Title = "new C", @@ -444,9 +444,9 @@ private void SeedDatabase() MinAge = 4, Logo = "image1", ProviderId = 1, - CategoryId = 1, - SubsubcategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + ClassId = 1, + DepartmentId = 1, AddressId = 55, Address = new Address { @@ -506,8 +506,8 @@ private void SeedDatabase() MinAge = 4, Logo = "image2", ProviderId = 2, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 10, Address = new Address { @@ -566,8 +566,8 @@ private void SeedDatabase() MinAge = 4, Logo = "image3", ProviderId = 3, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 11, Address = new Address { @@ -627,8 +627,8 @@ private void SeedDatabase() MinAge = 4, Logo = "image4", ProviderId = 4, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 15, Address = new Address { @@ -688,8 +688,8 @@ private void SeedDatabase() MinAge = 4, Logo = "image5", ProviderId = 5, - CategoryId = 1, - SubcategoryId = 1, + DirectionId = 1, + DepartmentId = 1, AddressId = 17, Address = new Address { @@ -733,12 +733,12 @@ private void SeedDatabase() var apps = new List() { new Application() { Id = 1, WorkshopId = 1 }, new Application() { Id = 2, WorkshopId = 1 }, new Application() { Id = 3, WorkshopId = 2 }, new Application() { Id = 4, WorkshopId = 2 } }; context.Applications.AddRangeAsync(apps); - var categories = new List() { new Category() { Title = "Category1" }, new Category() { Title = "Category2" } }; - context.Categories.AddRangeAsync(categories); - var subcategories = new List() { new Subcategory() { Title = "new1", CategoryId = 1 }, new Subcategory() { Title = "new2", CategoryId = 1 } }; - context.Subcategories.AddRangeAsync(subcategories); - var subsubcategories = new List() { new Subsubcategory() { Title = "new1", SubcategoryId = 1 }, new Subsubcategory() { Title = "new2", SubcategoryId = 1 } }; - context.Subsubcategories.AddRangeAsync(subsubcategories); + var directions = new List() { new Direction() { Title = "Direction1" }, new Direction() { Title = "Direction2" } }; + context.Directions.AddRangeAsync(directions); + var departments = new List() { new Department() { Title = "new1", DirectionId = 1 }, new Department() { Title = "new2", DirectionId = 1 } }; + context.Departments.AddRangeAsync(departments); + var classes = new List() { new Class() { Title = "new1", DepartmentId = 1 }, new Class() { Title = "new2", DepartmentId = 1 } }; + context.Classes.AddRangeAsync(classes); context.Workshops.AddRangeAsync(workshops); context.SaveChangesAsync(); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs deleted file mode 100644 index b2109d7095..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Mime; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Localization; -using OutOfSchool.WebApi.Extensions; -using OutOfSchool.WebApi.Models; -using OutOfSchool.WebApi.Services; - -namespace OutOfSchool.WebApi.Controllers -{ - /// - /// Controller with CRUD operations for category entity. - /// - [ApiController] - [Route("[controller]/[action]")] - [Authorize(AuthenticationSchemes = "Bearer")] - public class CategoryController : ControllerBase - { - private readonly ICategoryService service; - private readonly IStringLocalizer localizer; - - /// - /// Initializes a new instance of the class. - /// Initialization of CategoryController. - /// - /// Service for CategoryCOntroller. - /// Localizer. - public CategoryController(ICategoryService service, IStringLocalizer localizer) - { - this.localizer = localizer; - this.service = service; - } - - /// - /// To get all Categories from DB. - /// - /// List of Categories. - [AllowAnonymous] - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Get() - { - var categories = await service.GetAll().ConfigureAwait(false); - - if (!categories.Any()) - { - return NoContent(); - } - - return Ok(categories); - } - - /// - /// To recieve category with define id. - /// - /// Key in table. - /// Category with define id. - [AllowAnonymous] - [HttpGet("{id}")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CategoryDTO))] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task GetById(long id) - { - this.ValidateId(id, localizer); - - return Ok(await service.GetById(id).ConfigureAwait(false)); - } - - /// - /// To create new Category and add to the DB. - /// - /// CategoryDTO object that we want to add. - /// A representing the result of the asynchronous operation. - [Authorize(Roles = "admin")] - [HttpPost] - [Consumes(MediaTypeNames.Application.Json)] - [ProducesResponseType(StatusCodes.Status201Created)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Create(CategoryDTO dto) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - try - { - dto.Id = default; - - var category = await service.Create(dto).ConfigureAwait(false); - - return CreatedAtAction( - nameof(GetById), - new { id = category.Id, }, - category); - } - catch (ArgumentException ex) - { - return BadRequest(ex.Message); - } - } - - /// - /// To update Category entity that already exists. - /// - /// CategoryDTO object with new properties. - /// Category's key. - [Authorize(Roles = "admin")] - [HttpPut] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CategoryDTO))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Update(CategoryDTO categoryDTO) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - return Ok(await service.Update(categoryDTO).ConfigureAwait(false)); - } - - /// - /// Delete Category entity from DB. - /// - /// The key in table. - /// A representing the result of the asynchronous operation. - [Authorize(Roles = "admin")] - [HttpDelete("{id}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Delete(long id) - { - this.ValidateId(id, localizer); - - await service.Delete(id).ConfigureAwait(false); - - return NoContent(); - } - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/ClassController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/ClassController.cs new file mode 100644 index 0000000000..70d7922206 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/ClassController.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mime; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using OutOfSchool.WebApi.Services; + +namespace OutOfSchool.WebApi.Controllers +{ + /// + /// Controller with CRUD operations for Class entity. + /// + [ApiController] + [ApiExplorerSettings(GroupName = "Direction")] + [Route("[controller]/[action]")] + [Authorize(AuthenticationSchemes = "Bearer")] + public class ClassController : ControllerBase + { + private readonly IClassService service; + private readonly IStringLocalizer localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Service for Class entity. + /// Localizer. + public ClassController(IClassService service, IStringLocalizer localizer) + { + this.localizer = localizer; + this.service = service; + } + + /// + /// To get all Classes from DB. + /// + /// List of all classes, or no content. + /// One or more classes were found. + /// No class was found. + /// If any server error occures. + [AllowAnonymous] + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Get() + { + var classes = await service.GetAll().ConfigureAwait(false); + + if (!classes.Any()) + { + return NoContent(); + } + + return Ok(classes); + } + + /// + /// To recieve the class with the defined id. + /// + /// Key of the class in table. + /// . + /// The entity was found by given Id. + /// If any server error occures. For example: Id was wrong. + [AllowAnonymous] + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ClassDto))] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetById(long id) + { + this.ValidateId(id, localizer); + + return Ok(await service.GetById(id).ConfigureAwait(false)); + } + + /// + /// To get Classes from DB with some Deprtment id. + /// + /// Department ID. + /// List of found classes, or no content. + /// One or more classes were found. + /// No class was found. + /// Id was wrong. + /// If any server error occures. + [AllowAnonymous] + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetByDepartmentId(long id) + { + try + { + var classes = await service.GetByDepartmentId(id).ConfigureAwait(false); + + if (!classes.Any()) + { + return NoContent(); + } + + return Ok(classes); + } + catch (ArgumentException ex) + { + return BadRequest(ex.Message); + } + } + + /// + /// To create a new Class and add it to the DB. + /// + /// ClassDto object that will be added. + /// Class that was created. + /// Class was successfully created. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpPost] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Create(ClassDto classDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + try + { + classDto.Id = default; + + var classEntity = await service.Create(classDto).ConfigureAwait(false); + + return CreatedAtAction( + nameof(GetById), + new { id = classEntity.Id, }, + classEntity); + } + catch (ArgumentException ex) + { + return BadRequest(ex.Message); + } + } + + /// + /// To update Class entity that already exists. + /// + /// ClassDto object with new properties. + /// Class that was updated. + /// Class was successfully updated. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpPut] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ClassDto))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Update(ClassDto classDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + return Ok(await service.Update(classDto).ConfigureAwait(false)); + } + + /// + /// Delete the Class entity from DB. + /// + /// The key of the class in table. + /// Status Code. + /// Class was successfully deleted. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Delete(long id) + { + this.ValidateId(id, localizer); + + await service.Delete(id).ConfigureAwait(false); + + return NoContent(); + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/DepartmentController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/DepartmentController.cs new file mode 100644 index 0000000000..d0143bd2ef --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/DepartmentController.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mime; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using OutOfSchool.WebApi.Services; + +namespace OutOfSchool.WebApi.Controllers +{ + /// + /// Controller with CRUD operations for Department entity. + /// + [ApiController] + [ApiExplorerSettings(GroupName = "Direction")] + [Route("[controller]/[action]")] + [Authorize(AuthenticationSchemes = "Bearer")] + public class DepartmentController : ControllerBase + { + private readonly IDepartmentService service; + private readonly IStringLocalizer localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Service for Department entity. + /// Localizer. + public DepartmentController(IDepartmentService service, IStringLocalizer localizer) + { + this.localizer = localizer; + this.service = service; + } + + /// + /// To get all Departments from DB. + /// + /// List of all departments, or no content. + /// One or more deparments were found. + /// No department was found. + /// If any server error occures. + [AllowAnonymous] + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Get() + { + var departments = await service.GetAll().ConfigureAwait(false); + + if (!departments.Any()) + { + return NoContent(); + } + + return Ok(departments); + } + + /// + /// To recieve the department with the defined id. + /// + /// Key of the department in the table. + /// . + /// The entity was found by given Id. + /// If any server error occures. For example: Id was wrong. + [AllowAnonymous] + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(DepartmentDto))] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetById(long id) + { + this.ValidateId(id, localizer); + + return Ok(await service.GetById(id).ConfigureAwait(false)); + } + + /// + /// To get all Departments from DB with some DirectionId. + /// + /// The direction's Id. + /// List of found departments, or no content. + /// One or more departments were found. + /// No department was found. + /// Id was wrong. + /// If any server error occures. + [AllowAnonymous] + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetByDirectionId(long id) + { + try + { + var departments = await service.GetByDirectionId(id).ConfigureAwait(false); + + if (!departments.Any()) + { + return NoContent(); + } + + return Ok(departments); + } + catch (ArgumentException ex) + { + return BadRequest(ex.Message); + } + } + + /// + /// To create a new Department and add it to the DB. + /// + /// DepartmentDto object that will be added. + /// Department that was created. + /// Department was successfully created. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpPost] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Create(DepartmentDto departmentDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + try + { + departmentDto.Id = default; + + var department = await service.Create(departmentDto).ConfigureAwait(false); + + return CreatedAtAction( + nameof(GetById), + new { id = department.Id, }, + department); + } + catch (ArgumentException ex) + { + return BadRequest(ex.Message); + } + } + + /// + /// To update Department entity that already exists. + /// + /// DepartmentDto object with new properties. + /// Department that was updated. + /// Department was successfully updated. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpPut] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(DepartmentDto))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Update(DepartmentDto departmentDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + return Ok(await service.Update(departmentDto).ConfigureAwait(false)); + } + + /// + /// Delete the Department entity from DB. + /// + /// The key of the Department in table. + /// Status Code. + /// Department was successfully deleted. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Delete(long id) + { + this.ValidateId(id, localizer); + + await service.Delete(id).ConfigureAwait(false); + + return NoContent(); + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/DirectionController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/DirectionController.cs new file mode 100644 index 0000000000..6a2a7d54a7 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/DirectionController.cs @@ -0,0 +1,174 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mime; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using OutOfSchool.WebApi.Services; + +namespace OutOfSchool.WebApi.Controllers +{ + /// + /// Controller with CRUD operations for Direction entity. + /// + [ApiController] + [ApiExplorerSettings(GroupName = "Direction")] + [Route("[controller]/[action]")] + [Authorize(AuthenticationSchemes = "Bearer")] + public class DirectionController : ControllerBase + { + private readonly IDirectionService service; + private readonly IStringLocalizer localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Service for Direction entity. + /// Localizer. + public DirectionController(IDirectionService service, IStringLocalizer localizer) + { + this.localizer = localizer; + this.service = service; + } + + /// + /// To get all Directions from DB. + /// + /// List of all directions, or no content. + /// One or more directions were found. + /// No direction was found. + /// If any server error occures. + [AllowAnonymous] + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Get() + { + var directions = await service.GetAll().ConfigureAwait(false); + + if (!directions.Any()) + { + return NoContent(); + } + + return Ok(directions); + } + + /// + /// To recieve the direction with the defined id. + /// + /// Key of the direction in the table. + /// . + /// The entity was found by given Id. + /// If any server error occures. For example: Id was wrong. + [AllowAnonymous] + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(DirectionDto))] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetById(long id) + { + this.ValidateId(id, localizer); + + return Ok(await service.GetById(id).ConfigureAwait(false)); + } + + /// + /// To create a new direction and add it to the DB. + /// + /// DirectionDto object that will be added. + /// Direction that was created. + /// Direction was successfully created. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpPost] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Create(DirectionDto directionDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + try + { + directionDto.Id = default; + + var direction = await service.Create(directionDto).ConfigureAwait(false); + + return CreatedAtAction( + nameof(GetById), + new { id = direction.Id, }, + direction); + } + catch (ArgumentException ex) + { + return BadRequest(ex.Message); + } + } + + /// + /// To update Direction entity that already exists. + /// + /// DirectionDto object with new properties. + /// Direction that was updated. + /// Direction was successfully updated. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpPut] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(DirectionDto))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Update(DirectionDto directionDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + return Ok(await service.Update(directionDto).ConfigureAwait(false)); + } + + /// + /// Delete the Direction entity from DB. + /// + /// The key of the Direction in table. + /// Status Code. + /// Direction was successfully deleted. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [Authorize(Roles = "admin")] + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Delete(long id) + { + this.ValidateId(id, localizer); + + await service.Delete(id).ConfigureAwait(false); + + return NoContent(); + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs deleted file mode 100644 index 0d2dc0c85b..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Mime; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Localization; -using OutOfSchool.WebApi.Extensions; -using OutOfSchool.WebApi.Models; -using OutOfSchool.WebApi.Services; - -namespace OutOfSchool.WebApi.Controllers -{ - /// - /// Controller with CRUD operations for subcategory entity. - /// - [ApiController] - [Route("[controller]/[action]")] - [Authorize(AuthenticationSchemes = "Bearer")] - public class SubcategoryController : ControllerBase - { - private readonly ISubcategoryService service; - private readonly IStringLocalizer localizer; - - /// - /// Initializes a new instance of the class. - /// Initialization of SubcategoryController. - /// - /// Service for SubcategoryCOntroller. - /// Localizer. - public SubcategoryController(ISubcategoryService service, IStringLocalizer localizer) - { - this.localizer = localizer; - this.service = service; - } - - /// - /// To get all Subcategories from DB. - /// - /// List of Subcategories. - [AllowAnonymous] - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Get() - { - var categories = await service.GetAll().ConfigureAwait(false); - - if (!categories.Any()) - { - return NoContent(); - } - - return Ok(categories); - } - - /// - /// To recieve Subcategory with define id. - /// - /// Key in table. - /// Subcategory with define id. - [AllowAnonymous] - [HttpGet("{id}")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SubcategoryDTO))] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task GetById(long id) - { - this.ValidateId(id, localizer); - - return Ok(await service.GetById(id).ConfigureAwait(false)); - } - - /// - /// To get all Subcategories from DB with some CategoryId. - /// - /// The category Id. - /// List of Categories. - [AllowAnonymous] - [HttpGet("{id}")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task GetByCategoryId(long id) - { - try - { - var categories = await service.GetByCategoryId(id).ConfigureAwait(false); - - if (!categories.Any()) - { - return NoContent(); - } - - return Ok(categories); - } - catch (ArgumentException ex) - { - return BadRequest(ex.Message); - } - } - - /// - /// To create new Subcategory and add to the DB. - /// - /// SubcategoryDTO object that we want to add. - /// A representing the result of the asynchronous operation. - [Authorize(Roles = "admin")] - [HttpPost] - [Consumes(MediaTypeNames.Application.Json)] - [ProducesResponseType(StatusCodes.Status201Created)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Create(SubcategoryDTO dto) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - try - { - dto.Id = default; - - var category = await service.Create(dto).ConfigureAwait(false); - - return CreatedAtAction( - nameof(GetById), - new { id = category.Id, }, - category); - } - catch (ArgumentException ex) - { - return BadRequest(ex.Message); - } - } - - /// - /// To update Subcategory entity that already exists. - /// - /// SubcategoryDTO object with new properties. - /// Subcategory's key. - [Authorize(Roles = "admin")] - [HttpPut] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SubcategoryDTO))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Update(SubcategoryDTO categoryDTO) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - return Ok(await service.Update(categoryDTO).ConfigureAwait(false)); - } - - /// - /// Delete Subcategory entity from DB. - /// - /// The key in table. - /// A representing the result of the asynchronous operation. - [Authorize(Roles = "admin")] - [HttpDelete("{id}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Delete(long id) - { - this.ValidateId(id, localizer); - - await service.Delete(id).ConfigureAwait(false); - - return NoContent(); - } - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs deleted file mode 100644 index 6544c2a500..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Mime; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Localization; -using OutOfSchool.WebApi.Extensions; -using OutOfSchool.WebApi.Models; -using OutOfSchool.WebApi.Services; - -namespace OutOfSchool.WebApi.Controllers -{ - /// - /// Controller with CRUD operations for subsubcategory entity. - /// - [ApiController] - [Route("[controller]/[action]")] - [Authorize(AuthenticationSchemes = "Bearer")] - public class SubsubcategoryController : ControllerBase - { - private readonly ISubsubcategoryService service; - private readonly IStringLocalizer localizer; - - /// - /// Initializes a new instance of the class. - /// Initialization of SubsubcategoryController. - /// - /// Service for SubsubcategoryCOntroller. - /// Localizer. - public SubsubcategoryController(ISubsubcategoryService service, IStringLocalizer localizer) - { - this.localizer = localizer; - this.service = service; - } - - /// - /// To get all Subsubcategories from DB. - /// - /// List of Subsubcategories. - [AllowAnonymous] - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Get() - { - var categories = await service.GetAll().ConfigureAwait(false); - - if (!categories.Any()) - { - return NoContent(); - } - - return Ok(categories); - } - - /// - /// To recieve Subsubcategory with define id. - /// - /// Key in table. - /// Subsubcategory with define id. - [AllowAnonymous] - [HttpGet("{id}")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SubsubcategoryDTO))] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task GetById(long id) - { - this.ValidateId(id, localizer); - - return Ok(await service.GetById(id).ConfigureAwait(false)); - } - - /// - /// To get Subategory from DB with some id. - /// - /// Subcategory ID. - /// Subcategory entity. - [AllowAnonymous] - [HttpGet("{id}")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task GetBySubcategoryId(long id) - { - try - { - var categories = await service.GetBySubcategoryId(id).ConfigureAwait(false); - - if (!categories.Any()) - { - return NoContent(); - } - - return Ok(categories); - } - catch (ArgumentException ex) - { - return BadRequest(ex.Message); - } - } - - /// - /// To create new Subsubcategory and add to the DB. - /// - /// SubsubcategoryDTO object that we want to add. - /// A representing the result of the asynchronous operation. - [Authorize(Roles = "admin")] - [HttpPost] - [Consumes(MediaTypeNames.Application.Json)] - [ProducesResponseType(StatusCodes.Status201Created)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Create(SubsubcategoryDTO dto) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - try - { - dto.Id = default; - - var category = await service.Create(dto).ConfigureAwait(false); - - return CreatedAtAction( - nameof(GetById), - new { id = category.Id, }, - category); - } - catch (ArgumentException ex) - { - return BadRequest(ex.Message); - } - } - - /// - /// To update Subsubcategory entity that already exists. - /// - /// SubsubcategoryDTO object with new properties. - /// Subsubcategory's key. - [Authorize(Roles = "admin")] - [HttpPut] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SubsubcategoryDTO))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Update(SubsubcategoryDTO categoryDTO) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - return Ok(await service.Update(categoryDTO).ConfigureAwait(false)); - } - - /// - /// Delete Subsubcategory entity from DB. - /// - /// The key in table. - /// A representing the result of the asynchronous operation. - [Authorize(Roles = "admin")] - [HttpDelete("{id}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task Delete(long id) - { - this.ValidateId(id, localizer); - - await service.Delete(id).ConfigureAwait(false); - - return NoContent(); - } - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs index f21ab2e9c7..53fcb9a5fb 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs @@ -41,8 +41,8 @@ public WorkshopController(IWorkshopService workshopService, IProviderService pro /// Get all workshops from the database. ///
/// List of all workshops, or no content. - /// The entity was found by given Id. - /// No entity with given Id was found. + /// One or more entites were found. + /// No entity was found. /// If any server error occures. [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] @@ -123,7 +123,7 @@ public async Task GetByProviderId(long id) /// Entity was created and returned with Id. /// If the model is invalid, some properties are not set etc. /// If the user is not authorized. - /// If the user has no rights use this method, or sets some properties that are forbidden to change. + /// If the user has no rights to use this method, or sets some properties that are forbidden to change. /// If any server error occures. [Authorize(Roles = "provider,admin")] [ProducesResponseType(StatusCodes.Status201Created, Type = typeof(WorkshopDTO))] diff --git a/OutOfSchool/OutOfSchool.WebApi/Extensions/MappingExtensions.cs b/OutOfSchool/OutOfSchool.WebApi/Extensions/MappingExtensions.cs index 6f36697a31..5992be23f5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Extensions/MappingExtensions.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Extensions/MappingExtensions.cs @@ -25,11 +25,6 @@ public static BirthCertificateDto ToModel(this BirthCertificate birthCertificate return Mapper(birthCertificate, cfg => { cfg.CreateMap(); }); } - public static CategoryDTO ToModel(this Category category) - { - return Mapper(category, cfg => { cfg.CreateMap(); }); - } - public static ChildDto ToModel(this Child child) { return child.Mapper(cfg => @@ -39,6 +34,21 @@ public static ChildDto ToModel(this Child child) }); } + public static ClassDto ToModel(this Class classEntity) + { + return Mapper(classEntity, cfg => { cfg.CreateMap(); }); + } + + public static DepartmentDto ToModel(this Department department) + { + return Mapper(department, cfg => { cfg.CreateMap(); }); + } + + public static DirectionDto ToModel(this Direction direction) + { + return Mapper(direction, cfg => { cfg.CreateMap(); }); + } + public static ParentDTO ToModel(this Parent parent) { var parentDto = @@ -84,16 +94,6 @@ public static SocialGroupDto ToModel(this SocialGroup group) return Mapper(group, cfg => { cfg.CreateMap(); }); } - public static SubcategoryDTO ToModel(this Subcategory category) - { - return Mapper(category, cfg => { cfg.CreateMap(); }); - } - - public static SubsubcategoryDTO ToModel(this Subsubcategory category) - { - return Mapper(category, cfg => { cfg.CreateMap(); }); - } - public static TeacherDTO ToModel(this Teacher teacher) { return Mapper(teacher, cfg => { cfg.CreateMap(); }); @@ -106,9 +106,9 @@ public static WorkshopDTO ToModel(this Workshop workshop) cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); cfg.CreateMap(); }); } @@ -135,11 +135,6 @@ public static BirthCertificate ToDomain(this BirthCertificateDto birthCertificat }); } - public static Category ToDomain(this CategoryDTO categoryDto) - { - return Mapper(categoryDto, cfg => { cfg.CreateMap(); }); - } - public static Child ToDomain(this ChildDto childDto) { return Mapper(childDto, cfg => @@ -149,6 +144,21 @@ public static Child ToDomain(this ChildDto childDto) }); } + public static Class ToDomain(this ClassDto classDto) + { + return Mapper(classDto, cfg => { cfg.CreateMap(); }); + } + + public static Department ToDomain(this DepartmentDto departmentDto) + { + return Mapper(departmentDto, cfg => { cfg.CreateMap(); }); + } + + public static Direction ToDomain(this DirectionDto directionDto) + { + return Mapper(directionDto, cfg => { cfg.CreateMap(); }); + } + public static Parent ToDomain(this ParentDTO parentDto) { var parent = @@ -175,16 +185,6 @@ public static SocialGroup ToDomain(this SocialGroupDto groupDto) return Mapper(groupDto, cfg => { cfg.CreateMap(); }); } - public static Subcategory ToDomain(this SubcategoryDTO categoryDto) - { - return Mapper(categoryDto, cfg => { cfg.CreateMap(); }); - } - - public static Subsubcategory ToDomain(this SubsubcategoryDTO categoryDto) - { - return Mapper(categoryDto, cfg => { cfg.CreateMap(); }); - } - public static Teacher ToDomain(this TeacherDTO teacherDto) { return Mapper(teacherDto, cfg => { cfg.CreateMap(); }); @@ -226,9 +226,9 @@ public static Workshop ToDomain(this WorkshopDTO workshopDto) cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); cfg.CreateMap(); }); } diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/SubsubcategoryDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/ClassDto.cs similarity index 86% rename from OutOfSchool/OutOfSchool.WebApi/Models/SubsubcategoryDTO.cs rename to OutOfSchool/OutOfSchool.WebApi/Models/ClassDto.cs index 31099029f4..942d60bad5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/SubsubcategoryDTO.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/ClassDto.cs @@ -6,7 +6,7 @@ namespace OutOfSchool.WebApi.Models { - public class SubsubcategoryDTO + public class ClassDto { public long Id { get; set; } @@ -20,6 +20,6 @@ public class SubsubcategoryDTO public string Description { get; set; } = string.Empty; [Required] - public long SubcategoryId { get; set; } + public long DepartmentId { get; set; } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/SubcategoryDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/DepartmentDto.cs similarity index 85% rename from OutOfSchool/OutOfSchool.WebApi/Models/SubcategoryDTO.cs rename to OutOfSchool/OutOfSchool.WebApi/Models/DepartmentDto.cs index 8122a49c4d..458601d7e2 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/SubcategoryDTO.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/DepartmentDto.cs @@ -3,7 +3,7 @@ namespace OutOfSchool.WebApi.Models { - public class SubcategoryDTO + public class DepartmentDto { public long Id { get; set; } @@ -17,6 +17,6 @@ public class SubcategoryDTO public string Description { get; set; } = string.Empty; [Required] - public long CategoryId { get; set; } + public long DirectionId { get; set; } } } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/CategoryDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/DirectionDto.cs similarity index 93% rename from OutOfSchool/OutOfSchool.WebApi/Models/CategoryDTO.cs rename to OutOfSchool/OutOfSchool.WebApi/Models/DirectionDto.cs index 7c4d99760d..87833bc0f1 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/CategoryDTO.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/DirectionDto.cs @@ -3,7 +3,7 @@ namespace OutOfSchool.WebApi.Models { - public class CategoryDTO + public class DirectionDto { public long Id { get; set; } diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs index 19f13a6f9a..11b93b4de4 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs @@ -85,13 +85,13 @@ public class WorkshopDTO public long AddressId { get; set; } [Required] - public long CategoryId { get; set; } + public long DirectionId { get; set; } [Required] - public long SubcategoryId { get; set; } + public long DepartmentId { get; set; } [Required] - public long SubsubcategoryId { get; set; } + public long ClassId { get; set; } public AddressDto Address { get; set; } diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopFilter.cs b/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopFilter.cs index 3538afe078..d768b3df3a 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopFilter.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopFilter.cs @@ -21,10 +21,10 @@ public class WorkshopFilter public bool OrderByPriceAscending { get; set; } = true; - public IEnumerable Categories { get; set; } = null; + public IEnumerable Directions { get; set; } = null; - public IEnumerable Subcategories { get; set; } = null; + public IEnumerable Departments { get; set; } = null; - public IEnumerable Subsubcategories { get; set; } = null; + public IEnumerable Classes { get; set; } = null; } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs deleted file mode 100644 index 6fcc04efbe..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; -using OutOfSchool.Services.Models; -using OutOfSchool.Services.Repository; -using OutOfSchool.WebApi.Extensions; -using OutOfSchool.WebApi.Models; -using Serilog; - -namespace OutOfSchool.WebApi.Services -{ - /// - /// CategoryService. - /// - public class CategoryService : ICategoryService - { - private readonly IEntityRepository repository; - private readonly ILogger logger; - private readonly IStringLocalizer localizer; - - /// - /// Initializes a new instance of the class. - /// - /// Repository for some entity. - /// Logger. - /// Localizer. - public CategoryService(IEntityRepository entityRepository, ILogger logger, IStringLocalizer localizer) - { - this.localizer = localizer; - this.repository = entityRepository; - this.logger = logger; - } - - /// - public async Task Create(CategoryDTO dto) - { - logger.Information("Category creating was started."); - - var category = dto.ToDomain(); - - CategoryValidation(dto); - - var newCategory = await repository.Create(category).ConfigureAwait(false); - - logger.Information($"Сategory with Id = {newCategory?.Id} created successfully."); - - return newCategory.ToModel(); - } - - /// - public async Task Delete(long id) - { - logger.Information($"Deleting Сategory with Id = {id} started."); - - var entity = new Category() { Id = id }; - - try - { - await repository.Delete(entity).ConfigureAwait(false); - - logger.Information($"Category with Id = {id} succesfully deleted."); - } - catch (DbUpdateConcurrencyException) - { - logger.Error($"Deleting failed. Category with Id = {id} doesn't exist in the system."); - throw; - } - } - - /// - public async Task> GetAll() - { - logger.Information("Getting all Categories started."); - - var categories = await this.repository.GetAll().ConfigureAwait(false); - - logger.Information(!categories.Any() - ? "Category table is empty." - : $"All {categories.Count()} records were successfully received from the Category table."); - - return categories.Select(parent => parent.ToModel()).ToList(); - } - - /// - public async Task GetById(long id) - { - logger.Information($"Getting Category by Id started. Looking Id = {id}."); - - var category = await repository.GetById((int)id).ConfigureAwait(false); - - if (category == null) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be greater than number of table entities."]); - } - - logger.Information($"Successfully got a category with Id = {id}."); - - return category.ToModel(); - } - - /// - public async Task Update(CategoryDTO dto) - { - logger.Information($"Updating Category with Id = {dto?.Id} started."); - - try - { - var category = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - - logger.Information($"Category with Id = {category?.Id} updated succesfully."); - - return category.ToModel(); - } - catch (DbUpdateConcurrencyException) - { - logger.Error($"Updating failed. Category with Id = {dto?.Id} doesn't exist in the system."); - throw; - } - } - - private void CategoryValidation(CategoryDTO dto) - { - if (repository.Get(where: x => x.Title == dto.Title).Any()) - { - throw new ArgumentException(localizer["There is already a category with such a data."]); - } - } - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs index 3be1374861..48d825b51b 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs @@ -87,7 +87,7 @@ public async Task GetById(long id) /// public async Task GetByIdWithDetails(long id) { - logger.Information($"Getting Child by Id with details started. Looking CategoryId = {id}."); + logger.Information($"Getting Child by Id with details started. Looking ChildId = {id}."); Expression> filter = child => child.Id == id; diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ClassService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ClassService.cs new file mode 100644 index 0000000000..91026bdc2d --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ClassService.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Localization; +using OutOfSchool.Services.Models; +using OutOfSchool.Services.Repository; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using Serilog; + +namespace OutOfSchool.WebApi.Services +{ + /// + /// Implements the interface with CRUD functionality for Class entity. + /// + public class ClassService : IClassService + { + private readonly IClassRepository repository; + private readonly ILogger logger; + private readonly IStringLocalizer localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Repository for some entity. + /// Logger. + /// Localizer. + public ClassService(IClassRepository entityRepository, ILogger logger, IStringLocalizer localizer) + { + this.localizer = localizer; + this.repository = entityRepository; + this.logger = logger; + } + + /// + public async Task Create(ClassDto dto) + { + logger.Information("Class creating was started."); + + var classEntity = dto.ToDomain(); + + ModelValidation(dto); + + var newClass = await repository.Create(classEntity).ConfigureAwait(false); + + logger.Information($"Class with Id = {newClass?.Id} created successfully."); + + return newClass.ToModel(); + } + + /// + public async Task Delete(long id) + { + logger.Information($"Deleting Class with Id = {id} started."); + + var entity = new Class() { Id = id }; + + try + { + await repository.Delete(entity).ConfigureAwait(false); + + logger.Information($"Class with Id = {id} succesfully deleted."); + } + catch (DbUpdateConcurrencyException) + { + logger.Error($"Deleting failed. Class with such Id = {id} doesn't exist in the system."); + throw; + } + } + + /// + public async Task> GetAll() + { + logger.Information("Getting all Classes started."); + + var classes = await this.repository.GetAll().ConfigureAwait(false); + + logger.Information(!classes.Any() + ? "Class table is empty." + : $"All {classes.Count()} records were successfully received from the Class table"); + + return classes.Select(entity => entity.ToModel()).ToList(); + } + + /// + public async Task GetById(long id) + { + logger.Information($"Getting Class by Id started. Looking Id = {id}."); + + var classEntity = await repository.GetById((int)id).ConfigureAwait(false); + + if (classEntity == null) + { + throw new ArgumentOutOfRangeException( + nameof(id), + localizer["The id cannot be greater than number of table entities."]); + } + + logger.Information($"Successfully got a Class with Id = {id}."); + + return classEntity.ToModel(); + } + + /// + public async Task> GetByDepartmentId(long id) + { + logger.Information($"Getting Class by Department's id started. Looking DepartmentId = {id}."); + + IdValidation(id); + + var classes = await this.repository.Get(where: x => x.DepartmentId == id).ToListAsync().ConfigureAwait(false); + + logger.Information(!classes.Any() + ? $"There aren't Classes for Department with Id = {id}." + : $"All {classes.Count} records were successfully received from the Class table"); + + return classes.Select(entity => entity.ToModel()).ToList(); + } + + /// + public async Task Update(ClassDto dto) + { + logger.Information($"Updating Class with Id = {dto?.Id} started."); + + try + { + var classEntity = await repository.Update(dto.ToDomain()).ConfigureAwait(false); + + logger.Information($"Class with Id = {classEntity?.Id} updated succesfully."); + + return classEntity.ToModel(); + } + catch (DbUpdateConcurrencyException) + { + logger.Error($"Updating failed. Class with Id = {dto?.Id} doesn't exist in the system."); + throw; + } + } + + private void ModelValidation(ClassDto dto) + { + if (repository.Get(where: x => x.Title == dto.Title).Any()) + { + throw new ArgumentException(localizer["There is already a Class with such a data."]); + } + } + + private void IdValidation(long id) + { + if (!repository.DepartmentExists(id)) + { + throw new ArgumentException(localizer["There is no Department with such id."]); + } + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/DepartmentService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/DepartmentService.cs new file mode 100644 index 0000000000..bab6b42f9a --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/DepartmentService.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Localization; +using OutOfSchool.Services.Models; +using OutOfSchool.Services.Repository; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using Serilog; + +namespace OutOfSchool.WebApi.Services +{ + /// + /// Implements the interface with CRUD functionality for Department entity. + /// + public class DepartmentService : IDepartmentService + { + private readonly IDepartmentRepository repository; + private readonly ILogger logger; + private readonly IStringLocalizer localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Repository for some entity. + /// Logger. + /// Localizer. + public DepartmentService(IDepartmentRepository entityRepository, ILogger logger, IStringLocalizer localizer) + { + this.localizer = localizer; + this.repository = entityRepository; + this.logger = logger; + } + + /// + public async Task Create(DepartmentDto dto) + { + logger.Information("Department creating was started."); + + var department = dto.ToDomain(); + + ModelValidation(dto); + + var newDepartment = await repository.Create(department).ConfigureAwait(false); + + logger.Information($"Department with Id = {newDepartment?.Id} created successfully."); + + return newDepartment.ToModel(); + } + + /// + public async Task Delete(long id) + { + logger.Information($"Deleting Department with Id = {id} started."); + + var entity = new Department() { Id = id }; + + try + { + await repository.Delete(entity).ConfigureAwait(false); + + logger.Information($"Department with Id = {id} succesfully deleted."); + } + catch (DbUpdateConcurrencyException) + { + logger.Error($"Deleting failed. Department with Id = {id} doesn't exist in the system."); + throw; + } + } + + /// + public async Task> GetAll() + { + logger.Information("Getting all Departments started."); + + var departments = await this.repository.GetAll().ConfigureAwait(false); + + logger.Information(!departments.Any() + ? "Department table is empty." + : $"All {departments.Count()} records were successfully received from the Department table"); + + return departments.Select(entity => entity.ToModel()).ToList(); + } + + /// + public async Task GetById(long id) + { + logger.Information($"Getting Department by Id started. Looking Id = {id}."); + + var department = await repository.GetById((int)id).ConfigureAwait(false); + + if (department == null) + { + throw new ArgumentOutOfRangeException( + nameof(id), + localizer["The id cannot be greater than number of table entities."]); + } + + logger.Information($"Successfully got a Department with Id = {id}."); + + return department.ToModel(); + } + + /// + public async Task> GetByDirectionId(long id) + { + logger.Information($"Getting Department by DirectionId started. Looking DirectionId = {id}."); + + IdValidation(id); + + var departments = await this.repository.Get(where: x => x.DirectionId == id).ToListAsync().ConfigureAwait(false); + + logger.Information(!departments.Any() + ? $"There is no Deparment with DirectionId = {id}." + : $"All {departments.Count} records were successfully received from the Department table"); + + return departments.Select(entity => entity.ToModel()).ToList(); + } + + /// + public async Task Update(DepartmentDto dto) + { + logger.Information($"Updating the Department with Id = {dto?.Id} started."); + + ModelValidation(dto); + + try + { + var department = await repository.Update(dto.ToDomain()).ConfigureAwait(false); + + logger.Information($"Department with Id = {department?.Id} updated succesfully."); + + return department.ToModel(); + } + catch (DbUpdateConcurrencyException) + { + logger.Error($"Updating failed. Department with Id = {dto?.Id} doesn't exist in the system."); + throw; + } + } + + private void ModelValidation(DepartmentDto dto) + { + if (dto == null) + { + throw new ArgumentException(localizer["Object cannot be null."]); + } + + if (!repository.DirectionExists(dto.DirectionId)) + { + throw new ArgumentException(localizer["There is no Direction with such id."]); + } + + if (repository.SameExists(dto.ToDomain())) + { + throw new ArgumentException(localizer["There is already a Department with such a data."]); + } + } + + private void IdValidation(long id) + { + if (!repository.DirectionExists(id)) + { + throw new ArgumentException(localizer["There is no Department with such id."]); + } + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/DirectionService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/DirectionService.cs new file mode 100644 index 0000000000..3bcdae10c6 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/DirectionService.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Localization; +using OutOfSchool.Services.Models; +using OutOfSchool.Services.Repository; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using Serilog; + +namespace OutOfSchool.WebApi.Services +{ + /// + /// Implements the interface with CRUD functionality for Direction entity. + /// + public class DirectionService : IDirectionService + { + private readonly IEntityRepository repository; + private readonly ILogger logger; + private readonly IStringLocalizer localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Repository for Direction entity. + /// Logger. + /// Localizer. + public DirectionService(IEntityRepository entityRepository, ILogger logger, IStringLocalizer localizer) + { + this.localizer = localizer; + this.repository = entityRepository; + this.logger = logger; + } + + /// + public async Task Create(DirectionDto dto) + { + logger.Information("Direction creating was started."); + + var direction = dto.ToDomain(); + + DirectionValidation(dto); + + var newDirection = await repository.Create(direction).ConfigureAwait(false); + + logger.Information($"Direction with Id = {newDirection?.Id} created successfully."); + + return newDirection.ToModel(); + } + + /// + public async Task Delete(long id) + { + logger.Information($"Deleting Direction with Id = {id} started."); + + var entity = new Direction() { Id = id }; + + try + { + await repository.Delete(entity).ConfigureAwait(false); + + logger.Information($"Direction with Id = {id} succesfully deleted."); + } + catch (DbUpdateConcurrencyException) + { + logger.Error($"Deleting failed. Direction with Id = {id} doesn't exist in the system."); + throw; + } + } + + /// + public async Task> GetAll() + { + logger.Information("Getting all Directions started."); + + var directions = await this.repository.GetAll().ConfigureAwait(false); + + logger.Information(!directions.Any() + ? "Direction table is empty." + : $"All {directions.Count()} records were successfully received from the Direction table."); + + return directions.Select(entity => entity.ToModel()).ToList(); + } + + /// + public async Task GetById(long id) + { + logger.Information($"Getting Direction by Id started. Looking Id = {id}."); + + var direction = await repository.GetById((int)id).ConfigureAwait(false); + + if (direction == null) + { + throw new ArgumentOutOfRangeException( + nameof(id), + localizer["The id cannot be greater than number of table entities."]); + } + + logger.Information($"Successfully got a Direction with Id = {id}."); + + return direction.ToModel(); + } + + /// + public async Task Update(DirectionDto dto) + { + logger.Information($"Updating Direction with Id = {dto?.Id} started."); + + try + { + var direction = await repository.Update(dto.ToDomain()).ConfigureAwait(false); + + logger.Information($"Direction with Id = {direction?.Id} updated succesfully."); + + return direction.ToModel(); + } + catch (DbUpdateConcurrencyException) + { + logger.Error($"Updating failed. Direction with Id = {dto?.Id} doesn't exist in the system."); + throw; + } + } + + private void DirectionValidation(DirectionDto dto) + { + if (repository.Get(where: x => x.Title == dto.Title).Any()) + { + throw new ArgumentException(localizer["There is already a Direction with such a data."]); + } + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ICategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ICategoryService.cs deleted file mode 100644 index 4cd1cc7bcb..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ICategoryService.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using OutOfSchool.WebApi.Models; - -namespace OutOfSchool.WebApi.Services -{ - /// - /// Defines interface for CRUD functionality for Category entity. - /// - public interface ICategoryService - { - /// - /// Add new Category to the DB. - /// - /// CategoryDTO element. - /// A representing the result of the asynchronous operation. - Task Create(CategoryDTO dto); - - /// - /// Get all Category objects from DB. - /// - /// List of Category objects. - Task> GetAll(); - - /// - /// To recieve the Category object with define id. - /// - /// Key in the table. - /// Category object. - Task GetById(long id); - - /// - /// To Update our object in DB. - /// - /// Category with new properties. - /// A representing the result of the asynchronous operation. - Task Update(CategoryDTO dto); - - /// - /// To delete the object from DB. - /// - /// Key in table. - /// A representing the result of the asynchronous operation. - Task Delete(long id); - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/IClassService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/IClassService.cs new file mode 100644 index 0000000000..4624b855d1 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/IClassService.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using OutOfSchool.WebApi.Models; + +namespace OutOfSchool.WebApi.Services +{ + /// + /// Defines interface for CRUD functionality for Class entity. + /// + public interface IClassService + { + /// + /// Add new Class to the DB. + /// + /// ClassDto entity. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was created. + Task Create(ClassDto dto); + + /// + /// Get all Class objects from DB. + /// + /// A representing the result of the asynchronous operation. + /// The task result contains a List of that were found. + Task> GetAll(); + + /// + /// To recieve the Class object with define id. + /// + /// Key in the table. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was found. + Task GetById(long id); + + /// + /// To recieve the Class list with defined DepartmentId. + /// + /// Key of the Department in the table. + /// A representing the result of the asynchronous operation. + /// The task result contains a List of that were found. + Task> GetByDepartmentId(long id); + + /// + /// To Update our object in DB. + /// + /// Class with new properties. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was updated. + Task Update(ClassDto dto); + + /// + /// To delete the object from DB. + /// + /// Key of the Class in table. + /// A representing the result of the asynchronous operation. + Task Delete(long id); + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/IDepartmentService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/IDepartmentService.cs new file mode 100644 index 0000000000..aefcf618cd --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/IDepartmentService.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using OutOfSchool.WebApi.Models; + +namespace OutOfSchool.WebApi.Services +{ + /// + /// Defines interface for CRUD functionality for Department entity. + /// + public interface IDepartmentService + { + /// + /// Add new Department to the DB. + /// + /// DepartmentDto element. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was created. + Task Create(DepartmentDto dto); + + /// + /// Get all Department objects from DB. + /// + /// A representing the result of the asynchronous operation. + /// The task result contains a List of that were found. + Task> GetAll(); + + /// + /// To recieve the Department object with define id. + /// + /// Key in the table. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was found. + Task GetById(long id); + + /// + /// To recieve the Department list with define Direction id. + /// + /// Key of the Direction in the table. + /// A representing the result of the asynchronous operation. + /// The task result contains a List of that were found. + Task> GetByDirectionId(long id); + + /// + /// To Update our object in DB. + /// + /// Department with new properties. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was updated. + Task Update(DepartmentDto dto); + + /// + /// To delete the object from DB. + /// + /// Key of the Department in table. + /// A representing the result of the asynchronous operation. + Task Delete(long id); + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/IDirectionService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/IDirectionService.cs new file mode 100644 index 0000000000..a0c92925ad --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/IDirectionService.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using OutOfSchool.WebApi.Models; + +namespace OutOfSchool.WebApi.Services +{ + /// + /// Defines interface for CRUD functionality for Direction entity. + /// + public interface IDirectionService + { + /// + /// Add new Direction to the DB. + /// + /// DirectionDto element. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was created. + Task Create(DirectionDto dto); + + /// + /// Get all Direction objects from DB. + /// + /// A representing the result of the asynchronous operation. + /// The task result contains a List of that were found. + Task> GetAll(); + + /// + /// To recieve the Direction object with define id. + /// + /// Key in the table. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was found. + Task GetById(long id); + + /// + /// To Update our object in DB. + /// + /// Direction with new properties. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was updated. + Task Update(DirectionDto dto); + + /// + /// To delete the object from DB. + /// + /// Key of the Direction in table. + /// A representing the result of the asynchronous operation. + Task Delete(long id); + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ISubcategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ISubcategoryService.cs deleted file mode 100644 index fc01c31f42..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ISubcategoryService.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using OutOfSchool.WebApi.Models; - -namespace OutOfSchool.WebApi.Services -{ - /// - /// Defines interface for CRUD functionality for Category entity. - /// - public interface ISubcategoryService - { - /// - /// Add new Category to the DB. - /// - /// CategoryDTO element. - /// A representing the result of the asynchronous operation. - Task Create(SubcategoryDTO dto); - - /// - /// Get all Category objects from DB. - /// - /// List of Category objects. - Task> GetAll(); - - /// - /// To recieve the Category object with define id. - /// - /// Key in the table. - /// Category object. - Task GetById(long id); - - /// - /// To recieve the Subcategory list with define Categoryid. - /// - /// Key in the table. - /// List of subcategories. - Task> GetByCategoryId(long id); - - /// - /// To Update our object in DB. - /// - /// Category with new properties. - /// A representing the result of the asynchronous operation. - Task Update(SubcategoryDTO dto); - - /// - /// To delete the object from DB. - /// - /// Key in table. - /// A representing the result of the asynchronous operation. - Task Delete(long id); - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ISubsubcategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ISubsubcategoryService.cs deleted file mode 100644 index 26378b0c25..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ISubsubcategoryService.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using OutOfSchool.WebApi.Models; - -namespace OutOfSchool.WebApi.Services -{ - /// - /// Defines interface for CRUD functionality for Category entity. - /// - public interface ISubsubcategoryService - { - /// - /// Add new Category to the DB. - /// - /// CategoryDTO element. - /// A representing the result of the asynchronous operation. - Task Create(SubsubcategoryDTO dto); - - /// - /// Get all Category objects from DB. - /// - /// List of Category objects. - Task> GetAll(); - - /// - /// To recieve the Category object with define id. - /// - /// Key in the table. - /// Category object. - Task GetById(long id); - - /// - /// To recieve the Subsubcategory list with defined SubcategoryId. - /// - /// Key in the table. - /// List of subsubcategories. - Task> GetBySubcategoryId(long id); - - /// - /// To Update our object in DB. - /// - /// Category with new properties. - /// A representing the result of the asynchronous operation. - Task Update(SubsubcategoryDTO dto); - - /// - /// To delete the object from DB. - /// - /// Key in table. - /// A representing the result of the asynchronous operation. - Task Delete(long id); - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs index d227180829..9333b922b5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs @@ -48,7 +48,7 @@ public async Task Create(ProviderDto dto) { logger.Information("Provider creating was started."); - if (providerRepository.Exists(dto.ToDomain())) + if (providerRepository.SameExists(dto.ToDomain())) { throw new ArgumentException(localizer["There is already a provider with such a data."]); } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs deleted file mode 100644 index ea87b921db..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs +++ /dev/null @@ -1,170 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; -using OutOfSchool.Services.Models; -using OutOfSchool.Services.Repository; -using OutOfSchool.WebApi.Extensions; -using OutOfSchool.WebApi.Models; -using Serilog; - -namespace OutOfSchool.WebApi.Services -{ - /// - /// SubcategoryService. - /// - public class SubcategoryService : ISubcategoryService - { - private readonly ISubcategoryRepository repository; - private readonly ILogger logger; - private readonly IStringLocalizer localizer; - - /// - /// Initializes a new instance of the class. - /// - /// Repository for some entity. - /// Logger. - /// Localizer. - public SubcategoryService(ISubcategoryRepository entityRepository, ILogger logger, IStringLocalizer localizer) - { - this.localizer = localizer; - this.repository = entityRepository; - this.logger = logger; - } - - /// - public async Task Create(SubcategoryDTO dto) - { - logger.Information("Subcategory creating was started."); - - var category = dto.ToDomain(); - - ModelValidation(dto); - - var newCategory = await repository.Create(category).ConfigureAwait(false); - - logger.Information($"Subcategory with Id = {newCategory?.Id} created successfully."); - - return newCategory.ToModel(); - } - - /// - public async Task Delete(long id) - { - logger.Information($"Deleting Subcategory with Id = {id} started."); - - var entity = new Subcategory() { Id = id }; - - try - { - await repository.Delete(entity).ConfigureAwait(false); - - logger.Information($"Subcategory with Id = {id} succesfully deleted."); - } - catch (DbUpdateConcurrencyException) - { - logger.Error($"Deleting failed. Subcategory with Id = {id} doesn't exist in the system."); - throw; - } - } - - /// - public async Task> GetAll() - { - logger.Information("Getting all Subcategories started."); - - var categories = await this.repository.GetAll().ConfigureAwait(false); - - logger.Information(!categories.Any() - ? "Subcategory table is empty." - : $"All {categories.Count()} records were successfully received from the Subcategory table"); - - return categories.Select(parent => parent.ToModel()).ToList(); - } - - /// - public async Task GetById(long id) - { - logger.Information($"Getting Subcategory by Id started. Looking Id = {id}."); - - var category = await repository.GetById((int)id).ConfigureAwait(false); - - if (category == null) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be greater than number of table entities."]); - } - - logger.Information($"Successfully got a Subcategory with Id = {id}."); - - return category.ToModel(); - } - - /// - public async Task> GetByCategoryId(long id) - { - logger.Information($"Getting Subcategory by CategoryId started. Looking CategoryId = {id}."); - - IdValidation(id); - - var categories = await this.repository.Get(where: x => x.CategoryId == id).ToListAsync().ConfigureAwait(false); - - logger.Information(!categories.Any() - ? $"There aren't Subcategories for Category with Id = {id}." - : $"All {categories.Count} records were successfully received from the Subcategory table"); - - return categories.Select(parent => parent.ToModel()).ToList(); - } - - /// - public async Task Update(SubcategoryDTO dto) - { - logger.Information($"Updating Subcategory with Id = {dto?.Id} started."); - - ModelValidation(dto); - - try - { - var category = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - - logger.Information($"Subcategory with Id = {category?.Id} updated succesfully."); - - return category.ToModel(); - } - catch (DbUpdateConcurrencyException) - { - logger.Error($"Updating failed. Subcategory with Id = {dto?.Id} doesn't exist in the system."); - throw; - } - } - - private void ModelValidation(SubcategoryDTO dto) - { - if (dto == null) - { - throw new ArgumentException(localizer["Object cannot be null."]); - } - - if (!repository.CategoryExists(dto.CategoryId)) - { - throw new ArgumentException(localizer["There is no category with such id."]); - } - - if (repository.SameExists(dto.ToDomain())) - { - throw new ArgumentException(localizer["There is already a subcategory with such a data."]); - } - } - - private void IdValidation(long id) - { - if (!repository.CategoryExists(id)) - { - throw new ArgumentException(localizer["There is no subcategory with such id."]); - } - } - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs deleted file mode 100644 index b055e92fb8..0000000000 --- a/OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; -using OutOfSchool.Services.Models; -using OutOfSchool.Services.Repository; -using OutOfSchool.WebApi.Extensions; -using OutOfSchool.WebApi.Models; -using Serilog; - -namespace OutOfSchool.WebApi.Services -{ - /// - /// SubsubcategoryService. - /// - public class SubsubcategoryService : ISubsubcategoryService - { - private readonly ISubsubcategoryRepository repository; - private readonly ILogger logger; - private readonly IStringLocalizer localizer; - - /// - /// Initializes a new instance of the class. - /// - /// Repository for some entity. - /// Logger. - /// Localizer. - public SubsubcategoryService(ISubsubcategoryRepository entityRepository, ILogger logger, IStringLocalizer localizer) - { - this.localizer = localizer; - this.repository = entityRepository; - this.logger = logger; - } - - /// - public async Task Create(SubsubcategoryDTO dto) - { - logger.Information("Subsubategory creating was started."); - - var category = dto.ToDomain(); - - ModelValidation(dto); - - var newCategory = await repository.Create(category).ConfigureAwait(false); - - logger.Information($"Subsubcategory with Id = {newCategory?.Id} created successfully."); - - return newCategory.ToModel(); - } - - /// - public async Task Delete(long id) - { - logger.Information($"Deleting Subsubcategory with Id = {id} started."); - - var entity = new Subsubcategory() { Id = id }; - - try - { - await repository.Delete(entity).ConfigureAwait(false); - - logger.Information($"Subsubcategory with Id = {id} succesfully deleted."); - } - catch (DbUpdateConcurrencyException) - { - logger.Error($"Deleting failed. Subsubcategory with such Id = {id} doesn't exist in the system."); - throw; - } - } - - /// - public async Task> GetAll() - { - logger.Information("Getting all Subsubcategories started."); - - var categories = await this.repository.GetAll().ConfigureAwait(false); - - logger.Information(!categories.Any() - ? "Subsubcategory table is empty." - : $"All {categories.Count()} records were successfully received from the Subsubcategory table"); - - return categories.Select(parent => parent.ToModel()).ToList(); - } - - /// - public async Task GetById(long id) - { - logger.Information($"Getting Subsubcategory by Id started. Looking Id = {id}."); - - var category = await repository.GetById((int)id).ConfigureAwait(false); - - if (category == null) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be greater than number of table entities."]); - } - - logger.Information($"Successfully got a Subsubcategory with Id = {id}."); - - return category.ToModel(); - } - - /// - public async Task> GetBySubcategoryId(long id) - { - logger.Information($"Getting Subsubcategory by SubcategoryId started. Looking SubcategoryId = {id}."); - - IdValidation(id); - - var categories = await this.repository.Get(where: x => x.SubcategoryId == id).ToListAsync().ConfigureAwait(false); - - logger.Information(!categories.Any() - ? $"There aren't Subsubcategories for Subcategory with Id = {id}." - : $"All {categories.Count} records were successfully received from the Subsubcategory table"); - - return categories.Select(parent => parent.ToModel()).ToList(); - } - - /// - public async Task Update(SubsubcategoryDTO dto) - { - logger.Information($"Updating Subsubcategory with Id = {dto?.Id} started."); - - try - { - var category = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - - logger.Information($"Subsubcategory with Id = {category?.Id} updated succesfully."); - - return category.ToModel(); - } - catch (DbUpdateConcurrencyException) - { - logger.Error($"Updating failed. Subsubcategory with Id = {dto?.Id} doesn't exist in the system."); - throw; - } - } - - private void ModelValidation(SubsubcategoryDTO dto) - { - if (repository.Get(where: x => x.Title == dto.Title).Any()) - { - throw new ArgumentException(localizer["There is already a subsubcategory with such a data."]); - } - } - - private void IdValidation(long id) - { - if (!repository.SubcategoryExists(id)) - { - throw new ArgumentException(localizer["There is no subcategory with such id."]); - } - } - } -} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs index a873f0fd9b..fcb80a7595 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs @@ -21,7 +21,7 @@ namespace OutOfSchool.WebApi.Services public class WorkshopService : IWorkshopService { private readonly IWorkshopRepository workshopRepository; - private readonly ISubsubcategoryRepository subsubcategoryRepository; + private readonly IClassRepository classRepository; private readonly IEntityRepository teacherRepository; private readonly IEntityRepository
addressRepository; private readonly IRatingService ratingService; @@ -33,7 +33,7 @@ public class WorkshopService : IWorkshopService /// Initializes a new instance of the class. /// /// Repository for Workshop entity. - /// Repository for Subsubcategory entity. + /// Repository for Class entity. /// Repository for Teacher. /// Repository for Address. /// Rating service. @@ -41,7 +41,7 @@ public class WorkshopService : IWorkshopService /// Localizer. public WorkshopService( IWorkshopRepository workshopRepository, - ISubsubcategoryRepository subsubcategoryRepository, + IClassRepository classRepository, IEntityRepository teacherRepository, IEntityRepository
addressRepository, IRatingService ratingService, @@ -49,7 +49,7 @@ public WorkshopService( IStringLocalizer localizer) { this.workshopRepository = workshopRepository; - this.subsubcategoryRepository = subsubcategoryRepository; + this.classRepository = classRepository; this.teacherRepository = teacherRepository; this.addressRepository = addressRepository; this.ratingService = ratingService; @@ -63,8 +63,8 @@ public async Task Create(WorkshopDTO dto) { logger.Information("Workshop creating was started."); - // In case if CategoryId and SubcategoryId does not match SubsubcategoryId - await this.FillCategoriesFields(dto).ConfigureAwait(false); + // In case if DirectionId and DepartmentId does not match ClassId + await this.FillDirectionsFields(dto).ConfigureAwait(false); Func> operation = async () => await workshopRepository.Create(dto.ToDomain()).ConfigureAwait(false); @@ -150,8 +150,8 @@ public async Task Update(WorkshopDTO dto) try { - // In case if CategoryId and SubcategoryId does not match SubsubcategoryId - await this.FillCategoriesFields(dto).ConfigureAwait(false); + // In case if DirectionId and DepartmentId does not match ClassId + await this.FillDirectionsFields(dto).ConfigureAwait(false); // In case if AddressId was changed. AddresId is one and unique for workshop. dto.AddressId = workshop.AddressId; @@ -294,34 +294,34 @@ private Expression> PredicateBuild(WorkshopFilter filter) predicate = predicate.And(x => x.WithDisabilityOptions == filter.Disability); - if (filter.Categories != null) + if (filter.Directions != null) { var tempPredicate = PredicateBuilder.True(); - foreach (var category in filter.Categories) + foreach (var direction in filter.Directions) { - tempPredicate = tempPredicate.Or(x => x.Subsubcategory.Subcategory.Category.Title == category); + tempPredicate = tempPredicate.Or(x => x.Class.Department.Direction.Title == direction); } predicate = predicate.And(tempPredicate); } - if (filter.Subcategories != null) + if (filter.Departments != null) { var tempPredicate = PredicateBuilder.True(); - foreach (var subcategory in filter.Subcategories) + foreach (var department in filter.Departments) { - tempPredicate = tempPredicate.Or(x => x.Subsubcategory.Subcategory.Title == subcategory); + tempPredicate = tempPredicate.Or(x => x.Class.Department.Title == department); } predicate = predicate.And(tempPredicate); } - if (filter.Subsubcategories != null) + if (filter.Classes != null) { var tempPredicate = PredicateBuilder.True(); - foreach (var subsubcategory in filter.Subsubcategories) + foreach (var classEntity in filter.Classes) { - tempPredicate = tempPredicate.Or(x => x.Subsubcategory.Title == subsubcategory); + tempPredicate = tempPredicate.Or(x => x.Class.Title == classEntity); } predicate = predicate.And(tempPredicate); @@ -331,21 +331,21 @@ private Expression> PredicateBuild(WorkshopFilter filter) } /// - /// Set properties of the given WorkshopDTO with certain data: categoryId and SubctegoryId are set with data according to found Subsubcategory entity. + /// Set properties of the given WorkshopDTO with certain data: DirectionId and DepartmentId are set with data according to the found Class entity. /// /// WorkshopDTO to fill. /// A representing the result of the asynchronous operation. - /// If Subsubctegory was not found. - private async Task FillCategoriesFields(WorkshopDTO dto) + /// If Class was not found. + private async Task FillDirectionsFields(WorkshopDTO dto) { - var sscategory = await subsubcategoryRepository.GetById(dto.SubsubcategoryId).ConfigureAwait(false); - if (sscategory is null) + var classEntity = await classRepository.GetById(dto.ClassId).ConfigureAwait(false); + if (classEntity is null) { - throw new ArgumentOutOfRangeException($"There is no Subsubcategory with id:{dto.SubsubcategoryId}"); + throw new ArgumentOutOfRangeException($"There is no Class with id:{dto.ClassId}"); } - dto.SubcategoryId = sscategory.SubcategoryId; - dto.CategoryId = sscategory.Subcategory.CategoryId; + dto.DepartmentId = classEntity.DepartmentId; + dto.DirectionId = classEntity.Department.DirectionId; } private void CompareTwoListsOfTeachers( diff --git a/OutOfSchool/OutOfSchool.WebApi/Startup.cs b/OutOfSchool/OutOfSchool.WebApi/Startup.cs index 6e27481171..45eeb145fc 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Startup.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Startup.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Localization; +using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -102,14 +103,14 @@ public void ConfigureServices(IServiceCollection services) // entities services services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -117,18 +118,18 @@ public void ConfigureServices(IServiceCollection services) // entities repositories services.AddTransient, EntityRepository
>(); services.AddTransient, EntityRepository>(); - services.AddTransient, EntityRepository>(); services.AddTransient, EntityRepository>(); + services.AddTransient, EntityRepository>(); services.AddTransient, EntityRepository>(); services.AddTransient, EntityRepository>(); services.AddTransient, EntityRepository>(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddSingleton(Log.Logger); @@ -140,6 +141,26 @@ public void ConfigureServices(IServiceCollection services) var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); + + c.TagActionsBy(api => + { + // If there is a groupName that is specified, then use it. + if (api.GroupName != null) + { + return new[] { api.GroupName }; + } + + // else use the controller name which is the default used by Swashbuckle. + var controllerActionDescriptor = api.ActionDescriptor as ControllerActionDescriptor; + if (controllerActionDescriptor != null) + { + return new[] { controllerActionDescriptor.ControllerName }; + } + + throw new InvalidOperationException("Unable to determine tag for endpoint."); + }); + + c.DocInclusionPredicate((name, api) => true); }); services.AddAutoMapper(typeof(Startup));