mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
feat: enable adding relevant skills to events
This commit is contained in:
@@ -133,7 +133,7 @@ namespace WebApp.Endpoints
|
||||
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
User? user = await guh.GetUserFromToken(token);
|
||||
|
||||
// Tylko wolontariusze powinno móc dodawać swoje skille
|
||||
// Tylko wolontariusze powinni móc dodawać swoje skille
|
||||
if (user == null || user.IsOrganisation) {
|
||||
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||
}
|
||||
@@ -170,7 +170,7 @@ namespace WebApp.Endpoints
|
||||
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
User? user = await guh.GetUserFromToken(token);
|
||||
|
||||
// Tylko wolontariusze powinien móc usuwac swoje skille
|
||||
// Tylko wolontariusze powinni móc usuwać swoje skille
|
||||
if (user == null || user.IsOrganisation)
|
||||
{
|
||||
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||
@@ -183,13 +183,12 @@ namespace WebApp.Endpoints
|
||||
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||
}
|
||||
|
||||
// Sprawdzamy, czy ten użytkownik ma już taki skill. Jeżeli nie ma, nie ma sensu usuwac go kilkukrotnie.
|
||||
// Sprawdzamy, czy ten użytkownik ma już taki skill. Jeżeli nie ma, to nie ma sensu usuwać czegoś, czego nie ma.
|
||||
VolunteerSkill? vs = await context.VolunteerSkills.FirstOrDefaultAsync(v => v.UserId == user.UserId && v.SkillId == dto.Skill);
|
||||
if (vs is not null)
|
||||
{
|
||||
// Nie ma - zatem musimy dodać nowy VolunteerSkill do bazy
|
||||
// Ma - zatem musimy usunąć otrzymany VolunteerSkill z bazy
|
||||
VolunteerSkill newVs = dto.ToVolunteerSkillEntity(user.UserId);
|
||||
|
||||
|
||||
await context.VolunteerSkills.Where(v => v.SkillId == dto.Skill)
|
||||
.ExecuteDeleteAsync();
|
||||
@@ -197,7 +196,7 @@ namespace WebApp.Endpoints
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ma - (ta para UserId <-> SkillId już istnieje w bazie) użytkownik już ma ten skill
|
||||
// Nie ma - (ta para UserId <-> SkillId nie istnieje w bazie). Zwracamy błąd.
|
||||
return Results.Json(new { message = "You don't have this skill" }, statusCode: 400);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user