From 4a4cc30d66ac51331fa79c3b68fe51c965397949 Mon Sep 17 00:00:00 2001 From: PixieStick314 Date: Wed, 4 Dec 2024 12:23:49 +0100 Subject: [PATCH 1/5] minor --- GirafAPI/Endpoints/OrganizationEndpoints.cs | 65 ++++++++++----------- GirafAPI/Endpoints/PictogramEndpoints.cs | 2 +- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/GirafAPI/Endpoints/OrganizationEndpoints.cs b/GirafAPI/Endpoints/OrganizationEndpoints.cs index 5f72405..393566d 100644 --- a/GirafAPI/Endpoints/OrganizationEndpoints.cs +++ b/GirafAPI/Endpoints/OrganizationEndpoints.cs @@ -83,9 +83,7 @@ await dbContext.Entry(organization) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status500InternalServerError); - group.MapPost("/", - async (CreateOrganizationDTO newOrganization, GirafDbContext dbContext, - UserManager userManager, HttpContext httpContext) => + group.MapPost("/", async (CreateOrganizationDTO newOrganization, GirafDbContext dbContext, UserManager userManager, HttpContext httpContext) => { try { @@ -181,43 +179,42 @@ await dbContext.Entry(organization) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status500InternalServerError); - group.MapPut("/{orgId}/remove-user/{userId}", - async (int orgId, string userId, UserManager userManager, GirafDbContext dbContext) => + group.MapPut("/{orgId}/remove-user/{userId}", async (int orgId, string userId, UserManager userManager, GirafDbContext dbContext) => + { + try { - try + var user = await userManager.FindByIdAsync(userId); + if (user is null) { - var user = await userManager.FindByIdAsync(userId); - if (user is null) - { - return Results.BadRequest("Invalid user id."); - } + return Results.BadRequest("Invalid user id."); + } - var organization = await dbContext.Organizations.FindAsync(orgId); - if (organization is null) - { - return Results.BadRequest("Invalid organization id."); - } + var organization = await dbContext.Organizations.FindAsync(orgId); + if (organization is null) + { + return Results.BadRequest("Invalid organization id."); + } - await dbContext.Entry(organization) - .Collection(o => o.Users).LoadAsync(); - await dbContext.Entry(organization) - .Collection(o => o.Citizens).LoadAsync(); + await dbContext.Entry(organization) + .Collection(o => o.Users).LoadAsync(); + await dbContext.Entry(organization) + .Collection(o => o.Citizens).LoadAsync(); - organization.Users.Remove(user); + organization.Users.Remove(user); - await dbContext.SaveChangesAsync(); - - var claims = await userManager.GetClaimsAsync(user); - var claimToRemove = claims.FirstOrDefault(c => c.Type == "OrgMember" && c.Value == organization.Id.ToString()); - var result = await userManager.RemoveClaimAsync(user, claimToRemove); + await dbContext.SaveChangesAsync(); + + var claims = await userManager.GetClaimsAsync(user); + var claimToRemove = claims.FirstOrDefault(c => c.Type == "OrgMember" && c.Value == organization.Id.ToString()); + var result = await userManager.RemoveClaimAsync(user, claimToRemove); - return !result.Succeeded ? Results.BadRequest("Failed to remove organization claim.") : Results.Ok(organization.ToDTO()); - } - catch (Exception ex) - { - return Results.Problem(ex.Message, statusCode: StatusCodes.Status500InternalServerError); - } - }) + return !result.Succeeded ? Results.BadRequest("Failed to remove organization claim.") : Results.Ok(organization.ToDTO()); + } + catch (Exception ex) + { + return Results.Problem(ex.Message, statusCode: StatusCodes.Status500InternalServerError); + } + }) .WithName("RemoveUser") .WithDescription("Removes user from organization.") .WithTags("Organizations") @@ -344,4 +341,4 @@ await dbContext.Entry(organization) return group; } -} +} \ No newline at end of file diff --git a/GirafAPI/Endpoints/PictogramEndpoints.cs b/GirafAPI/Endpoints/PictogramEndpoints.cs index 8beaaac..0e1a37e 100644 --- a/GirafAPI/Endpoints/PictogramEndpoints.cs +++ b/GirafAPI/Endpoints/PictogramEndpoints.cs @@ -11,7 +11,7 @@ public static class PictogramEndpoints { public static RouteGroupBuilder MapPictogramEndpoints(this WebApplication app) { - var group = app.MapGroup("pictograms").AllowAnonymous(); + var group = app.MapGroup("pictograms"); // Can't use a DTO here since for the endpoint to work correctly with images, the image and the dto must both be multipart/form-data // but minimal apis can't map from multipart/form-data to a record DTO, only from application/json From 1d3131d8e3a32cef62dbd9793064405b1adee94e Mon Sep 17 00:00:00 2001 From: PixieStick314 Date: Wed, 4 Dec 2024 13:05:28 +0100 Subject: [PATCH 2/5] Fixed the two failing ones. --- Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs | 2 +- Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs | 5 ++++- GirafAPI/Endpoints/PictogramEndpoints.cs | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs index ad46b70..cfaabf9 100644 --- a/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs @@ -382,7 +382,7 @@ public async Task UpdateActivity_ReturnsOk_WhenActivityExists() StartTime: TimeOnly.FromDateTime(DateTime.UtcNow), EndTime: TimeOnly.FromDateTime(DateTime.UtcNow.AddHours(1)), IsCompleted: true, - PictogramId: null, + PictogramId: 1, CitizenId: 1 ); diff --git a/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs index 9178769..79fd0db 100644 --- a/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs @@ -244,8 +244,11 @@ public async Task GetPictogramsByOrganizationId_ReturnsEmptyList_WhenNoPictogram new Claim("OrgMember", organizationId.ToString()) }; + var currentPage = 1; + var pageSize = 10; + // Act - var response = await client.GetAsync($"/pictograms/organization/{organizationId}"); + var response = await client.GetAsync($"/pictograms/organizationId:int?organizationId={organizationId}¤tPage={currentPage}&pageSize={pageSize}"); // Assert response.EnsureSuccessStatusCode(); diff --git a/GirafAPI/Endpoints/PictogramEndpoints.cs b/GirafAPI/Endpoints/PictogramEndpoints.cs index 0e1a37e..b167828 100644 --- a/GirafAPI/Endpoints/PictogramEndpoints.cs +++ b/GirafAPI/Endpoints/PictogramEndpoints.cs @@ -62,6 +62,7 @@ public static RouteGroupBuilder MapPictogramEndpoints(this WebApplication app) .DisableAntiforgery() .WithName("CreatePictogram") .WithDescription("Creates a pictogram") + .RequireAuthorization("OrganizationMember") .WithTags("Pictograms") .Accepts("multipart/form-data") .Accepts("multipart/form-data") @@ -119,6 +120,7 @@ public static RouteGroupBuilder MapPictogramEndpoints(this WebApplication app) .WithName("GetPictogramsByOrgId") .WithDescription("Gets all the pictograms belonging to the specified organization.") .WithTags("Pictograms") + .RequireAuthorization("OrganizationMember") .Produces>(StatusCodes.Status200OK) .Produces(StatusCodes.Status400BadRequest) .Produces(StatusCodes.Status500InternalServerError); From 8281058d4bad7289bac8b53f750bb0327e808a1b Mon Sep 17 00:00:00 2001 From: NSpahic22 Date: Thu, 5 Dec 2024 14:41:58 +0100 Subject: [PATCH 3/5] Updated citizen testing to include auth + added collections to xunit can handle all the tests --- .../Endpoints/ActivityEndpointTests.cs | 1 + .../Endpoints/CitizensEndpointTests.cs | 116 ++++++++++++++---- .../Endpoints/GradeEndpointTests.cs | 1 + .../Endpoints/InvitationEndpointTests.cs | 1 + .../Endpoints/LoginEndpointTests.cs | 1 + .../Endpoints/OrganizationEndpointTests.cs | 3 +- .../Endpoints/PictogramEndpointTests.cs | 1 + .../Endpoints/UsersEndpointTests.cs | 1 + GirafAPI/Endpoints/CitizenEndpoints.cs | 5 + 9 files changed, 105 insertions(+), 25 deletions(-) diff --git a/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs index cfaabf9..3f7d829 100644 --- a/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs @@ -12,6 +12,7 @@ namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class ActivityEndpointTests { #region GET /weekplan/ - Get all activities diff --git a/Giraf.IntegrationTests/Endpoints/CitizensEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/CitizensEndpointTests.cs index cd7e9ef..3378606 100644 --- a/Giraf.IntegrationTests/Endpoints/CitizensEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/CitizensEndpointTests.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; using System.Net; using System.Net.Http.Json; -using System.Threading.Tasks; using Giraf.IntegrationTests.Utils; using Giraf.IntegrationTests.Utils.DbSeeders; using GirafAPI.Data; using GirafAPI.Entities.Citizens.DTOs; -using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using Xunit; +using System.Security.Claims; + + namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class CitizensEndpointTests { #region Get All Citizens Tests @@ -25,9 +25,16 @@ public async Task GetAllCitizens_ReturnsListOfCitizens() var factory = new GirafWebApplicationFactory(_ => new MultipleCitizensSeeder()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.GetAsync("/citizens"); + // Assert response.EnsureSuccessStatusCode(); var citizens = await response.Content.ReadFromJsonAsync>(); @@ -43,6 +50,12 @@ public async Task GetAllCitizens_ReturnsEmptyList_WhenNoCitizens() var factory = new GirafWebApplicationFactory(_ => new EmptyDb()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.GetAsync("/citizens"); @@ -65,6 +78,12 @@ public async Task GetCitizenById_ReturnsCitizen_WhenCitizenExists() var factory = new GirafWebApplicationFactory(_ => new BasicCitizenSeeder()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // First, get the list of citizens to obtain the ID var citizensResponse = await client.GetAsync("/citizens"); citizensResponse.EnsureSuccessStatusCode(); @@ -73,6 +92,8 @@ public async Task GetCitizenById_ReturnsCitizen_WhenCitizenExists() var citizenId = citizens[0].Id; + + // Act var response = await client.GetAsync($"/citizens/{citizenId}"); @@ -93,6 +114,12 @@ public async Task GetCitizenById_ReturnsNotFound_WhenCitizenDoesNotExist() var factory = new GirafWebApplicationFactory(_ => new EmptyDb()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.GetAsync("/citizens/999"); @@ -112,6 +139,12 @@ public async Task UpdateCitizen_ReturnsOk_WhenCitizenExists() var factory = new GirafWebApplicationFactory(_ => new BasicCitizenSeeder()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Get the citizen's ID var citizensResponse = await client.GetAsync("/citizens"); citizensResponse.EnsureSuccessStatusCode(); @@ -148,6 +181,12 @@ public async Task UpdateCitizen_ReturnsNotFound_WhenCitizenDoesNotExist() var updateCitizenDto = new UpdateCitizenDTO("FirstName", "LastName"); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.PutAsJsonAsync("/citizens/999", updateCitizenDto); @@ -168,30 +207,35 @@ public async Task AddCitizen_ReturnsOk_WhenOrganizationExists() var client = factory.CreateClient(); // Get the organization ID - using (var scope = factory.Services.CreateScope()) - { - var dbContext = scope.ServiceProvider.GetRequiredService(); - var organization = await dbContext.Organizations.FirstOrDefaultAsync(); - Assert.NotNull(organization); - var organizationId = organization.Id; + var scope = factory.Services.CreateScope(); + var dbContext = scope.ServiceProvider.GetRequiredService(); + var organization = await dbContext.Organizations.FirstOrDefaultAsync(); + Assert.NotNull(organization); + var organizationId = organization.Id; - var createCitizenDto = new CreateCitizenDTO("New", "Citizen"); + var createCitizenDto = new CreateCitizenDTO("New", "Citizen"); - // Act - var response = await client.PostAsJsonAsync($"/citizens/{organizationId}/add-citizen", createCitizenDto); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; - // Assert - response.EnsureSuccessStatusCode(); + // Act + var response = await client.PostAsJsonAsync($"/citizens/{organizationId}/add-citizen", createCitizenDto); - // Verify that the citizen was added - var getCitizensResponse = await client.GetAsync("/citizens"); - getCitizensResponse.EnsureSuccessStatusCode(); - var citizens = await getCitizensResponse.Content.ReadFromJsonAsync>(); - Assert.NotNull(citizens); - Assert.Single(citizens); - Assert.Equal("New", citizens[0].FirstName); - Assert.Equal("Citizen", citizens[0].LastName); - } + // Assert + response.EnsureSuccessStatusCode(); + + // Verify that the citizen was added + var getCitizensResponse = await client.GetAsync("/citizens"); + getCitizensResponse.EnsureSuccessStatusCode(); + var citizens = await getCitizensResponse.Content.ReadFromJsonAsync>(); + Assert.NotNull(citizens); + Assert.Single(citizens); + Assert.Equal("New", citizens[0].FirstName); + Assert.Equal("Citizen", citizens[0].LastName); + } // 8. Test POST /citizens/{id}/add-citizen when the organization does not exist. @@ -204,6 +248,12 @@ public async Task AddCitizen_ReturnsNotFound_WhenOrganizationDoesNotExist() var createCitizenDto = new CreateCitizenDTO("New", "Citizen"); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.PostAsJsonAsync("/citizens/999/add-citizen", createCitizenDto); @@ -235,6 +285,12 @@ public async Task RemoveCitizen_ReturnsNoContent_WhenCitizenExistsInOrganization Assert.NotNull(citizen); var citizenId = citizen.Id; + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.DeleteAsync($"/citizens/{organizationId}/remove-citizen/{citizenId}"); @@ -266,6 +322,12 @@ public async Task RemoveCitizen_ReturnsNotFound_WhenCitizenDoesNotExist() Assert.NotNull(organization); var organizationId = organization.Id; + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.DeleteAsync($"/citizens/{organizationId}/remove-citizen/999"); @@ -297,6 +359,12 @@ public async Task RemoveCitizen_ReturnsBadRequest_WhenCitizenNotInOrganization() Assert.NotNull(citizenNotInOrg); var citizenId = citizenNotInOrg.Id; + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + // Act var response = await client.DeleteAsync($"/citizens/{organization1.Id}/remove-citizen/{citizenId}"); diff --git a/Giraf.IntegrationTests/Endpoints/GradeEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/GradeEndpointTests.cs index ff1b3e2..8c2e310 100644 --- a/Giraf.IntegrationTests/Endpoints/GradeEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/GradeEndpointTests.cs @@ -9,6 +9,7 @@ namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class GradeEndpointsTests { #region 1. Get Grade by ID Tests diff --git a/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs index 84beed9..a9b147d 100644 --- a/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs @@ -13,6 +13,7 @@ namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class InvitationEndpointsTests { #region Get Invitation by ID Tests - Test 1-4 diff --git a/Giraf.IntegrationTests/Endpoints/LoginEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/LoginEndpointTests.cs index 50f6620..d38cb1d 100644 --- a/Giraf.IntegrationTests/Endpoints/LoginEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/LoginEndpointTests.cs @@ -8,6 +8,7 @@ namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class LoginEndpointTests { [Fact] diff --git a/Giraf.IntegrationTests/Endpoints/OrganizationEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/OrganizationEndpointTests.cs index f077382..5d9c721 100644 --- a/Giraf.IntegrationTests/Endpoints/OrganizationEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/OrganizationEndpointTests.cs @@ -12,6 +12,7 @@ namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class OrganizationEndpointsTests { #region Get Organizations for User Tests @@ -211,7 +212,7 @@ public async Task ChangeOrganizationName_ReturnsNotFound_WhenOrganizationDoesNot // Arrange var factory = new GirafWebApplicationFactory(_ => new EmptyDb()); var client = factory.CreateClient(); - var nonExistentOrgId = 9999; + var nonExistentOrgId = 1; var newName = "Nonexistent Organization Name"; // Act diff --git a/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs index 79fd0db..dcaebc3 100644 --- a/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs @@ -12,6 +12,7 @@ namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class PictogramEndpointsTests { #region Create Pictogram Tests diff --git a/Giraf.IntegrationTests/Endpoints/UsersEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/UsersEndpointTests.cs index 8ba7976..b4dfa43 100644 --- a/Giraf.IntegrationTests/Endpoints/UsersEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/UsersEndpointTests.cs @@ -12,6 +12,7 @@ namespace Giraf.IntegrationTests.Endpoints { + [Collection("IntegrationTests")] public class UsersEndpointTests { #region Create User Tests diff --git a/GirafAPI/Endpoints/CitizenEndpoints.cs b/GirafAPI/Endpoints/CitizenEndpoints.cs index ec28556..8fd9b3a 100644 --- a/GirafAPI/Endpoints/CitizenEndpoints.cs +++ b/GirafAPI/Endpoints/CitizenEndpoints.cs @@ -33,6 +33,7 @@ public static RouteGroupBuilder MapCitizensEndpoints(this WebApplication app) }) .WithName("GetAllCitizens") .WithTags("Citizens") + .RequireAuthorization("OrganizationMember") .WithDescription("Retrieves a list of all citizens.") .Produces>(StatusCodes.Status200OK) .Produces(StatusCodes.Status500InternalServerError); @@ -52,6 +53,7 @@ public static RouteGroupBuilder MapCitizensEndpoints(this WebApplication app) }) .WithName("GetCitizenById") .WithTags("Citizens") + .RequireAuthorization("OrganizationMember") .WithDescription("Retrieves a citizen by their ID.") .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status404NotFound) @@ -100,6 +102,7 @@ public static RouteGroupBuilder MapCitizensEndpoints(this WebApplication app) }) .WithName("UpdateCitizen") .WithTags("Citizens") + .RequireAuthorization("OrganizationMember") .WithDescription("Updates an existing citizen.") .Accepts("application/json") .Produces(StatusCodes.Status200OK) @@ -138,6 +141,7 @@ await dbContext.Entry(organization) .WithName("AddCitizen") .WithDescription("Add citizen to organization.") .WithTags("Organizations") + .RequireAuthorization("OrganizationMember") .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status500InternalServerError); @@ -174,6 +178,7 @@ await dbContext.Entry(organization) .WithName("RemoveCitizen") .WithDescription("Remove citizen from organization.") .WithTags("Organizations") + .RequireAuthorization("OrganizationMember") .Produces(StatusCodes.Status204NoContent) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status500InternalServerError); From 3fab1e30065b189e432807cfbbfa9c8b176ca7de Mon Sep 17 00:00:00 2001 From: NSpahic22 Date: Thu, 5 Dec 2024 15:05:04 +0100 Subject: [PATCH 4/5] Merged main into the branch, in hopes of fixing docker isssues --- .../Endpoints/InvitationEndpointTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs index 2fa09c7..6b1c6b6 100644 --- a/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/InvitationEndpointTests.cs @@ -126,7 +126,7 @@ public async Task GetUserInvitation_ReturnsInvitation_WhenInvitationExists() response.EnsureSuccessStatusCode(); } - //6. Tests if you get a Not Found if user doesn't have an invitation + //6. Tests if you get a OK if user doesn't have an invitation [Fact] public async Task GetUserInvitation_ReturnsNotFound_WhenNoInvitationExists() { @@ -139,9 +139,9 @@ public async Task GetUserInvitation_ReturnsNotFound_WhenNoInvitationExists() var response = await client.GetAsync($"/invitations/user/{fakeId}"); // Assert - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - //7. Tests if you get a Not Found if invitation is found but sender is null + //7. Tests if you get a OK if invitation is found but sender is null [Fact] public async Task GetUserInvitation_ReturnsNotFound_WhenInvitationExistsButSenderIsNull() { @@ -162,10 +162,10 @@ public async Task GetUserInvitation_ReturnsNotFound_WhenInvitationExistsButSende var response = await client.GetAsync($"/invitations/user/{existingRecievingUser}"); // Assert - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - //8. Tests if you get a Not Found if invitation is found but organization is null + //8. Tests if you get a OK if invitation is found but organization is null [Fact] public async Task GetUserInvitation_ReturnsNotFound_WhenInvitationExistsButOrganizationIsNull() { @@ -187,7 +187,7 @@ public async Task GetUserInvitation_ReturnsNotFound_WhenInvitationExistsButOrgan var response = await client.GetAsync($"/invitations/user/{existingRecievingUser}"); // Assert - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } #endregion @@ -318,7 +318,7 @@ public async Task PostInvitation_ReturnsCreated_IfSucessfullyCreated() public async Task PostInvitation_ReturnsBadRequest_IfRecieverNotFound() { // Arrange - var factory = new GirafWebApplicationFactory(sp => new OrganizationAndUser(sp.GetRequiredService>())); + var factory = new GirafWebApplicationFactory(sp => new UserWithOrganizationsSeeder(sp.GetRequiredService>())); var client = factory.CreateClient(); using var scope = factory.Services.CreateScope(); From 3e290a90a716ec7193bfeb9e2c2329975121a71b Mon Sep 17 00:00:00 2001 From: NSpahic22 Date: Thu, 5 Dec 2024 16:55:39 +0100 Subject: [PATCH 5/5] Opdated branch, so it doesn't have failing tests, due to new changes in main --- .../Endpoints/PictogramEndpointTests.cs | 28 +- .../20241126132157_InitialCreate.Designer.cs | 527 ------------------ .../20241126132157_InitialCreate.cs | 430 -------------- ... 20241205153220_InitialCreate.Designer.cs} | 6 +- ...ons.cs => 20241205153220_InitialCreate.cs} | 4 +- GirafAPI/Endpoints/CitizenEndpoints.cs | 10 +- GirafAPI/Endpoints/PictogramEndpoints.cs | 4 +- 7 files changed, 33 insertions(+), 976 deletions(-) delete mode 100644 GirafAPI/Data/Migrations/20241126132157_InitialCreate.Designer.cs delete mode 100644 GirafAPI/Data/Migrations/20241126132157_InitialCreate.cs rename GirafAPI/Data/Migrations/{20241204134150_DBMigrations.Designer.cs => 20241205153220_InitialCreate.Designer.cs} (99%) rename GirafAPI/Data/Migrations/{20241204134150_DBMigrations.cs => 20241205153220_InitialCreate.cs} (99%) diff --git a/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs b/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs index 9a8d11f..cfa9ee7 100644 --- a/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs +++ b/Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs @@ -115,6 +115,12 @@ public async Task CreatePictogram_ReturnsBadRequest_WhenPictogramNameIsMissing() var factory = new GirafWebApplicationFactory(_ => new BasicOrganizationSeeder()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + int organizationId; using (var scope = factory.Services.CreateScope()) @@ -200,6 +206,12 @@ public async Task GetPictogramsByOrganizationId_ReturnsPictograms_WhenPictograms var factory = new GirafWebApplicationFactory(_ => new BasicPictogramSeeder()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + int organizationId; using var scope = factory.Services.CreateScope(); @@ -228,6 +240,12 @@ public async Task GetPictogramsByOrganizationId_ReturnsEmptyList_WhenNoPictogram var factory = new GirafWebApplicationFactory(_ => new BasicOrganizationSeeder()); var client = factory.CreateClient(); + var testOrgId = 1; + TestAuthHandler.TestClaims = new List + { + new Claim("OrgMember", testOrgId.ToString()) + }; + int organizationId; using (var scope = factory.Services.CreateScope()) @@ -238,15 +256,11 @@ public async Task GetPictogramsByOrganizationId_ReturnsEmptyList_WhenNoPictogram organizationId = organization.Id; } - // Set up the test claims - TestAuthHandler.TestClaims = new List - { - new Claim(ClaimTypes.NameIdentifier, "test-user-id"), - new Claim("OrgMember", organizationId.ToString()) - }; + var currentPage = 1; + var pageSize = 10; // Act - var response = await client.GetAsync($"/pictograms/organization/{organizationId}"); + var response = await client.GetAsync($"/pictograms/organizationId:int?organizationId={organizationId}¤tPage={currentPage}&pageSize={pageSize}"); // Assert response.EnsureSuccessStatusCode(); diff --git a/GirafAPI/Data/Migrations/20241126132157_InitialCreate.Designer.cs b/GirafAPI/Data/Migrations/20241126132157_InitialCreate.Designer.cs deleted file mode 100644 index 465bd4f..0000000 --- a/GirafAPI/Data/Migrations/20241126132157_InitialCreate.Designer.cs +++ /dev/null @@ -1,527 +0,0 @@ -// -using System; -using GirafAPI.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace GirafAPI.Migrations -{ - [DbContext(typeof(GirafDbContext))] - [Migration("20241126132157_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "8.0.8"); - - modelBuilder.Entity("GirafAPI.Entities.Activities.Activity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("CitizenId") - .HasColumnType("INTEGER"); - - b.Property("Date") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("EndTime") - .HasColumnType("TEXT"); - - b.Property("GradeId") - .HasColumnType("INTEGER"); - - b.Property("IsCompleted") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("PictogramId") - .HasColumnType("INTEGER"); - - b.Property("StartTime") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("CitizenId"); - - b.HasIndex("GradeId"); - - b.HasIndex("PictogramId"); - - b.ToTable("Activities"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Citizens.Citizen", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("GradeId") - .HasColumnType("INTEGER"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("OrganizationId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("GradeId"); - - b.HasIndex("OrganizationId"); - - b.ToTable("Citizens"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Grades.Grade", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("OrganizationId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("OrganizationId"); - - b.ToTable("Grades"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Invitations.Invitation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("OrganizationId") - .HasColumnType("INTEGER"); - - b.Property("ReceiverId") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("SenderId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Invitations"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Organizations.Organization", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Organizations"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Pictograms.Pictogram", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("OrganizationId") - .HasColumnType("INTEGER"); - - b.Property("PictogramName") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("PictogramUrl") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Pictograms"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Users.GirafUser", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("AccessFailedCount") - .HasColumnType("INTEGER"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("EmailConfirmed") - .HasColumnType("INTEGER"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("TEXT"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.Property("LockoutEnabled") - .HasColumnType("INTEGER"); - - b.Property("LockoutEnd") - .HasColumnType("TEXT"); - - b.Property("NormalizedEmail") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("NormalizedUserName") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("PasswordHash") - .HasColumnType("TEXT"); - - b.Property("PhoneNumber") - .HasColumnType("TEXT"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("INTEGER"); - - b.Property("SecurityStamp") - .HasColumnType("TEXT"); - - b.Property("TwoFactorEnabled") - .HasColumnType("INTEGER"); - - b.Property("UserName") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("GirafUserOrganization", b => - { - b.Property("OrganizationsId") - .HasColumnType("INTEGER"); - - b.Property("UsersId") - .HasColumnType("TEXT"); - - b.HasKey("OrganizationsId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("GirafUserOrganization"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("ProviderKey") - .HasColumnType("TEXT"); - - b.Property("ProviderDisplayName") - .HasColumnType("TEXT"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("TEXT"); - - b.Property("RoleId") - .HasColumnType("TEXT"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("TEXT"); - - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Value") - .HasColumnType("TEXT"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("GirafAPI.Entities.Activities.Activity", b => - { - b.HasOne("GirafAPI.Entities.Citizens.Citizen", null) - .WithMany("Activities") - .HasForeignKey("CitizenId"); - - b.HasOne("GirafAPI.Entities.Grades.Grade", null) - .WithMany("Activities") - .HasForeignKey("GradeId"); - - b.HasOne("GirafAPI.Entities.Pictograms.Pictogram", "Pictogram") - .WithMany() - .HasForeignKey("PictogramId"); - - b.Navigation("Pictogram"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Citizens.Citizen", b => - { - b.HasOne("GirafAPI.Entities.Grades.Grade", null) - .WithMany("Citizens") - .HasForeignKey("GradeId"); - - b.HasOne("GirafAPI.Entities.Organizations.Organization", "Organization") - .WithMany("Citizens") - .HasForeignKey("OrganizationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Organization"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Grades.Grade", b => - { - b.HasOne("GirafAPI.Entities.Organizations.Organization", null) - .WithMany("Grades") - .HasForeignKey("OrganizationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("GirafUserOrganization", b => - { - b.HasOne("GirafAPI.Entities.Organizations.Organization", null) - .WithMany() - .HasForeignKey("OrganizationsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("GirafAPI.Entities.Users.GirafUser", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("GirafAPI.Entities.Users.GirafUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("GirafAPI.Entities.Users.GirafUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("GirafAPI.Entities.Users.GirafUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("GirafAPI.Entities.Users.GirafUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("GirafAPI.Entities.Citizens.Citizen", b => - { - b.Navigation("Activities"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Grades.Grade", b => - { - b.Navigation("Activities"); - - b.Navigation("Citizens"); - }); - - modelBuilder.Entity("GirafAPI.Entities.Organizations.Organization", b => - { - b.Navigation("Citizens"); - - b.Navigation("Grades"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/GirafAPI/Data/Migrations/20241126132157_InitialCreate.cs b/GirafAPI/Data/Migrations/20241126132157_InitialCreate.cs deleted file mode 100644 index 604b81a..0000000 --- a/GirafAPI/Data/Migrations/20241126132157_InitialCreate.cs +++ /dev/null @@ -1,430 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace GirafAPI.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - Name = table.Column(type: "TEXT", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "TEXT", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - UserName = table.Column(type: "TEXT", maxLength: 256, nullable: false), - Email = table.Column(type: "TEXT", maxLength: 256, nullable: false), - NormalizedUserName = table.Column(type: "TEXT", maxLength: 256, nullable: false), - NormalizedEmail = table.Column(type: "TEXT", maxLength: 256, nullable: false), - FirstName = table.Column(type: "TEXT", maxLength: 20, nullable: false), - LastName = table.Column(type: "TEXT", maxLength: 50, nullable: false), - EmailConfirmed = table.Column(type: "INTEGER", nullable: false), - PasswordHash = table.Column(type: "TEXT", nullable: true), - SecurityStamp = table.Column(type: "TEXT", nullable: true), - ConcurrencyStamp = table.Column(type: "TEXT", nullable: true), - PhoneNumber = table.Column(type: "TEXT", nullable: true), - PhoneNumberConfirmed = table.Column(type: "INTEGER", nullable: false), - TwoFactorEnabled = table.Column(type: "INTEGER", nullable: false), - LockoutEnd = table.Column(type: "TEXT", nullable: true), - LockoutEnabled = table.Column(type: "INTEGER", nullable: false), - AccessFailedCount = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Invitations", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - OrganizationId = table.Column(type: "INTEGER", nullable: false), - ReceiverId = table.Column(type: "TEXT", nullable: false), - SenderId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Invitations", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Organizations", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", maxLength: 100, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Organizations", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Pictograms", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - OrganizationId = table.Column(type: "INTEGER", nullable: true), - PictogramName = table.Column(type: "TEXT", nullable: false), - PictogramUrl = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Pictograms", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - RoleId = table.Column(type: "TEXT", nullable: false), - ClaimType = table.Column(type: "TEXT", nullable: true), - ClaimValue = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - UserId = table.Column(type: "TEXT", nullable: false), - ClaimType = table.Column(type: "TEXT", nullable: true), - ClaimValue = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "TEXT", nullable: false), - ProviderKey = table.Column(type: "TEXT", nullable: false), - ProviderDisplayName = table.Column(type: "TEXT", nullable: true), - UserId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(type: "TEXT", nullable: false), - RoleId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - columns: table => new - { - UserId = table.Column(type: "TEXT", nullable: false), - LoginProvider = table.Column(type: "TEXT", nullable: false), - Name = table.Column(type: "TEXT", nullable: false), - Value = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "GirafUserOrganization", - columns: table => new - { - OrganizationsId = table.Column(type: "INTEGER", nullable: false), - UsersId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_GirafUserOrganization", x => new { x.OrganizationsId, x.UsersId }); - table.ForeignKey( - name: "FK_GirafUserOrganization_AspNetUsers_UsersId", - column: x => x.UsersId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_GirafUserOrganization_Organizations_OrganizationsId", - column: x => x.OrganizationsId, - principalTable: "Organizations", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Grades", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - OrganizationId = table.Column(type: "INTEGER", nullable: false), - Name = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Grades", x => x.Id); - table.ForeignKey( - name: "FK_Grades_Organizations_OrganizationId", - column: x => x.OrganizationId, - principalTable: "Organizations", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Citizens", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - FirstName = table.Column(type: "TEXT", nullable: false), - LastName = table.Column(type: "TEXT", nullable: false), - OrganizationId = table.Column(type: "INTEGER", nullable: false), - GradeId = table.Column(type: "INTEGER", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Citizens", x => x.Id); - table.ForeignKey( - name: "FK_Citizens_Grades_GradeId", - column: x => x.GradeId, - principalTable: "Grades", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Citizens_Organizations_OrganizationId", - column: x => x.OrganizationId, - principalTable: "Organizations", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Activities", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Date = table.Column(type: "TEXT", nullable: false), - Name = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", nullable: false), - StartTime = table.Column(type: "TEXT", nullable: false), - EndTime = table.Column(type: "TEXT", nullable: false), - IsCompleted = table.Column(type: "INTEGER", nullable: false), - PictogramId = table.Column(type: "INTEGER", nullable: true), - CitizenId = table.Column(type: "INTEGER", nullable: true), - GradeId = table.Column(type: "INTEGER", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Activities", x => x.Id); - table.ForeignKey( - name: "FK_Activities_Citizens_CitizenId", - column: x => x.CitizenId, - principalTable: "Citizens", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Activities_Grades_GradeId", - column: x => x.GradeId, - principalTable: "Grades", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Activities_Pictograms_PictogramId", - column: x => x.PictogramId, - principalTable: "Pictograms", - principalColumn: "Id"); - }); - - migrationBuilder.CreateIndex( - name: "IX_Activities_CitizenId", - table: "Activities", - column: "CitizenId"); - - migrationBuilder.CreateIndex( - name: "IX_Activities_GradeId", - table: "Activities", - column: "GradeId"); - - migrationBuilder.CreateIndex( - name: "IX_Activities_PictogramId", - table: "Activities", - column: "PictogramId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "AspNetRoles", - column: "NormalizedName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Citizens_GradeId", - table: "Citizens", - column: "GradeId"); - - migrationBuilder.CreateIndex( - name: "IX_Citizens_OrganizationId", - table: "Citizens", - column: "OrganizationId"); - - migrationBuilder.CreateIndex( - name: "IX_GirafUserOrganization_UsersId", - table: "GirafUserOrganization", - column: "UsersId"); - - migrationBuilder.CreateIndex( - name: "IX_Grades_OrganizationId", - table: "Grades", - column: "OrganizationId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Activities"); - - migrationBuilder.DropTable( - name: "AspNetRoleClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens"); - - migrationBuilder.DropTable( - name: "GirafUserOrganization"); - - migrationBuilder.DropTable( - name: "Invitations"); - - migrationBuilder.DropTable( - name: "Citizens"); - - migrationBuilder.DropTable( - name: "Pictograms"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - - migrationBuilder.DropTable( - name: "Grades"); - - migrationBuilder.DropTable( - name: "Organizations"); - } - } -} diff --git a/GirafAPI/Data/Migrations/20241204134150_DBMigrations.Designer.cs b/GirafAPI/Data/Migrations/20241205153220_InitialCreate.Designer.cs similarity index 99% rename from GirafAPI/Data/Migrations/20241204134150_DBMigrations.Designer.cs rename to GirafAPI/Data/Migrations/20241205153220_InitialCreate.Designer.cs index 456a092..84ea2c7 100644 --- a/GirafAPI/Data/Migrations/20241204134150_DBMigrations.Designer.cs +++ b/GirafAPI/Data/Migrations/20241205153220_InitialCreate.Designer.cs @@ -8,11 +8,11 @@ #nullable disable -namespace GirafAPI.Data.Migrations +namespace GirafAPI.Migrations { [DbContext(typeof(GirafDbContext))] - [Migration("20241204134150_DBMigrations")] - partial class DBMigrations + [Migration("20241205153220_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/GirafAPI/Data/Migrations/20241204134150_DBMigrations.cs b/GirafAPI/Data/Migrations/20241205153220_InitialCreate.cs similarity index 99% rename from GirafAPI/Data/Migrations/20241204134150_DBMigrations.cs rename to GirafAPI/Data/Migrations/20241205153220_InitialCreate.cs index 97c9f1e..e6fe6da 100644 --- a/GirafAPI/Data/Migrations/20241204134150_DBMigrations.cs +++ b/GirafAPI/Data/Migrations/20241205153220_InitialCreate.cs @@ -3,10 +3,10 @@ #nullable disable -namespace GirafAPI.Data.Migrations +namespace GirafAPI.Migrations { /// - public partial class DBMigrations : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/GirafAPI/Endpoints/CitizenEndpoints.cs b/GirafAPI/Endpoints/CitizenEndpoints.cs index 8fd9b3a..f9f464f 100644 --- a/GirafAPI/Endpoints/CitizenEndpoints.cs +++ b/GirafAPI/Endpoints/CitizenEndpoints.cs @@ -33,7 +33,7 @@ public static RouteGroupBuilder MapCitizensEndpoints(this WebApplication app) }) .WithName("GetAllCitizens") .WithTags("Citizens") - .RequireAuthorization("OrganizationMember") + .RequireAuthorization("OrgMember") .WithDescription("Retrieves a list of all citizens.") .Produces>(StatusCodes.Status200OK) .Produces(StatusCodes.Status500InternalServerError); @@ -53,7 +53,7 @@ public static RouteGroupBuilder MapCitizensEndpoints(this WebApplication app) }) .WithName("GetCitizenById") .WithTags("Citizens") - .RequireAuthorization("OrganizationMember") + .RequireAuthorization("OrgMember") .WithDescription("Retrieves a citizen by their ID.") .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status404NotFound) @@ -102,7 +102,7 @@ public static RouteGroupBuilder MapCitizensEndpoints(this WebApplication app) }) .WithName("UpdateCitizen") .WithTags("Citizens") - .RequireAuthorization("OrganizationMember") + .RequireAuthorization("OrgMember") .WithDescription("Updates an existing citizen.") .Accepts("application/json") .Produces(StatusCodes.Status200OK) @@ -141,7 +141,7 @@ await dbContext.Entry(organization) .WithName("AddCitizen") .WithDescription("Add citizen to organization.") .WithTags("Organizations") - .RequireAuthorization("OrganizationMember") + .RequireAuthorization("OrgMember") .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status500InternalServerError); @@ -178,7 +178,7 @@ await dbContext.Entry(organization) .WithName("RemoveCitizen") .WithDescription("Remove citizen from organization.") .WithTags("Organizations") - .RequireAuthorization("OrganizationMember") + .RequireAuthorization("OrgMember") .Produces(StatusCodes.Status204NoContent) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status500InternalServerError); diff --git a/GirafAPI/Endpoints/PictogramEndpoints.cs b/GirafAPI/Endpoints/PictogramEndpoints.cs index b167828..2f8a8e9 100644 --- a/GirafAPI/Endpoints/PictogramEndpoints.cs +++ b/GirafAPI/Endpoints/PictogramEndpoints.cs @@ -62,7 +62,7 @@ public static RouteGroupBuilder MapPictogramEndpoints(this WebApplication app) .DisableAntiforgery() .WithName("CreatePictogram") .WithDescription("Creates a pictogram") - .RequireAuthorization("OrganizationMember") + .RequireAuthorization("OrgMember") .WithTags("Pictograms") .Accepts("multipart/form-data") .Accepts("multipart/form-data") @@ -120,7 +120,7 @@ public static RouteGroupBuilder MapPictogramEndpoints(this WebApplication app) .WithName("GetPictogramsByOrgId") .WithDescription("Gets all the pictograms belonging to the specified organization.") .WithTags("Pictograms") - .RequireAuthorization("OrganizationMember") + .RequireAuthorization("OrgMember") .Produces>(StatusCodes.Status200OK) .Produces(StatusCodes.Status400BadRequest) .Produces(StatusCodes.Status500InternalServerError);