Changeset 7146ebb


Ignore:
Timestamp:
09/08/21 17:49:03 (3 years ago)
Author:
Стојков Марко <mst@…>
Branches:
dev
Children:
cba21c9
Parents:
cabaa79
Message:

Ask question endpoint

Location:
src/FinkiChattery
Files:
24 added
19 edited
3 moved

Legend:

Unmodified
Added
Removed
  • src/FinkiChattery/FinkiChattery.Api/FinkiChattery.Api.csproj

    rcabaa79 r7146ebb  
    1313    <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
    1414    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
     15    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
    1516    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
    1617      <PrivateAssets>all</PrivateAssets>
     
    2122
    2223  <ItemGroup>
     24    <ProjectReference Include="..\FinkiChattery.Commands\FinkiChattery.Commands.csproj" />
    2325    <ProjectReference Include="..\FinkiChattery.Common\FinkiChattery.Common.csproj" />
     26    <ProjectReference Include="..\FinkiChattery.Contracts\FinkiChattery.Contracts.csproj" />
    2427    <ProjectReference Include="..\FinkiChattery.Persistence\FinkiChattery.Persistence.csproj" />
    25   </ItemGroup>
    26 
    27   <ItemGroup>
    28     <Folder Include="Controllers\" />
    2928  </ItemGroup>
    3029
  • src/FinkiChattery/FinkiChattery.Api/Services/RegisterServices.cs

    rcabaa79 r7146ebb  
    1 using FinkiChattery.Api.Services;
     1using FinkiChattery.Api.ApplicationServices.Authentication;
     2using FinkiChattery.Api.Services;
     3using FinkiChattery.Commands.Questioning;
    24using FinkiChattery.Common.Mediator;
    35using FinkiChattery.Common.Mediator.Interfaces;
     
    68using FinkiChattery.Persistence.Context;
    79using FinkiChattery.Persistence.Models;
     10using FinkiChattery.Persistence.Repositories;
    811using Hangfire;
    912using Hangfire.SqlServer;
    1013using MediatR;
    1114using Microsoft.AspNetCore.Authentication.JwtBearer;
     15using Microsoft.AspNetCore.Authorization;
    1216using Microsoft.AspNetCore.Http;
    1317using Microsoft.AspNetCore.Identity;
     
    2529            services.AddScoped<IEventService, EventService>();
    2630            services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
    27 
    28             // TODO: REGISTER MEDIATOR HANDLERS WHEN WE CREATE FIRST COMMAND SMENI SO DOMAIN KLASA
    29             services.AddMediatR(typeof(RegisterServices));
     31            services.AddMediatR(typeof(AskQuestionCommand));
    3032        }
    3133
     
    7476            });
    7577
    76             services.AddAuthorization();
     78            services.AddScoped<IAuthorizationHandler, CurrentUserIsOfRoleRequirementHandler>();
     79
     80            services.AddAuthorization(options =>
     81            {
     82                options.AddPolicy(AuthenticationPolicy.Student, policy => policy.Requirements.Add(new StudentRequirement()));
     83
     84            });
    7785        }
    7886
     
    94102        public static void AddRepos(this IServiceCollection services)
    95103        {
     104            services.AddScoped<ICategoriesRepo, CategoriesRepo>();
     105            services.AddScoped<ITeamRepo, TeamRepo>();
     106            services.AddScoped<IQuestionRepo, QuestionRepo>();
     107            services.AddScoped<IStudentRepo, StudentRepo>();
    96108        }
    97109
  • src/FinkiChattery/FinkiChattery.Api/Startup.cs

    rcabaa79 r7146ebb  
    22using FinkiChattery.Api.Server;
    33using FinkiChattery.Api.Services;
     4using FinkiChattery.Commands.Questioning;
    45using FinkiChattery.Persistence.Context;
     6using FluentValidation.AspNetCore;
    57using Hangfire;
    68using Microsoft.AspNetCore.Builder;
     
    4143
    4244            services.AddControllers()
    43                 .ConfigureApiBehaviorOptions(options => options.InvalidModelStateResponseFactory = context => new BadRequestObjectResult(context.ModelState));
    44             // TODO: validators
    45             // .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<CreateOrganizerWithOrganizationValidator>());
     45                .ConfigureApiBehaviorOptions(options => options.InvalidModelStateResponseFactory = context => new BadRequestObjectResult(context.ModelState))
     46                .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<AskQuestionValidator>());
     47            services.AddApiVersioning();
    4648
    4749            services.AddCors(options =>
  • src/FinkiChattery/FinkiChattery.Commands/FinkiChattery.Commands.csproj

    rcabaa79 r7146ebb  
    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>
  • src/FinkiChattery/FinkiChattery.Common/Errors/ErrorCodes.cs

    rcabaa79 r7146ebb  
    11namespace FinkiChattery.Common.Errors
    22{
    3     public static class ErrorCodes
     3    public class ErrorCodes
    44    {
     5        public const string CantBeNull = "CantBeNull";
    56    }
    67}
  • src/FinkiChattery/FinkiChattery.Database/FinkiChattery.Database.sqlproj

    rcabaa79 r7146ebb  
    6666    <Folder Include="dbo\Tables\User" />
    6767    <Folder Include="dbo\Tables\User\Seed" />
     68    <Folder Include="dbo\Tables\Category" />
     69    <Folder Include="dbo\Tables\Team" />
     70    <Folder Include="dbo\Tables\Student" />
    6871  </ItemGroup>
    6972  <ItemGroup>
    70     <Build Include="dbo\Tables\Category.sql" />
    71     <Build Include="dbo\Tables\Team.sql" />
    7273    <Build Include="dbo\Tables\Moderator.sql" />
    73     <Build Include="dbo\Tables\Student.sql" />
    7474    <Build Include="dbo\Tables\Teacher.sql" />
    7575    <Build Include="dbo\Tables\Question.sql" />
     
    8383    <Build Include="dbo\Tables\User\AspNetRoles.sql" />
    8484    <None Include="dbo\Tables\User\Seed\Users.Debug.Seed.sql" />
     85    <Build Include="dbo\Tables\Category\Category.sql" />
     86    <None Include="dbo\Tables\Category\Category.Seed.sql" />
     87    <Build Include="dbo\Tables\Team\Team.sql" />
     88    <Build Include="dbo\Tables\Student\Student.sql" />
     89    <None Include="dbo\Tables\Student\Student.Debug.Seed.sql" />
    8590  </ItemGroup>
    8691  <ItemGroup>
  • src/FinkiChattery/FinkiChattery.Database/dbo/Scripts/PostDeploymentScripts/Debug.PostDeployment.sql

    rcabaa79 r7146ebb  
    11: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

    rcabaa79 r7146ebb  
    1 
     1:r .\..\..\Tables\Category\Category.Seed.sql
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/Answer.sql

    rcabaa79 r7146ebb  
    22    [Id]            BIGINT           IDENTITY (1, 1) NOT NULL,
    33    [Uid]           UNIQUEIDENTIFIER NOT NULL,
    4     [Text]          NVARCHAR (1)     NOT NULL,
     4    [Text]          NVARCHAR (4000)  NOT NULL,
    55    [QuestionFk]    BIGINT           NOT NULL,
    66    [StudentFk]     BIGINT           NOT NULL,
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/AnswerResponse.sql

    rcabaa79 r7146ebb  
    22    [Id]        BIGINT           IDENTITY (1, 1) NOT NULL,
    33    [Uid]       UNIQUEIDENTIFIER NOT NULL,
    4     [Text]      NVARCHAR (1)     NOT NULL,
     4    [Text]      NVARCHAR (4000)  NOT NULL,
    55    [AnswerFk]  BIGINT           NOT NULL,
    66    [StudentFk] BIGINT           NOT NULL,
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/Category/Category.sql

    rcabaa79 r7146ebb  
    22    [Id]   BIGINT           IDENTITY (1, 1) NOT NULL,
    33    [Uid]  UNIQUEIDENTIFIER NOT NULL,
    4     [Name] NVARCHAR (1)     NOT NULL,
     4    [Name] NVARCHAR (500)     NOT NULL,
    55    CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED ([Id] ASC)
    66);
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/Question.sql

    rcabaa79 r7146ebb  
    22    [Id]           BIGINT           IDENTITY (1, 1) NOT NULL,
    33    [Uid]          UNIQUEIDENTIFIER NOT NULL,
    4     [Title]        NVARCHAR (1)     NOT NULL,
     4    [Title]        NVARCHAR (500)     NOT NULL,
    55    [Text]         NVARCHAR (MAX)   NULL,
    66    [StudentFk]    BIGINT           NOT NULL,
  • src/FinkiChattery/FinkiChattery.Database/dbo/Tables/Student/Student.sql

    rcabaa79 r7146ebb  
    33    [Uid]               UNIQUEIDENTIFIER NOT NULL,
    44    [ApplicationUserFk] BIGINT           NOT NULL,
    5     [IndexNumber]       NVARCHAR (1)     NOT NULL,
     5    [IndexNumber]       NVARCHAR (50)     NOT NULL,
    66    [Reputation]        BIGINT           DEFAULT (CONVERT([bigint],(0))) NOT NULL,
    77    [ReportReputation]  BIGINT           DEFAULT (CONVERT([bigint],(0))) NOT NULL,
    8     [ImageUrl]          NVARCHAR (1)     NOT NULL,
     8    [ImageUrl]          NVARCHAR (1000)     NOT NULL,
    99    CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED ([Id] ASC),
    1010    CONSTRAINT [FK_Student_AspNetUsers_ApplicationUserFk] FOREIGN KEY ([ApplicationUserFk]) REFERENCES [dbo].[AspNetUsers] ([Id])
  • src/FinkiChattery/FinkiChattery.Persistence/Configurations/QuestionConfig.cs

    rcabaa79 r7146ebb  
    1 using Microsoft.EntityFrameworkCore;
     1using FinkiChattery.Persistence.Models;
     2using Microsoft.EntityFrameworkCore;
    23using Microsoft.EntityFrameworkCore.Metadata.Builders;
    3 using System;
    4 using System.Collections.Generic;
    5 using System.Linq;
    6 using System.Text;
    7 using System.Threading.Tasks;
    8 using FinkiChattery.Persistence.Models;
    94
    105namespace FinkiChattery.Persistence.Configurations
     
    2318
    2419            builder.Property(x => x.Title).HasColumnName(@"Title").HasColumnType("nvarchar").IsRequired().HasMaxLength(500);
    25             builder.Property(x => x.TeamFk).HasColumnName(@"Team").HasColumnType("nvarchar").IsRequired().HasMaxLength(4000);
     20            builder.Property(x => x.Text).HasColumnName(@"Text").HasColumnType("nvarchar").IsRequired().HasMaxLength(4000);
    2621            builder.Property(x => x.StudentFk).HasColumnName(@"StudentFk").HasColumnType("bigint").IsRequired();
    2722            builder.Property(x => x.CreatedOn).HasColumnName(@"CreatedOn").HasColumnType("smalldatetime").IsRequired();
  • src/FinkiChattery/FinkiChattery.Persistence/Models/Answer.cs

    rcabaa79 r7146ebb  
    2020        public DateTime CreatedOn { get; set; }
    2121
    22         public virtual IEnumerable<Upvote> Upvotes { get; set; }
     22        public virtual ICollection<Upvote> Upvotes { get; set; }
    2323
    24         public virtual IEnumerable<AnswerResponse> AnswerResponses { get; set; }
     24        public virtual ICollection<AnswerResponse> AnswerResponses { get; set; }
    2525
    2626    }
  • src/FinkiChattery/FinkiChattery.Persistence/Models/Base/BaseEntity.cs

    rcabaa79 r7146ebb  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    62
    73namespace FinkiChattery.Persistence.Models
     
    95    public class BaseEntity
    106    {
     7        public BaseEntity()
     8        {
     9            Uid = Guid.NewGuid();
     10        }
     11
    1112        public long Id { get; set; }
    1213
  • src/FinkiChattery/FinkiChattery.Persistence/Models/Question.cs

    rcabaa79 r7146ebb  
    66    public class Question : BaseEntity
    77    {
     8        public Question() : base()
     9        {
     10            CreatedOn = DateTime.UtcNow;
     11            LastActiveOn = DateTime.UtcNow;
     12            Answers = new List<Answer>();
     13            QuestionCategories = new List<QuestionCategory>();
     14        }
     15
    816        public string Title { get; set; }
    917
     
    2432        public DateTime LastActiveOn { get; set; }
    2533
    26         public virtual IEnumerable<Answer> Answers { get; set; }
     34        public virtual ICollection<Answer> Answers { get; set; }
    2735
    28         public virtual IEnumerable<QuestionCategory> QuestionCategories { get; set; }
     36        public virtual ICollection<QuestionCategory> QuestionCategories { get; set; }
    2937
    3038        // TODO: Pole po koe ke pravime queries
  • src/FinkiChattery/FinkiChattery.Persistence/Models/QuestionCategory.cs

    rcabaa79 r7146ebb  
    99    public class QuestionCategory : BaseEntity
    1010    {
     11        public QuestionCategory() : base()
     12        {
     13        }
     14
    1115        public long QuestionFk { get; set; }
    1216
  • src/FinkiChattery/FinkiChattery.Persistence/Models/Student.cs

    rcabaa79 r7146ebb  
    2121        public string ImageUrl { get; set; }
    2222
    23         public virtual IEnumerable<Question> Questions { get; set; }
     23        public virtual ICollection<Question> Questions { get; set; }
    2424       
    25         public virtual IEnumerable<Answer> Answers { get; set; }
     25        public virtual ICollection<Answer> Answers { get; set; }
    2626       
    27         public virtual IEnumerable<StudentTeam> StudentTeams { get; set; }
     27        public virtual ICollection<StudentTeam> StudentTeams { get; set; }
    2828    }
    2929}
  • src/FinkiChattery/FinkiChattery.Persistence/Models/Teacher.cs

    rcabaa79 r7146ebb  
    1313        public virtual ApplicationUser ApplicationUser { get; set; }
    1414
    15         public virtual IEnumerable<TeacherTeam> TeacherTeams { get; set; }
     15        public virtual ICollection<TeacherTeam> TeacherTeams { get; set; }
    1616
    1717    }
  • src/FinkiChattery/FinkiChattery.Persistence/Models/Team.cs

    rcabaa79 r7146ebb  
    1313        public string Description { get; set; }
    1414
    15         public virtual IEnumerable<Question> Questions{ get; set; }
     15        public virtual ICollection<Question> Questions{ get; set; }
    1616
    17         public virtual IEnumerable<StudentTeam> TeamStudents { get; set; }
     17        public virtual ICollection<StudentTeam> TeamStudents { get; set; }
    1818
    19         public virtual IEnumerable<TeacherTeam> TeamTeachers { get; set; }
     19        public virtual ICollection<TeacherTeam> TeamTeachers { get; set; }
    2020    }
    2121}
Note: See TracChangeset for help on using the changeset viewer.