Changeset 3b395c5


Ignore:
Timestamp:
10/21/21 19:17:43 (3 years ago)
Author:
Стојков Марко <mst@…>
Branches:
dev
Children:
31c006c, 45cf412
Parents:
9885bee (diff), 95d80e4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged feature unit of work into dev

Location:
src
Files:
3 added
15 edited

Legend:

Unmodified
Added
Removed
  • src/Clients/Angular/finki-chattery/src/app/shared-app/components/components.ts

    r9885bee r3b395c5  
    66import { StudentCardComponent } from './question/student-card/student-card.component';
    77
    8 export const COMPONENTS: any[] = [ButtonComponent, FormErrorComponent, FileUploadComponent, QuestionPreviewComponent, VoteComponent, StudentCardComponent];
     8export const COMPONENTS: any[] = [
     9  ButtonComponent,
     10  FormErrorComponent,
     11  FileUploadComponent,
     12  QuestionPreviewComponent,
     13  VoteComponent,
     14  StudentCardComponent
     15];
  • src/Clients/Angular/finki-chattery/src/app/shared-app/directives/directives.ts

    r9885bee r3b395c5  
    1 import { HandleInputFormErrorsDirective, HoverElevationDirective, LoaderDirective, HandleSelectFormErrorsDirective, ShareLinkDirective } from '.';
     1import {
     2  HandleInputFormErrorsDirective,
     3  HoverElevationDirective,
     4  LoaderDirective,
     5  HandleSelectFormErrorsDirective,
     6  ShareLinkDirective
     7} from '.';
    28
    3 export const DIRECTIVES: any[] = [HandleInputFormErrorsDirective, LoaderDirective, HoverElevationDirective, HandleSelectFormErrorsDirective, ShareLinkDirective];
     9export const DIRECTIVES: any[] = [
     10  HandleInputFormErrorsDirective,
     11  LoaderDirective,
     12  HoverElevationDirective,
     13  HandleSelectFormErrorsDirective,
     14  ShareLinkDirective
     15];
  • src/FinkiChattery/FinkiChattery.Api/Services/RegisterServices.cs

    r9885bee r3b395c5  
    99using FinkiChattery.Persistence.Models;
    1010using FinkiChattery.Persistence.Repositories;
     11using FinkiChattery.Persistence.UnitOfWork;
    1112using FinkiChattery.Queries.Questioning;
    1213using Hangfire;
     
    101102        }
    102103
    103         public static void AddRepos(this IServiceCollection services)
     104        public static void AddUnitOfWork(this IServiceCollection services)
    104105        {
    105             services.AddScoped<ICategoriesRepo, CategoriesRepo>();
    106             services.AddScoped<ITeamRepo, TeamRepo>();
    107             services.AddScoped<IQuestionRepo, QuestionRepo>();
    108             services.AddScoped<IStudentRepo, StudentRepo>();
     106            services.AddScoped<IUnitOfWork, UnitOfWork>();
    109107        }
    110108
  • src/FinkiChattery/FinkiChattery.Api/Startup.cs

    r9885bee r3b395c5  
    3535            services.AddOriginUrlSettings();
    3636            services.AddCurrentUser();
    37             services.AddRepos();
     37            services.AddUnitOfWork();
    3838            services.AddAwsClient(Configuration);
    3939            services.AddHangfireService(Configuration);
  • src/FinkiChattery/FinkiChattery.Commands/Questioning/AskQuestion/AskQuestionCommand.cs

    r9885bee r3b395c5  
    11using FinkiChattery.Common.Mediator.Contracs;
    22using FinkiChattery.Common.User;
    3 using FinkiChattery.Persistence.Context;
    43using FinkiChattery.Persistence.Models;
    5 using FinkiChattery.Persistence.Repositories;
     4using FinkiChattery.Persistence.UnitOfWork;
    65using System;
    76using System.Collections.Generic;
     
    2726    public class AskQuestionHandler : ICommandHandler<AskQuestionCommand, Guid>
    2827    {
    29         public AskQuestionHandler(ApplicationDbContext dbContext, ICategoriesRepo categoriesRepo, IStudentRepo studentRepo, ICurrentUser currentUser)
     28        public AskQuestionHandler(IUnitOfWork unitOfWork, ICurrentUser currentUser)
    3029        {
    31             DbContext = dbContext;
    32             CategoriesRepo = categoriesRepo;
    33             StudentRepo = studentRepo;
     30            UnitOfWork = unitOfWork;
    3431            CurrentUser = currentUser;
    3532        }
    3633
    37         public ApplicationDbContext DbContext { get; }
    38         public ICategoriesRepo CategoriesRepo { get; }
    39         public IStudentRepo StudentRepo { get; }
     34        public IUnitOfWork UnitOfWork { get; }
    4035        public ICurrentUser CurrentUser { get; }
    4136
    4237        public async Task<Guid> Handle(AskQuestionCommand request, CancellationToken cancellationToken)
    4338        {
    44             var questionCategories = await CategoriesRepo.GetCategories(request.Categories);
    45             var currentStudent = await StudentRepo.GetStudent(CurrentUser.Id);
     39            var questionCategories = await UnitOfWork.Categories.GetCategories(request.Categories);
     40            var currentStudent = await UnitOfWork.Students.GetStudent(CurrentUser.Id);
    4641
    4742            var questionDatabaseEntity = new Question()
     
    6055            }
    6156
    62             DbContext.Questions.Add(questionDatabaseEntity);
    63             await DbContext.SaveChangesAsync();
     57            UnitOfWork.Questions.Add(questionDatabaseEntity);
     58            await UnitOfWork.SaveAsync();
    6459            return questionDatabaseEntity.Uid;
    6560        }
  • src/FinkiChattery/FinkiChattery.Commands/Questioning/AskQuestion/AskQuestionValidator.cs

    r9885bee r3b395c5  
    11using FinkiChattery.Commands.Questioning.Validators;
    2 using FinkiChattery.Persistence.Repositories;
     2using FinkiChattery.Persistence.UnitOfWork;
    33using FluentValidation;
    44
     
    77    public class AskQuestionValidator : AbstractValidator<AskQuestionCommand>
    88    {
    9         public AskQuestionValidator(ICategoriesRepo categoriesRepo)
     9        public AskQuestionValidator(IUnitOfWork unitOfWork)
    1010        {
    1111            RuleFor(x => x.Title).QuestionTitleValidate();
    1212            RuleFor(x => x.Text).QuestionTextValidate();
    13             RuleFor(x => x.Categories).Cascade(CascadeMode.Stop).ListNotNull().SetValidator(new CategoriesUidsExist(categoriesRepo));
     13            RuleFor(x => x.Categories).Cascade(CascadeMode.Stop).ListNotNull().SetValidator(new CategoriesUidsExist(unitOfWork));
    1414        }
    1515    }
  • src/FinkiChattery/FinkiChattery.Commands/Questioning/Validators/CategoriesUidsExist.cs

    r9885bee r3b395c5  
    11using FinkiChattery.Persistence.Repositories;
     2using FinkiChattery.Persistence.UnitOfWork;
    23using FluentValidation.Validators;
    34using System;
     
    1011    public class CategoriesUidsExist : AsyncValidatorBase
    1112    {
    12         public CategoriesUidsExist(ICategoriesRepo categoriesRepo)
     13        public CategoriesUidsExist(IUnitOfWork unitOfWork)
    1314        {
    14             CategoriesRepo = categoriesRepo;
     15            UnitOfWork = unitOfWork;
    1516        }
    1617
    17         public ICategoriesRepo CategoriesRepo { get; }
     18        public IUnitOfWork UnitOfWork { get; }
    1819
    1920        protected override async Task<bool> IsValidAsync(PropertyValidatorContext context, CancellationToken cancellation)
     
    2122            var categoriesUids = (IEnumerable<Guid>)context.PropertyValue;
    2223
    23             return await CategoriesRepo.CategoriesExist(categoriesUids);
     24            return await UnitOfWork.Categories.CategoriesExist(categoriesUids);
    2425        }
    2526
  • src/FinkiChattery/FinkiChattery.Commands/Questioning/Validators/TeamWithUidExist.cs

    r9885bee r3b395c5  
    1 using FinkiChattery.Persistence.Repositories;
     1using FinkiChattery.Persistence.UnitOfWork;
    22using FluentValidation.Validators;
    33using System;
     
    99    public class TeamWithUidExist : AsyncValidatorBase
    1010    {
    11         public TeamWithUidExist(ITeamRepo teamRepo)
     11        public TeamWithUidExist(IUnitOfWork unitOfWork)
    1212        {
    13             TeamRepo = teamRepo;
     13            UnitOfWork = unitOfWork;
    1414        }
    1515
    16         public ITeamRepo TeamRepo { get; }
     16        public IUnitOfWork UnitOfWork { get; }
    1717
    1818        protected override async Task<bool> IsValidAsync(PropertyValidatorContext context, CancellationToken cancellation)
    1919        {
    2020            var teamUid = (Guid)context.PropertyValue;
    21             return await TeamRepo.TeamWithUidExists(teamUid);       
     21            return await UnitOfWork.Teams.TeamWithUidExists(teamUid);
    2222        }
    2323
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Base/IRepository.cs

    r9885bee r3b395c5  
    1313        Task<T> GetByIdAsync(int id);
    1414
    15         Task Add(T entity);
     15        void Add(T entity);
    1616    }
    1717}
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Base/Repository.cs

    r9885bee r3b395c5  
    2929        }
    3030
    31         public async Task Add(T entity)
     31        public void Add(T entity)
    3232        {
    3333            DbSet.Add(entity);
    34             await DbContext.SaveChangesAsync();
    3534        }
    3635
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/ICategoriesRepo.cs

    r9885bee r3b395c5  
    88namespace FinkiChattery.Persistence.Repositories
    99{
    10     public interface ICategoriesRepo
     10    public interface ICategoriesRepo : IRepository<Category>
    1111    {
    1212        public Task<bool> CategoriesExist(IEnumerable<Guid> categoriesUids);
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/IQuestionRepo.cs

    r9885bee r3b395c5  
    1 using FinkiChattery.Persistence.Repositories.Contracts;
     1using FinkiChattery.Persistence.Models;
     2using FinkiChattery.Persistence.Repositories.Contracts;
    23using System;
    34using System.Threading.Tasks;
     
    56namespace FinkiChattery.Persistence.Repositories
    67{
    7     public interface IQuestionRepo
     8    public interface IQuestionRepo : IRepository<Question>
    89    {
    910        Task<QuestionStateDto> GetQuestionState(Guid questionUid);
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/IStudentRepo.cs

    r9885bee r3b395c5  
    44namespace FinkiChattery.Persistence.Repositories
    55{
    6     public interface IStudentRepo
     6    public interface IStudentRepo : IRepository<Student>
    77    {
    88        public Task<Student> GetStudent(long applicationUserFk);
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/ITeamRepo.cs

    r9885bee r3b395c5  
    1 using System;
     1using FinkiChattery.Persistence.Models;
     2using System;
    23using System.Threading.Tasks;
    34
    45namespace FinkiChattery.Persistence.Repositories
    56{
    6     public interface ITeamRepo
     7    public interface ITeamRepo : IRepository<Team>
    78    {
    89        public Task<bool> TeamWithUidExists(Guid teamUid);
  • src/FinkiChattery/FinkiChattery.Queries/Questioning/GetQuestionState/GetQuestionStateQuery.cs

    r9885bee r3b395c5  
    11using FinkiChattery.Common.Mediator.Contracs;
    2 using FinkiChattery.Persistence.Repositories;
    32using FinkiChattery.Persistence.Repositories.Contracts;
     3using FinkiChattery.Persistence.UnitOfWork;
    44using System;
    55using System.Threading;
     
    2020    public class GetQuestionStateQueryHandler : IQueryHandler<GetQuestionStateQuery, QuestionStateDto>
    2121    {
    22         public GetQuestionStateQueryHandler(IQuestionRepo questionRepo)
     22        public GetQuestionStateQueryHandler(IUnitOfWork unitOfWork)
    2323        {
    24             QuestionRepo = questionRepo;
     24            UnitOfWork = unitOfWork;
    2525        }
    2626
    27         public IQuestionRepo QuestionRepo { get; }
     27        public IUnitOfWork UnitOfWork { get; }
    2828
    2929        public async Task<QuestionStateDto> Handle(GetQuestionStateQuery request, CancellationToken cancellationToken)
    3030        {
    31             return await QuestionRepo.GetQuestionState(request.QuestionUid);
     31            return await UnitOfWork.Questions.GetQuestionState(request.QuestionUid);
    3232        }
    3333    }
Note: See TracChangeset for help on using the changeset viewer.