Changes in / [7f1a891:7dd2ea2]
- Location:
- src/FinkiChattery
- Files:
-
- 4 added
- 16 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FinkiChattery/FinkiChattery.Api/Controllers/v1/QuestionsController.cs
r7f1a891 r7dd2ea2 1 1 using FinkiChattery.Api.ApplicationServices.Authentication; 2 using FinkiChattery.Api.ApplicationServices.Questioning;3 2 using FinkiChattery.Commands.Questioning; 4 3 using FinkiChattery.Common.Mediator.Interfaces; 5 4 using FinkiChattery.Contracts.Questioning; 6 using FinkiChattery.Queries.Questioning;7 5 using IdentityServer4.AccessTokenValidation; 8 6 using Microsoft.AspNetCore.Authorization; 9 7 using Microsoft.AspNetCore.Mvc; 10 using System;11 8 using System.Threading.Tasks; 12 9 … … 32 29 return Ok(); 33 30 } 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 }42 31 } 43 32 } -
src/FinkiChattery/FinkiChattery.Api/FinkiChattery.Api.csproj
r7f1a891 r7dd2ea2 26 26 <ProjectReference Include="..\FinkiChattery.Contracts\FinkiChattery.Contracts.csproj" /> 27 27 <ProjectReference Include="..\FinkiChattery.Persistence\FinkiChattery.Persistence.csproj" /> 28 <ProjectReference Include="..\FinkiChattery.Queries\FinkiChattery.Queries.csproj" />29 28 </ItemGroup> 30 29 -
src/FinkiChattery/FinkiChattery.Api/Services/RegisterServices.cs
r7f1a891 r7dd2ea2 9 9 using FinkiChattery.Persistence.Models; 10 10 using FinkiChattery.Persistence.Repositories; 11 using FinkiChattery.Queries.Questioning;12 11 using Hangfire; 13 12 using Hangfire.SqlServer; … … 30 29 services.AddScoped<IEventService, EventService>(); 31 30 services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); 32 services.AddMediatR(typeof(AskQuestionCommand) , typeof(GetQuestionStateQuery));31 services.AddMediatR(typeof(AskQuestionCommand)); 33 32 } 34 33 … … 144 143 services.AddScoped<IStorageService, AwsStorageService>();*/ 145 144 } 145 146 // TODO: ADD HANGFIRE AND SCAFOLD DB IN HANGFIREDB 146 147 } 147 148 -
src/FinkiChattery/FinkiChattery.Common/Mediator/Interfaces/IMediatorService.cs
r7f1a891 r7dd2ea2 11 11 Task<TResponse> SendAsync<TResponse>(ICommand<TResponse> request); 12 12 13 Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request, CancellationToken cancellationToken);14 15 Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request);16 17 13 Task PublishAsync<TNotification>(TNotification notification) where TNotification : IEvent; 18 14 -
src/FinkiChattery/FinkiChattery.Common/Mediator/MediatorService.cs
r7f1a891 r7dd2ea2 37 37 await mediator.Publish(notification, default); 38 38 } 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 }49 39 } 50 40 } -
src/FinkiChattery/FinkiChattery.Database/FinkiChattery.Database.sqlproj
r7f1a891 r7dd2ea2 70 70 <Folder Include="dbo\Tables\Student" /> 71 71 <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" />77 72 </ItemGroup> 78 73 <ItemGroup> 79 74 <Build Include="dbo\Tables\Moderator.sql" /> 80 75 <Build Include="dbo\Tables\Teacher.sql" /> 76 <Build Include="dbo\Tables\Question.sql" /> 81 77 <Build Include="dbo\Tables\StudentTeam.sql" /> 82 78 <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" /> 83 82 <Build Include="dbo\Tables\Upvote.sql" /> 84 83 <Build Include="dbo\Tables\User\AspNetRoleClaims.sql" /> … … 92 91 <Build Include="FullTextSearch\FullTextIndexQuestion.sql" /> 93 92 <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" />102 93 </ItemGroup> 103 94 <ItemGroup> … … 106 97 <PreDeploy Include="dbo\Scripts\Script.PreDeployment.sql" /> 107 98 <None Include="FinkiChattery.Database.publish.xml" /> 108 <None Include="Snapshots\FinkiChattery.Database_20210922_17-47-58.dacpac" />109 99 </ItemGroup> 110 100 <ItemGroup> … … 130 120 </SqlCmdVariable> 131 121 </ItemGroup> 132 <ItemGroup>133 <RefactorLog Include="FinkiChattery.Database.refactorlog" />134 </ItemGroup>135 122 </Project> -
src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/PostDeploymentScripts/Debug.PostDeployment.sql
r7f1a891 r7dd2ea2 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 1 :r .\..\..\Tables\User\Seed\Users.Debug.Seed.sql 2 :r .\..\..\Tables\Category\Category.Seed.sql 3 :r .\..\..\Tables\Student\Student.Debug.Seed.sql -
src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/PostDeploymentScripts/Production.PostDeployment.sql
r7f1a891 r7dd2ea2 1 :r . /../../Tables/Category/Category.Seed.sql1 :r .\..\..\Tables\Category\Category.Seed.sql -
src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/Script.PostDeployment.sql
r7f1a891 r7dd2ea2 4 4 PRINT 'Deploying DEBUG scripts'; 5 5 END 6 :r . /PostDeploymentScripts/Debug.PostDeployment.sql6 :r .\PostDeploymentScripts\Debug.PostDeployment.sql 7 7 BEGIN --Run scripts 8 8 PRINT 'End deploying DEBUG scripts'; … … 15 15 PRINT 'Deploying PRODUCTION scripts' 16 16 END 17 :r . /PostDeploymentScripts/Production.PostDeployment.sql17 :r .\PostDeploymentScripts\Production.PostDeployment.sql 18 18 BEGIN --Run scripts 19 19 PRINT 'End deploying PRODUCTION scripts' -
src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/Script.PreDeployment.sql
r7f1a891 r7dd2ea2 4 4 PRINT 'Deploying DEBUG pre deployment scripts'; 5 5 END 6 :r . /PreDeploymentScripts/Debug.PreDeployment.sql6 :r .\PreDeploymentScripts\Debug.PreDeployment.sql 7 7 BEGIN --Run scripts 8 8 PRINT 'End deploying DEBUG pre deployment scripts'; … … 15 15 PRINT 'Deploying PRODUCTION pre deployment scripts' 16 16 END 17 :r . /PreDeploymentScripts/Production.PreDeployment.sql17 :r .\PreDeploymentScripts\Production.PreDeployment.sql 18 18 BEGIN --Run scripts 19 19 PRINT 'End deploying PRODUCTION pre deployment scripts' -
src/FinkiChattery/FinkiChattery.Persistence/Configurations/AnswerConfig.cs
r7f1a891 r7dd2ea2 22 22 builder.Property(x => x.CorrectAnswer).HasColumnName(@"CorrectAnswer").HasColumnType("bit").IsRequired(); 23 23 builder.Property(x => x.CreatedOn).HasColumnName(@"CreatedOn").HasColumnType("smalldatetime").IsRequired(); 24 builder.Property(x => x.UpvotesCount).HasColumnName(@"UpvotesCount").HasColumnType("bigint").IsRequired().HasDefaultValue(0);25 24 26 25 builder.HasOne(x => x.Question).WithMany(x => x.Answers).HasForeignKey(x => x.QuestionFk).OnDelete(DeleteBehavior.Restrict); -
src/FinkiChattery/FinkiChattery.Persistence/Configurations/AnswerResponseConfig.cs
r7f1a891 r7dd2ea2 28 28 29 29 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. StudentFk).OnDelete(DeleteBehavior.Restrict);30 builder.HasOne(x => x.Student).WithMany().HasForeignKey(x => x.AnswerFk).OnDelete(DeleteBehavior.Restrict); 31 31 } 32 32 } -
src/FinkiChattery/FinkiChattery.Persistence/Configurations/QuestionCategoryConfig.cs
r7f1a891 r7dd2ea2 26 26 27 27 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. CategoryFk).OnDelete(DeleteBehavior.Restrict);28 builder.HasOne(x => x.Category).WithMany().HasForeignKey(x => x.QuestionFk).OnDelete(DeleteBehavior.Restrict); 29 29 } 30 30 } -
src/FinkiChattery/FinkiChattery.Persistence/Models/Answer.cs
r7f1a891 r7dd2ea2 20 20 public DateTime CreatedOn { get; set; } 21 21 22 public long UpvotesCount { get; set; }23 24 22 public virtual ICollection<Upvote> Upvotes { get; set; } 25 23 -
src/FinkiChattery/FinkiChattery.Persistence/Repositories/Base/Repository.cs
r7f1a891 r7dd2ea2 8 8 namespace FinkiChattery.Persistence.Repositories 9 9 { 10 public abstract class Repository<T> : IRepository<T>where T : BaseEntity10 public abstract class Repository<T> where T : BaseEntity 11 11 { 12 12 public Repository(ApplicationDbContext dbContext) … … 29 29 } 30 30 31 public async TaskAdd(T entity)31 public void Add(T entity) 32 32 { 33 33 DbSet.Add(entity); 34 await DbContext.SaveChangesAsync();35 34 } 36 35 -
src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/IQuestionRepo.cs
r7f1a891 r7dd2ea2 1 using FinkiChattery.Persistence.Repositories.Contracts; 2 using System; 3 using System.Threading.Tasks; 4 5 namespace FinkiChattery.Persistence.Repositories 1 namespace FinkiChattery.Persistence.Repositories 6 2 { 7 3 public interface IQuestionRepo 8 4 { 9 Task<QuestionStateDto> GetQuestionState(Guid questionUid);10 5 } 11 6 } -
src/FinkiChattery/FinkiChattery.Persistence/Repositories/Implementations/QuestionRepo.cs
r7f1a891 r7dd2ea2 1 1 using FinkiChattery.Persistence.Context; 2 2 using FinkiChattery.Persistence.Models; 3 using FinkiChattery.Persistence.Repositories.Contracts;4 using Microsoft.EntityFrameworkCore;5 using System;6 using System.Linq;7 using System.Threading.Tasks;8 3 9 4 namespace FinkiChattery.Persistence.Repositories … … 14 9 { 15 10 } 16 17 public async Task<QuestionStateDto> GetQuestionState(Guid questionUid)18 {19 // TODO: MAYBE WRITE THIS QUERY AS SP ??20 var questionDto = await DbSet21 .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 }78 11 } 79 12 } -
src/FinkiChattery/FinkiChattery.Queries/FinkiChattery.Queries.csproj
r7f1a891 r7dd2ea2 1 <Project Sdk="Microsoft.NET.Sdk">1 <Project Sdk="Microsoft.NET.Sdk"> 2 2 3 3 <PropertyGroup> … … 5 5 </PropertyGroup> 6 6 7 <ItemGroup>8 <ProjectReference Include="..\FinkiChattery.Common\FinkiChattery.Common.csproj" />9 <ProjectReference Include="..\FinkiChattery.Persistence\FinkiChattery.Persistence.csproj" />10 </ItemGroup>11 12 7 </Project>
Note:
See TracChangeset
for help on using the changeset viewer.