Skip to content

Commit afbe033

Browse files
author
Roman Eriksen
committed
Added authorization to cohort endpoints
1 parent ffa3a11 commit afbe033

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

exercise.wwwapi/Endpoints/CohortEndpoints.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using exercise.wwwapi.DTOs.Posts;
55
using exercise.wwwapi.Models;
66
using exercise.wwwapi.Repository;
7+
using Microsoft.AspNetCore.Authorization;
78
using Microsoft.AspNetCore.Mvc;
89
using Microsoft.EntityFrameworkCore;
910
using System.Linq;
@@ -23,6 +24,8 @@ public static void ConfigureCohortEndpoints(this WebApplication app)
2324
cohorts.MapDelete("/{cohortId}/{userId}/{courseId}", DeleteUserFromCohort).WithSummary("Delete a user from a cohort");
2425
}
2526

27+
[Authorize]
28+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
2629
[ProducesResponseType(StatusCodes.Status200OK)]
2730
public static async Task<IResult> GetCohort(IRepository<Cohort> service, IMapper mapper, int cohortId)
2831
{
@@ -52,7 +55,8 @@ public static async Task<IResult> GetCohort(IRepository<Cohort> service, IMapper
5255
//return TypedResults.Ok(cohortDTOs);
5356
}
5457

55-
58+
[Authorize]
59+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
5660
[ProducesResponseType(StatusCodes.Status200OK)]
5761
public static async Task<IResult> GetCohortByUserId(IRepository<Cohort> cohortRepo, IMapper mapper, int userId)
5862
{
@@ -81,6 +85,7 @@ public static async Task<IResult> GetCohortByUserId(IRepository<Cohort> cohortRe
8185
return TypedResults.Ok(response);
8286
}
8387

88+
[Authorize]
8489
[ProducesResponseType(StatusCodes.Status200OK)]
8590
public static async Task<IResult> GetAllCohorts(IRepository<Cohort> cohortService, IMapper mapper)
8691
{
@@ -102,6 +107,8 @@ public static async Task<IResult> GetAllCohorts(IRepository<Cohort> cohortServic
102107
return TypedResults.Ok(response);
103108
}
104109

110+
[Authorize]
111+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
105112
[ProducesResponseType(StatusCodes.Status201Created)]
106113
public static async Task<IResult> CreateCohort(
107114
IRepository<Cohort> cohortService,
@@ -155,6 +162,7 @@ public static async Task<IResult> CreateCohort(
155162
return TypedResults.Created($"/api/cohorts/{cohort.Id}", response);
156163
}
157164

165+
[Authorize]
158166
[ProducesResponseType(StatusCodes.Status200OK)]
159167
[ProducesResponseType(StatusCodes.Status400BadRequest)]
160168
public static async Task<IResult> AddUserToCohort(
@@ -243,6 +251,7 @@ public static async Task<IResult> AddUserToCohort(
243251
});
244252
}
245253

254+
[Authorize]
246255
[ProducesResponseType(StatusCodes.Status200OK)]
247256
[ProducesResponseType(StatusCodes.Status400BadRequest)]
248257
public static async Task<IResult> DeleteUserFromCohort(

0 commit comments

Comments
 (0)