Changes in / [7dd2ea2:7f1a891]
- Location:
- src/FinkiChattery
- Files:
-
- 16 added
- 4 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FinkiChattery/FinkiChattery.Api/Controllers/v1/QuestionsController.cs
r7dd2ea2 r7f1a891 1 1 using FinkiChattery.Api.ApplicationServices.Authentication; 2 using FinkiChattery.Api.ApplicationServices.Questioning; 2 3 using FinkiChattery.Commands.Questioning; 3 4 using FinkiChattery.Common.Mediator.Interfaces; 4 5 using FinkiChattery.Contracts.Questioning; 6 using FinkiChattery.Queries.Questioning; 5 7 using IdentityServer4.AccessTokenValidation; 6 8 using Microsoft.AspNetCore.Authorization; 7 9 using Microsoft.AspNetCore.Mvc; 10 using System; 8 11 using System.Threading.Tasks; 9 12 … … 29 32 return Ok(); 30 33 } 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 } 31 42 } 32 43 } -
src/FinkiChattery/FinkiChattery.Api/FinkiChattery.Api.csproj
r7dd2ea2 r7f1a891 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" /> 28 29 </ItemGroup> 29 30 -
src/FinkiChattery/FinkiChattery.Api/Services/RegisterServices.cs
r7dd2ea2 r7f1a891 9 9 using FinkiChattery.Persistence.Models; 10 10 using FinkiChattery.Persistence.Repositories; 11 using FinkiChattery.Queries.Questioning; 11 12 using Hangfire; 12 13 using Hangfire.SqlServer; … … 29 30 services.AddScoped<IEventService, EventService>(); 30 31 services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); 31 services.AddMediatR(typeof(AskQuestionCommand) );32 services.AddMediatR(typeof(AskQuestionCommand), typeof(GetQuestionStateQuery)); 32 33 } 33 34 … … 143 144 services.AddScoped<IStorageService, AwsStorageService>();*/ 144 145 } 145 146 // TODO: ADD HANGFIRE AND SCAFOLD DB IN HANGFIREDB147 146 } 148 147 -
src/FinkiChattery/FinkiChattery.Common/Mediator/Interfaces/IMediatorService.cs
r7dd2ea2 r7f1a891 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 13 17 Task PublishAsync<TNotification>(TNotification notification) where TNotification : IEvent; 14 18 -
src/FinkiChattery/FinkiChattery.Common/Mediator/MediatorService.cs
r7dd2ea2 r7f1a891 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 } 39 49 } 40 50 } -
src/FinkiChattery/FinkiChattery.Database/FinkiChattery.Database.sqlproj
r7dd2ea2 r7f1a891 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" /> 72 77 </ItemGroup> 73 78 <ItemGroup> 74 79 <Build Include="dbo\Tables\Moderator.sql" /> 75 80 <Build Include="dbo\Tables\Teacher.sql" /> 76 <Build Include="dbo\Tables\Question.sql" />77 81 <Build Include="dbo\Tables\StudentTeam.sql" /> 78 82 <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" />82 83 <Build Include="dbo\Tables\Upvote.sql" /> 83 84 <Build Include="dbo\Tables\User\AspNetRoleClaims.sql" /> … … 91 92 <Build Include="FullTextSearch\FullTextIndexQuestion.sql" /> 92 93 <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" /> 93 102 </ItemGroup> 94 103 <ItemGroup> … … 97 106 <PreDeploy Include="dbo\Scripts\Script.PreDeployment.sql" /> 98 107 <None Include="FinkiChattery.Database.publish.xml" /> 108 <None Include="Snapshots\FinkiChattery.Database_20210922_17-47-58.dacpac" /> 99 109 </ItemGroup> 100 110 <ItemGroup> … … 120 130 </SqlCmdVariable> 121 131 </ItemGroup> 132 <ItemGroup> 133 <RefactorLog Include="FinkiChattery.Database.refactorlog" /> 134 </ItemGroup> 122 135 </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.sql1 :r ./../../Tables/Category/Category.Seed.sql -
src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/Script.PostDeployment.sql
r7dd2ea2 r7f1a891 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
r7dd2ea2 r7f1a891 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
r7dd2ea2 r7f1a891 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); 24 25 25 26 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 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. AnswerFk).OnDelete(DeleteBehavior.Restrict);30 builder.HasOne(x => x.Student).WithMany().HasForeignKey(x => x.StudentFk).OnDelete(DeleteBehavior.Restrict); 31 31 } 32 32 } -
src/FinkiChattery/FinkiChattery.Persistence/Configurations/QuestionCategoryConfig.cs
r7dd2ea2 r7f1a891 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. QuestionFk).OnDelete(DeleteBehavior.Restrict);28 builder.HasOne(x => x.Category).WithMany().HasForeignKey(x => x.CategoryFk).OnDelete(DeleteBehavior.Restrict); 29 29 } 30 30 } -
src/FinkiChattery/FinkiChattery.Persistence/Models/Answer.cs
r7dd2ea2 r7f1a891 20 20 public DateTime CreatedOn { get; set; } 21 21 22 public long UpvotesCount { get; set; } 23 22 24 public virtual ICollection<Upvote> Upvotes { get; set; } 23 25 -
src/FinkiChattery/FinkiChattery.Persistence/Repositories/Base/Repository.cs
r7dd2ea2 r7f1a891 8 8 namespace FinkiChattery.Persistence.Repositories 9 9 { 10 public abstract class Repository<T> where T : BaseEntity10 public abstract class Repository<T> : IRepository<T> where T : BaseEntity 11 11 { 12 12 public Repository(ApplicationDbContext dbContext) … … 29 29 } 30 30 31 public voidAdd(T entity)31 public async Task Add(T entity) 32 32 { 33 33 DbSet.Add(entity); 34 await DbContext.SaveChangesAsync(); 34 35 } 35 36 -
src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/IQuestionRepo.cs
r7dd2ea2 r7f1a891 1 namespace FinkiChattery.Persistence.Repositories 1 using FinkiChattery.Persistence.Repositories.Contracts; 2 using System; 3 using System.Threading.Tasks; 4 5 namespace FinkiChattery.Persistence.Repositories 2 6 { 3 7 public interface IQuestionRepo 4 8 { 9 Task<QuestionStateDto> GetQuestionState(Guid questionUid); 5 10 } 6 11 } -
src/FinkiChattery/FinkiChattery.Persistence/Repositories/Implementations/QuestionRepo.cs
r7dd2ea2 r7f1a891 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; 3 8 4 9 namespace FinkiChattery.Persistence.Repositories … … 9 14 { 10 15 } 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 } 11 78 } 12 79 } -
src/FinkiChattery/FinkiChattery.Queries/FinkiChattery.Queries.csproj
r7dd2ea2 r7f1a891 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 7 12 </Project>
Note:
See TracChangeset
for help on using the changeset viewer.