Skip to content

Commit

Permalink
Added basic authorization to activity endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
LokeSGJ committed Dec 6, 2024
1 parent 0a2670e commit af5f0e3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions GirafAPI/Endpoints/ActivityEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static RouteGroupBuilder MapActivityEndpoints(this WebApplication app)
.WithName("GetAllActivities")
.WithDescription("Gets all activities.")
.WithTags("Activities")
.RequireAuthorization()
.Produces<List<ActivityDTO>>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status500InternalServerError);

Expand Down Expand Up @@ -77,6 +78,7 @@ await dbContext.Entry(citizen)
.WithName("GetActivitiesForCitizenOnDate")
.WithDescription("Gets activities for a specific citizen on a given date.")
.WithTags("Activities")
.RequireAuthorization()
.Produces<List<ActivityDTO>>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status404NotFound)
.Produces(StatusCodes.Status500InternalServerError);
Expand Down Expand Up @@ -125,6 +127,7 @@ await dbContext.Entry(grade)
.WithName("GetActivitiesForGradeOnDate")
.WithDescription("Gets activities for a specific grade on a given date.")
.WithTags("Activities")
.RequireAuthorization()
.Produces<List<ActivityDTO>>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status404NotFound)
.Produces(StatusCodes.Status500InternalServerError);
Expand All @@ -149,6 +152,7 @@ await dbContext.Entry(grade)
.WithName("GetActivityById")
.WithDescription("Gets a specific activity by ID.")
.WithTags("Activities")
.RequireAuthorization()
.Produces<ActivityDTO>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status404NotFound)
.Produces(StatusCodes.Status500InternalServerError);
Expand Down Expand Up @@ -195,6 +199,7 @@ await dbContext.Entry(citizen)
.WithName("CreateActivityForCitizen")
.WithDescription("Creates a new activity for a citizen.")
.WithTags("Activities")
.RequireAuthorization()
.Accepts<CreateActivityDTO>("application/json")
.Produces<ActivityDTO>(StatusCodes.Status201Created)
.Produces(StatusCodes.Status404NotFound)
Expand Down Expand Up @@ -241,6 +246,7 @@ await dbContext.Entry(grade)
.WithName("CreateActivityForGrade")
.WithDescription("Creates a new activity for a grade.")
.WithTags("Activities")
.RequireAuthorization()
.Accepts<CreateActivityDTO>("application/json")
.Produces<ActivityDTO>(StatusCodes.Status201Created)
.Produces(StatusCodes.Status404NotFound)
Expand Down Expand Up @@ -294,7 +300,8 @@ await dbContext.Entry(citizen)
//unexpected errors
return Results.Problem("An error occurred while copying the activities.", statusCode: StatusCodes.Status500InternalServerError);
}
});
})
.RequireAuthorization();


// PUT updated activity
Expand Down Expand Up @@ -337,6 +344,7 @@ await dbContext.Entry(citizen)
.WithName("UpdateActivity")
.WithDescription("Updates an existing activity using ID.")
.WithTags("Activities")
.RequireAuthorization()
.Accepts<UpdateActivityDTO>("application/json")
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status404NotFound)
Expand Down Expand Up @@ -371,7 +379,8 @@ await dbContext.Entry(citizen)
// unexpected errors
return Results.Problem("An error occurred while updating the activity status.", statusCode: StatusCodes.Status500InternalServerError);
}
});
})
.RequireAuthorization();


// DELETE activity
Expand Down Expand Up @@ -402,6 +411,7 @@ await dbContext.Entry(citizen)
.WithName("DeleteActivity")
.WithDescription("Deletes an activity by ID.")
.WithTags("Activities")
.RequireAuthorization()
.Produces(StatusCodes.Status204NoContent)
.Produces(StatusCodes.Status404NotFound)
.Produces(StatusCodes.Status400BadRequest)
Expand Down Expand Up @@ -441,6 +451,7 @@ await dbContext.Entry(citizen)
.WithName("AssignPictogram")
.WithDescription("Assigns a pictogram by ID.")
.WithTags("Activities")
.RequireAuthorization()
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status404NotFound)
.Produces(StatusCodes.Status500InternalServerError);
Expand Down

0 comments on commit af5f0e3

Please sign in to comment.