Skip to content

Commit

Permalink
[authorize]
Browse files Browse the repository at this point in the history
  • Loading branch information
OlimjonovOzodbek committed Sep 21, 2024
1 parent fe88318 commit 8e22ba7
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions UrphaCapital.API/Controllers/AdminsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using UrphaCapital.Application.AuthServices;
Expand Down
4 changes: 4 additions & 0 deletions UrphaCapital.API/Controllers/CoursesController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using UrphaCapital.Application.UseCases.Courses.Commands;
using UrphaCapital.Application.UseCases.Courses.Queries;
Expand All @@ -19,6 +20,7 @@ public CoursesController(IMediator mediator)
}

[HttpPost]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> Create([FromForm] CreateCourseCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand Down Expand Up @@ -66,6 +68,7 @@ public async Task<IEnumerable<Course>> GetAll(int index, int count, Cancellation
}

[HttpPut]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> Update([FromForm] UpdateCourseCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -74,6 +77,7 @@ public async Task<ResponseModel> Update([FromForm] UpdateCourseCommand command,
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> Delete(Guid id, CancellationToken cancellation)
{
var command = new DeleteCourseCommand { Id = id };
Expand Down
3 changes: 3 additions & 0 deletions UrphaCapital.API/Controllers/HelpController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using UrphaCapital.Application.UseCases.Homework.Commands;
Expand Down Expand Up @@ -27,6 +28,7 @@ public async Task<ResponseModel> PostHelp([FromForm] CreateHomeworkCommand comma
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> RemoveHelp(long id, CancellationToken cancellation)
{
var command = new DeleteHomeworkCommand { Id = id };
Expand All @@ -37,6 +39,7 @@ public async Task<ResponseModel> RemoveHelp(long id, CancellationToken cancellat
}

[HttpGet]
[Authorize(Roles = "Admin")]
public async Task<IEnumerable<Homeworks>> GetAll(int index, int count, CancellationToken cancellation)
{
var query = new GetAllHomeworksQuery();
Expand Down
15 changes: 15 additions & 0 deletions UrphaCapital.API/Controllers/HomeworksController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using UrphaCapital.Application.UseCases.Homework.Commands;
using UrphaCapital.Application.UseCases.Homework.Queries;
Expand Down Expand Up @@ -28,6 +29,8 @@ public async Task<ResponseModel> PostLesson([FromForm] CreateHomeworkCommand com
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
public async Task<ResponseModel> RemoveHomework(long id, CancellationToken cancellation)
{
var command = new DeleteHomeworkCommand { Id = id };
Expand All @@ -46,6 +49,8 @@ public async Task<ResponseModel> PutHomework([FromForm] UpdateHomeworkCommand co
}

[HttpPut("grade-homework")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
public async Task<ResponseModel> PutHomework([FromBody] GradeHomeworkCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -54,6 +59,9 @@ public async Task<ResponseModel> PutHomework([FromBody] GradeHomeworkCommand com
}

[HttpGet("{studentId}/results/{index}/{count}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
[Authorize(Roles = "Student")]
public async Task<IEnumerable<HomeworkResultView>> GetStudentHomeworkResults(long studentId, int index, int count, CancellationToken cancellation)
{
var query = new GetStudentHomeworkResultsQuery()
Expand All @@ -69,6 +77,9 @@ public async Task<IEnumerable<HomeworkResultView>> GetStudentHomeworkResults(lon
}

[HttpGet("{index}/{count}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
[Authorize(Roles = "Student")]
public async Task<IEnumerable<Homeworks>> GetAll(int index, int count, CancellationToken cancellation)
{
var query = new GetAllHomeworksQuery()
Expand All @@ -83,6 +94,8 @@ public async Task<IEnumerable<Homeworks>> GetAll(int index, int count, Cancellat
}

[HttpGet("{mentorId}/{index}/{count}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
public async Task<IEnumerable<Homeworks>> GetAllHomeworksByMentorId(int index, int count, long mentorId, CancellationToken cancellation)
{
var query = new Application.UseCases.Homework.Queries.GetAllHomeworksByMentorIdQuery()
Expand All @@ -98,6 +111,8 @@ public async Task<IEnumerable<Homeworks>> GetAllHomeworksByMentorId(int index, i
}

[HttpGet("bylesson/{lessonId}/{index}/{count}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
public async Task<IEnumerable<Homeworks>> GetAllHomeworksByLessonId(int index, int count, long lessonId, CancellationToken cancellation)
{
var query = new Application.UseCases.Homework.Queries.GetAllHomeworksByLessonIdQuery()
Expand Down
13 changes: 13 additions & 0 deletions UrphaCapital.API/Controllers/LessonsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using UrphaCapital.Application.UseCases.Lessons.Commands;
Expand All @@ -21,6 +22,7 @@ public LessonsController(IMediator mediator)
}

[HttpPost]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> PostLesson([FromForm] CreateLessonCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -29,6 +31,9 @@ public async Task<ResponseModel> PostLesson([FromForm] CreateLessonCommand comma
}

[HttpGet("{id}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
[Authorize(Roles = "Student")]
public async Task<Lesson> GetLessonById(string id, CancellationToken cancellation)
{
var query = new GetLessonByIdQuery { Id = id };
Expand All @@ -39,6 +44,9 @@ public async Task<Lesson> GetLessonById(string id, CancellationToken cancellatio
}

[HttpGet("getvideo")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
[Authorize(Roles = "Student")]
public async Task<IActionResult> GetLessonVideo([FromQuery] string lessonId, CancellationToken cancellation)
{
var query = new GetLessonVideoQuery { Id = lessonId };
Expand All @@ -58,6 +66,9 @@ public async Task<IActionResult> GetLessonVideo([FromQuery] string lessonId, Can
}

[HttpGet("{courseId}/{index}/{count}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Mentor")]
[Authorize(Roles = "Student")]
public async Task<IEnumerable<Lesson>> GetLessonsByCourseId(string courseId, int index, int count, CancellationToken cancellation)
{
var query = new GetAllLessonsByCourseIdQuery()
Expand All @@ -73,6 +84,7 @@ public async Task<IEnumerable<Lesson>> GetLessonsByCourseId(string courseId, int
}

[HttpPut]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> PutLesson([FromForm] UpdateLessonCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -81,6 +93,7 @@ public async Task<ResponseModel> PutLesson([FromForm] UpdateLessonCommand comman
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> RemoveLesson(string id, CancellationToken cancellation)
{
var command = new DeleteLessonCommand { Id = id };
Expand Down
6 changes: 6 additions & 0 deletions UrphaCapital.API/Controllers/MentorsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
Expand Down Expand Up @@ -28,6 +29,7 @@ public MentorsController(IMediator mediator, IPasswordHasher passwordHasher, IAu
}

[HttpPost]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> Create([FromForm] CreateMentorCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -36,6 +38,7 @@ public async Task<ResponseModel> Create([FromForm] CreateMentorCommand command,
}

[HttpGet("{id}")]
[Authorize(Roles = "Admin")]
public async Task<Mentor> GetById(long id, CancellationToken cancellation)
{
var query = new GetMentorByIdQuery { Id = id };
Expand All @@ -46,6 +49,7 @@ public async Task<Mentor> GetById(long id, CancellationToken cancellation)
}

[HttpGet("{index}/{count}")]
[Authorize(Roles = "Admin")]
public async Task<IEnumerable<Mentor>> GetAll(int index, int count, CancellationToken cancellation)
{
var query = new GetAllMentorsQuery()
Expand All @@ -60,6 +64,7 @@ public async Task<IEnumerable<Mentor>> GetAll(int index, int count, Cancellation
}

[HttpPut]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> Update([FromForm] UpdateMentorCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -68,6 +73,7 @@ public async Task<ResponseModel> Update([FromForm] UpdateMentorCommand command,
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> Delete(long id, CancellationToken cancellation)
{
var command = new DeleteMentorCommand { Id = id };
Expand Down
11 changes: 11 additions & 0 deletions UrphaCapital.API/Controllers/StudentController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using UrphaCapital.Application.AuthServices;
Expand Down Expand Up @@ -28,6 +29,8 @@ public StudentController(IMediator mediator, IAuthService authService, IPassword
}

[HttpPost]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Student")]
public async Task<ResponseModel> PostStudent([FromBody] CreateStudentsCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -36,6 +39,7 @@ public async Task<ResponseModel> PostStudent([FromBody] CreateStudentsCommand co
}

[HttpGet("{id}")]
[Authorize(Roles = "Admin")]
public async Task<Student> GetStudentById(long id, CancellationToken cancellation)
{
var query = new GetAllStudentsByIdQuery { Id = id };
Expand All @@ -46,6 +50,8 @@ public async Task<Student> GetStudentById(long id, CancellationToken cancellatio
}

[HttpGet("get-my-courses/{id}")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Student")]
//one
public async Task<IEnumerable<Course>> GetMyCoursesById(long id, CancellationToken cancellation)
// two
Expand All @@ -59,6 +65,7 @@ public async Task<IEnumerable<Course>> GetMyCoursesById(long id, CancellationTok
}

[HttpGet("{index}/{count}")]
[Authorize(Roles = "Admin")]
public async Task<IEnumerable<Student>> GetStudentsByStudentId(int index, int count, CancellationToken cancellation)
{
var query = new GetAllStudentsQuery()
Expand All @@ -73,6 +80,7 @@ public async Task<IEnumerable<Student>> GetStudentsByStudentId(int index, int co
}

[HttpPut]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> PutStudent([FromBody] UpdateStudentCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -81,6 +89,8 @@ public async Task<ResponseModel> PutStudent([FromBody] UpdateStudentCommand comm
}

[HttpPut("add-course")]
[Authorize(Roles = "Admin")]
[Authorize(Roles = "Student")]
public async Task<ResponseModel> AddMyCourse([FromQuery] AddMyCourseCommand command, CancellationToken cancellation)
{
var response = await _mediator.Send(command, cancellation);
Expand All @@ -89,6 +99,7 @@ public async Task<ResponseModel> AddMyCourse([FromQuery] AddMyCourseCommand comm
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
public async Task<ResponseModel> RemoveStudent(string id, CancellationToken cancellation)
{
var command = new DeleteLessonCommand { Id = id };
Expand Down

0 comments on commit 8e22ba7

Please sign in to comment.