Skip to content

Commit 8195551

Browse files
committed
role permission and code cleanup and other fixes
1 parent 2142190 commit 8195551

File tree

78 files changed

+751
-1370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+751
-1370
lines changed

backend/scripts/seed-data.sql

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CREATE TABLE IF NOT EXISTS "Pages" (
4444
"Id" UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
4545
"Name" VARCHAR(100) NOT NULL,
4646
"Url" VARCHAR(250) NOT NULL,
47+
"Order" INT NOT NULL DEFAULT 0,
4748
"CreatedOn" TIMESTAMP WITH TIME ZONE NOT NULL,
4849
"CreatedBy" UUID NOT NULL,
4950
"UpdatedOn" TIMESTAMP WITH TIME ZONE,
@@ -152,17 +153,15 @@ INSERT INTO "Operations" ("Id", "Name", "Description", "CreatedOn", "CreatedBy")
152153
('09be3f29-6429-4089-a2a9-a17efe46cd7b', 'Create', 'Create', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb');
153154

154155
-- Insert data into Pages table
155-
INSERT INTO "Pages" ("Id", "Name", "Url", "CreatedOn", "CreatedBy") VALUES
156-
('aa56a391-e880-4ac5-9f6f-6c8aa33454b8', 'Contacts', '/contacts', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
157-
('c4943131-a642-4352-9725-e44ba5972b4b', 'Users', 'admin/users', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
158-
('c4943131-a642-4352-9725-e44ba5972b4c', 'ActivityLog', 'admin/activity-logs', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
159-
('d4943131-a642-4352-9725-e44ba5972b4d', 'Pages', 'admin/pages', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
160-
('e4943131-a642-4352-9725-e44ba5972b4e', 'Operations', 'admin/operations', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
161-
('f4943131-a642-4352-9725-e44ba5972b4f', 'Permissions', 'admin/permissions', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
162-
('84943131-a642-4352-9725-e44ba5972b48', 'RolePermissions', 'admin/role-permissions', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
163-
('94943131-a642-4352-9725-e44ba5972b49', 'UserRoles', 'admin/user-roles', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
164-
('a4943131-a642-4352-9725-e44ba5972b47', 'Roles', 'admin/roles', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
165-
('b4943131-a642-4352-9725-e44ba5972b46', 'RolePermissionMapping', 'admin/role-permission-mapping', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb');
156+
INSERT INTO "Pages" ("Id", "Name", "Url", "Order", "CreatedOn", "CreatedBy") VALUES
157+
('e4943131-a642-4352-9725-e44ba5972b4e', 'Operations', 'admin/operations', 3, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
158+
('d4943131-a642-4352-9725-e44ba5972b4d', 'Pages', 'admin/pages', 2, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
159+
('a4943131-a642-4352-9725-e44ba5972b47', 'Roles', 'admin/roles', 4, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
160+
('b4943131-a642-4352-9725-e44ba5972b46', 'RolePermissionMapping', 'admin/role-permission-mapping', 5, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
161+
('c4943131-a642-4352-9725-e44ba5972b4b', 'Users', 'admin/users', 6, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
162+
('94943131-a642-4352-9725-e44ba5972b49', 'UserRoles', 'admin/user-roles', 7, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
163+
('aa56a391-e880-4ac5-9f6f-6c8aa33454b8', 'Contacts', '/contacts', 1, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
164+
('c4943131-a642-4352-9725-e44ba5972b4c', 'ActivityLog', 'admin/activity-logs', 10, NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb');
166165

167166
-- Insert data into Roles table
168167
INSERT INTO "Roles" ("Id", "Name", "Description", "CreatedOn", "CreatedBy") VALUES
@@ -204,20 +203,6 @@ INSERT INTO "Permissions" ("Id", "PageId", "OperationId", "Description", "Create
204203
('d35daa4e-fd02-4934-98d2-5b06e9b694c5', 'e4943131-a642-4352-9725-e44ba5972b4e', 'dce8d805-df41-4549-be7b-6ed5647b09c3', 'Operations Update', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
205204
('d35daa4e-fd02-4934-98d2-5b06e9b694c6', 'e4943131-a642-4352-9725-e44ba5972b4e', '7493f274-5007-4e17-9840-88c9a096422f', 'Operations Read', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
206205
('d35daa4e-fd02-4934-98d2-5b06e9b694c7', 'e4943131-a642-4352-9725-e44ba5972b4e', 'cef15d6f-25e4-422b-a7d6-405aaa2de2d5', 'Operations Delete', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
207-
('d35daa4e-fd02-4934-98d2-5b06e9b694c8', 'f4943131-a642-4352-9725-e44ba5972b4f', '09be3f29-6429-4089-a2a9-a17efe46cd7b', 'Permissions Create', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
208-
('d35daa4e-fd02-4934-98d2-5b06e9b694c9', 'f4943131-a642-4352-9725-e44ba5972b4f', 'dce8d805-df41-4549-be7b-6ed5647b09c3', 'Permissions Update', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
209-
('d35daa4e-fd02-4934-98d2-5b06e9b694d0', 'f4943131-a642-4352-9725-e44ba5972b4f', '7493f274-5007-4e17-9840-88c9a096422f', 'Permissions Read', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
210-
('d35daa4e-fd02-4934-98d2-5b06e9b694d1', 'f4943131-a642-4352-9725-e44ba5972b4f', 'cef15d6f-25e4-422b-a7d6-405aaa2de2d5', 'Permissions Delete', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
211-
-- Add permissions for RolePermissions page
212-
('e35daa4e-fd02-4934-98d2-5b06e9b694d2', '84943131-a642-4352-9725-e44ba5972b48', '09be3f29-6429-4089-a2a9-a17efe46cd7b', 'RolePermissions Create', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
213-
('e35daa4e-fd02-4934-98d2-5b06e9b694d3', '84943131-a642-4352-9725-e44ba5972b48', 'dce8d805-df41-4549-be7b-6ed5647b09c3', 'RolePermissions Update', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
214-
('e35daa4e-fd02-4934-98d2-5b06e9b694d4', '84943131-a642-4352-9725-e44ba5972b48', '7493f274-5007-4e17-9840-88c9a096422f', 'RolePermissions Read', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
215-
('e35daa4e-fd02-4934-98d2-5b06e9b694d5', '84943131-a642-4352-9725-e44ba5972b48', 'cef15d6f-25e4-422b-a7d6-405aaa2de2d5', 'RolePermissions Delete', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
216-
-- Add permissions for UserRoles page
217-
('f35daa4e-fd02-4934-98d2-5b06e9b694d6', '94943131-a642-4352-9725-e44ba5972b49', '09be3f29-6429-4089-a2a9-a17efe46cd7b', 'UserRoles Create', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
218-
('f35daa4e-fd02-4934-98d2-5b06e9b694d7', '94943131-a642-4352-9725-e44ba5972b49', 'dce8d805-df41-4549-be7b-6ed5647b09c3', 'UserRoles Update', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
219-
('f35daa4e-fd02-4934-98d2-5b06e9b694d8', '94943131-a642-4352-9725-e44ba5972b49', '7493f274-5007-4e17-9840-88c9a096422f', 'UserRoles Read', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
220-
('f35daa4e-fd02-4934-98d2-5b06e9b694d9', '94943131-a642-4352-9725-e44ba5972b49', 'cef15d6f-25e4-422b-a7d6-405aaa2de2d5', 'UserRoles Delete', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
221206
-- Add permissions for Roles page
222207
('635daa4e-fd02-4934-98d2-5b06e9b694e1', 'a4943131-a642-4352-9725-e44ba5972b47', '09be3f29-6429-4089-a2a9-a17efe46cd7b', 'Roles Create', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
223208
('635daa4e-fd02-4934-98d2-5b06e9b694e2', 'a4943131-a642-4352-9725-e44ba5972b47', 'dce8d805-df41-4549-be7b-6ed5647b09c3', 'Roles Update', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
@@ -227,7 +212,12 @@ INSERT INTO "Permissions" ("Id", "PageId", "OperationId", "Description", "Create
227212
('735daa4e-fd02-4934-98d2-5b06e9b694e5', 'b4943131-a642-4352-9725-e44ba5972b46', '09be3f29-6429-4089-a2a9-a17efe46cd7b', 'RolePermissionMapping Create', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
228213
('735daa4e-fd02-4934-98d2-5b06e9b694e6', 'b4943131-a642-4352-9725-e44ba5972b46', 'dce8d805-df41-4549-be7b-6ed5647b09c3', 'RolePermissionMapping Update', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
229214
('735daa4e-fd02-4934-98d2-5b06e9b694e7', 'b4943131-a642-4352-9725-e44ba5972b46', '7493f274-5007-4e17-9840-88c9a096422f', 'RolePermissionMapping Read', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
230-
('735daa4e-fd02-4934-98d2-5b06e9b694e8', 'b4943131-a642-4352-9725-e44ba5972b46', 'cef15d6f-25e4-422b-a7d6-405aaa2de2d5', 'RolePermissionMapping Delete', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb');
215+
('735daa4e-fd02-4934-98d2-5b06e9b694e8', 'b4943131-a642-4352-9725-e44ba5972b46', 'cef15d6f-25e4-422b-a7d6-405aaa2de2d5', 'RolePermissionMapping Delete', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
216+
-- Add permissions for UserRoles page
217+
('f35daa4e-fd02-4934-98d2-5b06e9b694d6', '94943131-a642-4352-9725-e44ba5972b49', '09be3f29-6429-4089-a2a9-a17efe46cd7b', 'UserRoles Create', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
218+
('f35daa4e-fd02-4934-98d2-5b06e9b694d7', '94943131-a642-4352-9725-e44ba5972b49', 'dce8d805-df41-4549-be7b-6ed5647b09c3', 'UserRoles Update', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
219+
('f35daa4e-fd02-4934-98d2-5b06e9b694d8', '94943131-a642-4352-9725-e44ba5972b49', '7493f274-5007-4e17-9840-88c9a096422f', 'UserRoles Read', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
220+
('f35daa4e-fd02-4934-98d2-5b06e9b694d9', '94943131-a642-4352-9725-e44ba5972b49', 'cef15d6f-25e4-422b-a7d6-405aaa2de2d5', 'UserRoles Delete', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb');
231221

232222
-- Set up admin role permissions
233223
INSERT INTO "RolePermissions" ("RoleId", "PermissionId", "CreatedOn", "CreatedBy") VALUES
@@ -248,15 +238,6 @@ INSERT INTO "RolePermissions" ("RoleId", "PermissionId", "CreatedOn", "CreatedBy
248238
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'd35daa4e-fd02-4934-98d2-5b06e9b694c5', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
249239
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'd35daa4e-fd02-4934-98d2-5b06e9b694c6', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
250240
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'd35daa4e-fd02-4934-98d2-5b06e9b694c7', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
251-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'd35daa4e-fd02-4934-98d2-5b06e9b694c8', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
252-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'd35daa4e-fd02-4934-98d2-5b06e9b694c9', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
253-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'd35daa4e-fd02-4934-98d2-5b06e9b694d0', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
254-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'd35daa4e-fd02-4934-98d2-5b06e9b694d1', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
255-
-- Assign RolePermissions permissions to admin role
256-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'e35daa4e-fd02-4934-98d2-5b06e9b694d2', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
257-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'e35daa4e-fd02-4934-98d2-5b06e9b694d3', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
258-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'e35daa4e-fd02-4934-98d2-5b06e9b694d4', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
259-
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'e35daa4e-fd02-4934-98d2-5b06e9b694d5', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
260241
-- Assign UserRoles permissions to admin role
261242
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'f35daa4e-fd02-4934-98d2-5b06e9b694d6', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),
262243
('d95d2348-1d79-4b93-96d4-e48e87fcb4b5', 'f35daa4e-fd02-4934-98d2-5b06e9b694d7', NOW(), '26402b6c-ebdd-44c3-9188-659a134819cb'),

backend/src/Contact.Api/Controllers/ContactPersonController.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,26 @@ namespace Contact.Api.Controllers;
99
[Route("api/[controller]")]
1010
[ApiController]
1111
[Authorize]
12-
public class ContactPersonController : ControllerBase
12+
public class ContactPersonController(IContactPersonService contactPersonService) : ControllerBase
1313
{
14-
private readonly IContactPersonService _contactPersonService;
15-
16-
public ContactPersonController(IContactPersonService contactPersonService)
17-
{
18-
_contactPersonService = contactPersonService;
19-
}
20-
2114
[HttpPost]
2215
[ActivityLog("Creating new Contact")]
2316
[AuthorizePermission("Contacts.Create")]
2417
public async Task<IActionResult> Add(CreateContactPerson createContactPerson)
2518
{
26-
var createdContactPerson = await _contactPersonService.Add(createContactPerson);
19+
var createdContactPerson = await contactPersonService.Add(createContactPerson);
2720
return CreatedAtAction(nameof(GetById), new { id = createdContactPerson.Id }, createdContactPerson);
2821
}
2922

3023
[HttpPut("{id}")]
3124
[ActivityLog("Updating Contact")]
3225
[AuthorizePermission("Contacts.Update")]
33-
public async Task<IActionResult> Update(Guid id,UpdateContactPerson updateContactPerson)
26+
public async Task<IActionResult> Update(Guid id, UpdateContactPerson updateContactPerson)
3427
{
35-
var contactPerson = await _contactPersonService.FindByID(id);
36-
if (contactPerson == null) return NotFound();
37-
var updatedContactPerson = await _contactPersonService.Update(updateContactPerson);
28+
var contactPerson = await contactPersonService.FindByID(id);
29+
if (contactPerson is null) return NotFound();
30+
31+
var updatedContactPerson = await contactPersonService.Update(updateContactPerson);
3832
return Ok(updatedContactPerson);
3933
}
4034

@@ -43,27 +37,25 @@ public async Task<IActionResult> Update(Guid id,UpdateContactPerson updateContac
4337
[AuthorizePermission("Contacts.Delete")]
4438
public async Task<IActionResult> Delete(Guid id)
4539
{
46-
var deleted = await _contactPersonService.Delete(id);
47-
if (!deleted) return NotFound();
48-
return NoContent();
40+
var deleted = await contactPersonService.Delete(id);
41+
return deleted ? NoContent() : NotFound();
4942
}
5043

5144
[HttpGet("{id}")]
5245
[ActivityLog("Reading Contact By id")]
5346
[AuthorizePermission("Contacts.Read")]
5447
public async Task<IActionResult> GetById(Guid id)
5548
{
56-
var contactPerson = await _contactPersonService.FindByID(id);
57-
if (contactPerson == null) return NotFound();
58-
return Ok(contactPerson);
49+
var contactPerson = await contactPersonService.FindByID(id);
50+
return contactPerson is null ? NotFound() : Ok(contactPerson);
5951
}
6052

6153
[HttpGet]
6254
[ActivityLog("Reading All Contacts")]
6355
[AuthorizePermission("Contacts.Read")]
6456
public async Task<IActionResult> GetAll()
6557
{
66-
var contactPersons = await _contactPersonService.FindAll();
58+
var contactPersons = await contactPersonService.FindAll();
6759
return Ok(contactPersons);
6860
}
6961
}
Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
1+
using Contact.Api.Core.Attributes;
12
using Contact.Application.Interfaces;
23
using Contact.Application.UseCases.Operations;
3-
using Microsoft.AspNetCore.Authorization;
44
using Microsoft.AspNetCore.Mvc;
55

66
namespace Contact.Api.Controllers;
77

88
[Route("api/[controller]")]
99
[ApiController]
10-
public class OperationsController : ControllerBase
10+
public class OperationsController(IOperationService operationService) : ControllerBase
1111
{
12-
private readonly IOperationService _operationService;
13-
14-
public OperationsController(IOperationService operationService)
15-
{
16-
_operationService = operationService;
17-
}
18-
1912
[HttpPost]
20-
[Authorize(Roles = "Admin")]
21-
public async Task<IActionResult> AddOperation(CreateOperation createOperation)
22-
{
23-
var response = await _operationService.Add(createOperation);
24-
return Ok(response);
25-
}
13+
[AuthorizePermission("Operations.Create")]
14+
[ActivityLog("Creating new Operation")]
15+
public async Task<IActionResult> AddOperation(CreateOperation createOperation) =>
16+
Ok(await operationService.Add(createOperation));
2617

2718
[HttpPut("{id}")]
28-
[Authorize(Roles = "Admin")]
19+
[AuthorizePermission("Operations.Update")]
20+
[ActivityLog("Updating Operation")]
2921
public async Task<IActionResult> UpdateOperation(Guid id, UpdateOperation updateOperation)
3022
{
3123
updateOperation.Id = id;
32-
var response = await _operationService.Update(updateOperation);
33-
return Ok(response);
24+
return Ok(await operationService.Update(updateOperation));
3425
}
3526

3627
[HttpGet]
37-
[Authorize(Roles = "Admin")]
38-
public async Task<IActionResult> GetOperations()
39-
{
40-
var response = await _operationService.FindAll();
41-
return Ok(response);
42-
}
28+
[AuthorizePermission("Operations.Read")]
29+
[ActivityLog("Fetching all Operations")]
30+
public async Task<IActionResult> GetOperations() =>
31+
Ok(await operationService.FindAll());
4332

4433
[HttpDelete("{id}")]
45-
[Authorize(Roles = "Admin")]
46-
public async Task<IActionResult> DeleteOperation(Guid id)
47-
{
48-
var response = await _operationService.Delete(id);
49-
return Ok(response);
50-
}
34+
[AuthorizePermission("Operations.Delete")]
35+
[ActivityLog("Deleting Operation")]
36+
public async Task<IActionResult> DeleteOperation(Guid id) =>
37+
Ok(await operationService.Delete(id));
5138
}
Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
1+
using Contact.Api.Core.Attributes;
12
using Contact.Application.Interfaces;
23
using Contact.Application.UseCases.Pages;
3-
using Microsoft.AspNetCore.Authorization;
44
using Microsoft.AspNetCore.Mvc;
55

66
namespace Contact.Api.Controllers;
77

88
[Route("api/[controller]")]
99
[ApiController]
10-
public class PagesController : ControllerBase
10+
public class PagesController(IPageService pageService) : ControllerBase
1111
{
12-
private readonly IPageService _pageService;
13-
14-
public PagesController(IPageService pageService)
15-
{
16-
_pageService = pageService;
17-
}
18-
1912
[HttpPost]
20-
[Authorize(Roles = "Admin")]
21-
public async Task<IActionResult> AddPage(CreatePage createPage)
22-
{
23-
var response = await _pageService.Add(createPage);
24-
return Ok(response);
25-
}
13+
[AuthorizePermission("Pages.Create")]
14+
[ActivityLog("Creating new Page")]
15+
public async Task<IActionResult> AddPage(CreatePage createPage) =>
16+
Ok(await pageService.Add(createPage));
2617

2718
[HttpPut("{id}")]
28-
[Authorize(Roles = "Admin")]
19+
[AuthorizePermission("Pages.Update")]
20+
[ActivityLog("Updating Page")]
2921
public async Task<IActionResult> UpdatePage(Guid id, UpdatePage updatePage)
3022
{
3123
updatePage.Id = id;
32-
var response = await _pageService.Update(updatePage);
33-
return Ok(response);
24+
return Ok(await pageService.Update(updatePage));
3425
}
3526

3627
[HttpGet]
37-
[Authorize(Roles = "Admin")]
38-
public async Task<IActionResult> GetPages()
39-
{
40-
var response = await _pageService.FindAll();
41-
return Ok(response);
42-
}
28+
[AuthorizePermission("Pages.Read")]
29+
[ActivityLog("Fetching all Pages")]
30+
public async Task<IActionResult> GetPages() =>
31+
Ok(await pageService.FindAll());
4332

4433
[HttpDelete("{id}")]
45-
[Authorize(Roles = "Admin")]
46-
public async Task<IActionResult> DeletePage(Guid id)
47-
{
48-
var response = await _pageService.Delete(id);
49-
return Ok(response);
50-
}
34+
[AuthorizePermission("pages.Delete")]
35+
[ActivityLog("Deleting Page")]
36+
public async Task<IActionResult> DeletePage(Guid id) =>
37+
Ok(await pageService.Delete(id));
5138
}
Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,12 @@
11
using Contact.Application.Interfaces;
2-
using Contact.Application.UseCases.Permissions;
3-
using Microsoft.AspNetCore.Authorization;
42
using Microsoft.AspNetCore.Mvc;
53

64
namespace Contact.Api.Controllers;
75

86
[Route("api/[controller]")]
97
[ApiController]
10-
public class PermissionsController : ControllerBase
8+
public class PermissionsController(IPermissionService permissionService) : ControllerBase
119
{
12-
private readonly IPermissionService _permissionService;
13-
14-
public PermissionsController(IPermissionService permissionService)
15-
{
16-
_permissionService = permissionService;
17-
}
18-
19-
[HttpPost]
20-
[Authorize(Roles = "Admin")]
21-
public async Task<IActionResult> AddPermission(CreatePermission createPermission)
22-
{
23-
var response = await _permissionService.Add(createPermission);
24-
return Ok(response);
25-
}
26-
27-
[HttpPut("{id}")]
28-
[Authorize(Roles = "Admin")]
29-
public async Task<IActionResult> UpdatePermission(Guid id, UpdatePermission updatePermission)
30-
{
31-
updatePermission.Id = id;
32-
var response = await _permissionService.Update(updatePermission);
33-
return Ok(response);
34-
}
35-
36-
[HttpGet]
37-
[Authorize(Roles = "Admin")]
38-
public async Task<IActionResult> GetPermissions()
39-
{
40-
var response = await _permissionService.GetAllPageOperationMappingsAsync();
41-
return Ok(response);
42-
}
43-
44-
[HttpDelete("{id}")]
45-
[Authorize(Roles = "Admin")]
46-
public async Task<IActionResult> DeletePermission(Guid id)
47-
{
48-
var response = await _permissionService.Delete(id);
49-
return Ok(response);
50-
}
10+
// All endpoints are currently commented out
11+
// Using primary constructor for dependency injection
5112
}

0 commit comments

Comments
 (0)