Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic authorization to activity endpoints #129

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading