Changeset 7f1a891 for src


Ignore:
Timestamp:
10/14/21 17:57:17 (3 years ago)
Author:
Стојков Марко <mst@…>
Branches:
dev
Children:
6d639c9, f9983f5
Parents:
7dd2ea2 (diff), b25b9ea (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 get question endpoint

Location:
src/FinkiChattery
Files:
12 added
18 edited
4 moved

Legend:

Unmodified
Added
Removed
  • src/FinkiChattery/FinkiChattery.Api/Controllers/v1/QuestionsController.cs

    r7dd2ea2 r7f1a891  
    11using FinkiChattery.Api.ApplicationServices.Authentication;
     2using FinkiChattery.Api.ApplicationServices.Questioning;
    23using FinkiChattery.Commands.Questioning;
    34using FinkiChattery.Common.Mediator.Interfaces;
    45using FinkiChattery.Contracts.Questioning;
     6using FinkiChattery.Queries.Questioning;
    57using IdentityServer4.AccessTokenValidation;
    68using Microsoft.AspNetCore.Authorization;
    79using Microsoft.AspNetCore.Mvc;
     10using System;
    811using System.Threading.Tasks;
    912
     
    2932            return Ok();
    3033        }
     34
     35        [HttpGet("{questionUid:Guid}")]
     36        [Authorize]
     37        public async Task<IActionResult> GetQuestionState([FromRoute]Guid questionUid)
     38        {
     39            var questionDto = await MediatorService.SendQueryAsync(new GetQuestionStateQuery(questionUid));
     40            return Ok(questionDto.ToQuestionStateResponse());
     41        }
    3142    }
    3243}
  • src/FinkiChattery/FinkiChattery.Api/FinkiChattery.Api.csproj

    r7dd2ea2 r7f1a891  
    2626    <ProjectReference Include="..\FinkiChattery.Contracts\FinkiChattery.Contracts.csproj" />
    2727    <ProjectReference Include="..\FinkiChattery.Persistence\FinkiChattery.Persistence.csproj" />
     28    <ProjectReference Include="..\FinkiChattery.Queries\FinkiChattery.Queries.csproj" />
    2829  </ItemGroup>
    2930
  • src/FinkiChattery/FinkiChattery.Api/Services/RegisterServices.cs

    r7dd2ea2 r7f1a891  
    99using FinkiChattery.Persistence.Models;
    1010using FinkiChattery.Persistence.Repositories;
     11using FinkiChattery.Queries.Questioning;
    1112using Hangfire;
    1213using Hangfire.SqlServer;
     
    2930            services.AddScoped<IEventService, EventService>();
    3031            services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
    31             services.AddMediatR(typeof(AskQuestionCommand));
     32            services.AddMediatR(typeof(AskQuestionCommand), typeof(GetQuestionStateQuery));
    3233        }
    3334
     
    143144                        services.AddScoped<IStorageService, AwsStorageService>();*/
    144145        }
    145 
    146         // TODO: ADD HANGFIRE AND SCAFOLD DB IN HANGFIREDB
    147146    }
    148147
  • src/FinkiChattery/FinkiChattery.Common/Mediator/Interfaces/IMediatorService.cs

    r7dd2ea2 r7f1a891  
    1111        Task<TResponse> SendAsync<TResponse>(ICommand<TResponse> request);
    1212
     13        Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request, CancellationToken cancellationToken);
     14
     15        Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request);
     16
    1317        Task PublishAsync<TNotification>(TNotification notification) where TNotification : IEvent;
    1418
  • src/FinkiChattery/FinkiChattery.Common/Mediator/MediatorService.cs

    r7dd2ea2 r7f1a891  
    3737            await mediator.Publish(notification, default);
    3838        }
     39
     40        public async Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request, CancellationToken cancellationToken)
     41        {
     42            return await mediator.Send(request, cancellationToken);
     43        }
     44
     45        public async Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request)
     46        {
     47            return await mediator.Send(request);
     48        }
    3949    }
    4050}
  • src/FinkiChattery/FinkiChattery.Database/FinkiChattery.Database.sqlproj

    r7dd2ea2 r7f1a891  
    7070    <Folder Include="dbo\Tables\Student" />
    7171    <Folder Include="FullTextSearch" />
     72    <Folder Include="dbo\Tables\Answer" />
     73    <Folder Include="dbo\Tables\AnswerResponse" />
     74    <Folder Include="dbo\Tables\Question" />
     75    <Folder Include="dbo\Tables\QuestionCategory" />
     76    <Folder Include="Snapshots" />
    7277  </ItemGroup>
    7378  <ItemGroup>
    7479    <Build Include="dbo\Tables\Moderator.sql" />
    7580    <Build Include="dbo\Tables\Teacher.sql" />
    76     <Build Include="dbo\Tables\Question.sql" />
    7781    <Build Include="dbo\Tables\StudentTeam.sql" />
    7882    <Build Include="dbo\Tables\TeacherTeam.sql" />
    79     <Build Include="dbo\Tables\Answer.sql" />
    80     <Build Include="dbo\Tables\QuestionCategory.sql" />
    81     <Build Include="dbo\Tables\AnswerResponse.sql" />
    8283    <Build Include="dbo\Tables\Upvote.sql" />
    8384    <Build Include="dbo\Tables\User\AspNetRoleClaims.sql" />
     
    9192    <Build Include="FullTextSearch\FullTextIndexQuestion.sql" />
    9293    <Build Include="FullTextSearch\QuestionFullTextCatalog.sql" />
     94    <Build Include="dbo\Tables\Question\Question.sql" />
     95    <None Include="dbo\Tables\Question\Question.Debug.Seed.sql" />
     96    <Build Include="dbo\Tables\Answer\Answer.sql" />
     97    <None Include="dbo\Tables\Answer\Answer.Debug.Seed.sql" />
     98    <Build Include="dbo\Tables\AnswerResponse\AnswerResponse.sql" />
     99    <None Include="dbo\Tables\AnswerResponse\AnswerResponse.Debug.Seed.sql" />
     100    <Build Include="dbo\Tables\QuestionCategory\QuestionCategory.sql" />
     101    <None Include="dbo\Tables\QuestionCategory\QuestionCategory.Debug.Seed.sql" />
    93102  </ItemGroup>
    94103  <ItemGroup>
     
    97106    <PreDeploy Include="dbo\Scripts\Script.PreDeployment.sql" />
    98107    <None Include="FinkiChattery.Database.publish.xml" />
     108    <None Include="Snapshots\FinkiChattery.Database_20210922_17-47-58.dacpac" />
    99109  </ItemGroup>
    100110  <ItemGroup>
     
    120130    </SqlCmdVariable>
    121131  </ItemGroup>
     132  <ItemGroup>
     133    <RefactorLog Include="FinkiChattery.Database.refactorlog" />
     134  </ItemGroup>
    122135</Project>
  • src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/PostDeploymentScripts/Debug.PostDeployment.sql

    r7dd2ea2 r7f1a891  
    1 :r .\..\..\Tables\User\Seed\Users.Debug.Seed.sql
    2 :r .\..\..\Tables\Category\Category.Seed.sql
    3 :r .\..\..\Tables\Student\Student.Debug.Seed.sql
     1:r ./../../Tables/User/Seed/Users.Debug.Seed.sql
     2:r ./../../Tables/Category/Category.Seed.sql
     3:r ./../../Tables/Student/Student.Debug.Seed.sql
     4:r ./../../Tables/Question/Question.Debug.Seed.sql
     5:r ./../../Tables/Answer/Answer.Debug.Seed.sql
     6:r ./../../Tables/AnswerResponse/AnswerResponse.Debug.Seed.sql
     7:r ./../../Tables/QuestionCategory/QuestionCategory.Debug.Seed.sql
  • src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/PostDeploymentScripts/Production.PostDeployment.sql

    r7dd2ea2 r7f1a891  
    1 :r .\..\..\Tables\Category\Category.Seed.sql
     1:r ./../../Tables/Category/Category.Seed.sql
  • src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/Script.PostDeployment.sql

    r7dd2ea2 r7f1a891  
    44                PRINT 'Deploying DEBUG scripts';
    55        END
    6         :r .\PostDeploymentScripts\Debug.PostDeployment.sql
     6        :r ./PostDeploymentScripts/Debug.PostDeployment.sql
    77        BEGIN --Run scripts
    88                PRINT 'End deploying DEBUG scripts';
     
    1515                PRINT 'Deploying PRODUCTION scripts'
    1616        END
    17                 :r .\PostDeploymentScripts\Production.PostDeployment.sql
     17                :r ./PostDeploymentScripts/Production.PostDeployment.sql
    1818                BEGIN --Run scripts
    1919                PRINT 'End deploying PRODUCTION scripts'
  • src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/Script.PreDeployment.sql

    r7dd2ea2 r7f1a891  
    44                PRINT 'Deploying DEBUG pre deployment scripts';
    55        END
    6         :r .\PreDeploymentScripts\Debug.PreDeployment.sql
     6        :r ./PreDeploymentScripts/Debug.PreDeployment.sql
    77        BEGIN --Run scripts
    88                PRINT 'End deploying DEBUG pre deployment scripts';
     
    1515                PRINT 'Deploying PRODUCTION pre deployment scripts'
    1616        END
    17         :r .\PreDeploymentScripts\Production.PreDeployment.sql
     17        :r ./PreDeploymentScripts/Production.PreDeployment.sql
    1818        BEGIN --Run scripts
    1919                PRINT 'End deploying PRODUCTION pre deployment scripts'
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/Answer/Answer.sql

    r7dd2ea2 r7f1a891  
    77    [CorrectAnswer] BIT              NOT NULL,
    88    [CreatedOn]     SMALLDATETIME    NOT NULL,
     9    [UpvotesCount] BIGINT NOT NULL DEFAULT 0,
    910    CONSTRAINT [PK_Answer] PRIMARY KEY CLUSTERED ([Id] ASC),
    1011    CONSTRAINT [FK_Answer_Question_QuestionFk] FOREIGN KEY ([QuestionFk]) REFERENCES [dbo].[Question] ([Id]),
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/AnswerResponse/AnswerResponse.sql

    r7dd2ea2 r7f1a891  
    88    CONSTRAINT [PK_AnswerResponse] PRIMARY KEY CLUSTERED ([Id] ASC),
    99    CONSTRAINT [FK_AnswerResponse_Answer_AnswerFk] FOREIGN KEY ([AnswerFk]) REFERENCES [dbo].[Answer] ([Id]),
    10     CONSTRAINT [FK_AnswerResponse_Student_AnswerFk] FOREIGN KEY ([AnswerFk]) REFERENCES [dbo].[Student] ([Id])
     10    CONSTRAINT [FK_AnswerResponse_Student_AnswerFk] FOREIGN KEY ([StudentFk]) REFERENCES [dbo].[Student] ([Id])
    1111);
    1212
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/QuestionCategory/QuestionCategory.sql

    r7dd2ea2 r7f1a891  
    55    [CategoryFk] BIGINT           NOT NULL,
    66    CONSTRAINT [PK_QuestionCategory] PRIMARY KEY CLUSTERED ([Id] ASC),
    7     CONSTRAINT [FK_QuestionCategory_Category_QuestionFk] FOREIGN KEY ([QuestionFk]) REFERENCES [dbo].[Category] ([Id]),
     7    CONSTRAINT [FK_QuestionCategory_Category_CategoryFk] FOREIGN KEY ([CategoryFk]) REFERENCES [dbo].[Category] ([Id]),
    88    CONSTRAINT [FK_QuestionCategory_Question_QuestionFk] FOREIGN KEY ([QuestionFk]) REFERENCES [dbo].[Question] ([Id])
    99);
  • src/FinkiChattery/FinkiChattery.Persistence/Configurations/AnswerConfig.cs

    r7dd2ea2 r7f1a891  
    2222            builder.Property(x => x.CorrectAnswer).HasColumnName(@"CorrectAnswer").HasColumnType("bit").IsRequired();
    2323            builder.Property(x => x.CreatedOn).HasColumnName(@"CreatedOn").HasColumnType("smalldatetime").IsRequired();
     24            builder.Property(x => x.UpvotesCount).HasColumnName(@"UpvotesCount").HasColumnType("bigint").IsRequired().HasDefaultValue(0);
    2425
    2526            builder.HasOne(x => x.Question).WithMany(x => x.Answers).HasForeignKey(x => x.QuestionFk).OnDelete(DeleteBehavior.Restrict);
  • src/FinkiChattery/FinkiChattery.Persistence/Configurations/AnswerResponseConfig.cs

    r7dd2ea2 r7f1a891  
    2828
    2929            builder.HasOne(x => x.Answer).WithMany(x => x.AnswerResponses).HasForeignKey(x => x.AnswerFk).OnDelete(DeleteBehavior.Restrict);
    30             builder.HasOne(x => x.Student).WithMany().HasForeignKey(x => x.AnswerFk).OnDelete(DeleteBehavior.Restrict);
     30            builder.HasOne(x => x.Student).WithMany().HasForeignKey(x => x.StudentFk).OnDelete(DeleteBehavior.Restrict);
    3131        }
    3232    }
  • src/FinkiChattery/FinkiChattery.Persistence/Configurations/QuestionCategoryConfig.cs

    r7dd2ea2 r7f1a891  
    2626
    2727            builder.HasOne(x => x.Question).WithMany(x => x.QuestionCategories).HasForeignKey(x => x.QuestionFk).OnDelete(DeleteBehavior.Restrict);
    28             builder.HasOne(x => x.Category).WithMany().HasForeignKey(x => x.QuestionFk).OnDelete(DeleteBehavior.Restrict);
     28            builder.HasOne(x => x.Category).WithMany().HasForeignKey(x => x.CategoryFk).OnDelete(DeleteBehavior.Restrict);
    2929        }
    3030    }
  • src/FinkiChattery/FinkiChattery.Persistence/Models/Answer.cs

    r7dd2ea2 r7f1a891  
    2020        public DateTime CreatedOn { get; set; }
    2121
     22        public long UpvotesCount { get; set; }
     23
    2224        public virtual ICollection<Upvote> Upvotes { get; set; }
    2325
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Base/Repository.cs

    r7dd2ea2 r7f1a891  
    88namespace FinkiChattery.Persistence.Repositories
    99{
    10     public abstract class Repository<T> where T : BaseEntity
     10    public abstract class Repository<T> : IRepository<T> where T : BaseEntity
    1111    {
    1212        public Repository(ApplicationDbContext dbContext)
     
    2929        }
    3030
    31         public void Add(T entity)
     31        public async Task Add(T entity)
    3232        {
    3333            DbSet.Add(entity);
     34            await DbContext.SaveChangesAsync();
    3435        }
    3536
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/IQuestionRepo.cs

    r7dd2ea2 r7f1a891  
    1 namespace FinkiChattery.Persistence.Repositories
     1using FinkiChattery.Persistence.Repositories.Contracts;
     2using System;
     3using System.Threading.Tasks;
     4
     5namespace FinkiChattery.Persistence.Repositories
    26{
    37    public interface IQuestionRepo
    48    {
     9        Task<QuestionStateDto> GetQuestionState(Guid questionUid);
    510    }
    611}
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Implementations/QuestionRepo.cs

    r7dd2ea2 r7f1a891  
    11using FinkiChattery.Persistence.Context;
    22using FinkiChattery.Persistence.Models;
     3using FinkiChattery.Persistence.Repositories.Contracts;
     4using Microsoft.EntityFrameworkCore;
     5using System;
     6using System.Linq;
     7using System.Threading.Tasks;
    38
    49namespace FinkiChattery.Persistence.Repositories
     
    914        {
    1015        }
     16
     17        public async Task<QuestionStateDto> GetQuestionState(Guid questionUid)
     18        {
     19            // TODO: MAYBE WRITE THIS QUERY AS SP ??
     20            var questionDto = await DbSet
     21              .AsNoTracking()
     22              .Include(x => x.Student)
     23              .Include(x => x.Team)
     24              .Include(x => x.Answers).ThenInclude(y => y.Student)
     25              .Include(x => x.Answers).ThenInclude(y => y.AnswerResponses).ThenInclude(y => y.Student)
     26              .Include(x => x.QuestionCategories).ThenInclude(y => y.Category)
     27              .Where(x => x.Uid == questionUid)
     28              .Select(x => new QuestionStateDto(
     29                                                x.Id,
     30                                                x.Uid,
     31                                                x.Title,
     32                                                x.Text,
     33                                                x.CreatedOn,
     34                                                x.Views,
     35                                                x.LastActiveOn,
     36                                                new StudentQuestionStateDto(
     37                                                  x.Student.Id,
     38                                                  x.Student.Uid,
     39                                                  x.Student.IndexNumber,
     40                                                  x.Student.ImageUrl),
     41                                                x.Answers.Select(y =>
     42                                                new AnswerQuestionStateDto(
     43                                                    y.Id,
     44                                                    y.Uid,
     45                                                    y.Text,
     46                                                    y.CorrectAnswer,
     47                                                    y.CreatedOn,
     48                                                    y.UpvotesCount,
     49                                                    new AnswerStudentQuestionStateDto(
     50                                                        y.Student.Id,
     51                                                        y.Student.Uid,
     52                                                        y.Student.IndexNumber,
     53                                                        y.Student.ImageUrl),
     54                                                    y.AnswerResponses.Select(z =>
     55                                                    new AnswerResponseQuestionStateDto(
     56                                                        z.Id,
     57                                                        z.Uid,
     58                                                        z.Text,
     59                                                        z.CreatedOn,
     60                                                        new AnswerResponseStudentQuestionStateDto(
     61                                                            z.Student.Id,
     62                                                            z.Student.Uid,
     63                                                            z.Student.IndexNumber,
     64                                                            z.Student.ImageUrl))))),
     65                                                x.QuestionCategories.Select(y =>
     66                                                new QuestionCategoryQuestionStateDto(
     67                                                    y.Id,
     68                                                    y.Uid,
     69                                                    y.Category.Name)),
     70                                                x.Team == null ? null : new TeamQuestionStateDto(
     71                                                    x.Team.Id,
     72                                                    x.Team.Uid,
     73                                                    x.Team.Name)))
     74              .FirstOrDefaultAsync();
     75
     76            return questionDto;
     77        }
    1178    }
    1279}
  • src/FinkiChattery/FinkiChattery.Queries/FinkiChattery.Queries.csproj

    r7dd2ea2 r7f1a891  
    1 <Project Sdk="Microsoft.NET.Sdk">
     1<Project Sdk="Microsoft.NET.Sdk">
    22
    33  <PropertyGroup>
     
    55  </PropertyGroup>
    66
     7  <ItemGroup>
     8    <ProjectReference Include="..\FinkiChattery.Common\FinkiChattery.Common.csproj" />
     9    <ProjectReference Include="..\FinkiChattery.Persistence\FinkiChattery.Persistence.csproj" />
     10  </ItemGroup>
     11
    712</Project>
Note: See TracChangeset for help on using the changeset viewer.