Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
ProjectsStatusManagement
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
ProjectsStatusManagement
Commits
69af1fba
Commit
69af1fba
authored
Aug 11, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Role Controller and userRoles Controller and some fixed error
parent
c2f1792e
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
190 additions
and
20 deletions
+190
-20
APIController.cs
PSManagement.Api/Controllers/ApiBase/APIController.cs
+15
-0
AuthenticationController.cs
...pi/Controllers/Authentication/AuthenticationController.cs
+5
-5
CustomersController.cs
...nagement.Api/Controllers/Customers/CustomersController.cs
+5
-6
EmployeesController.cs
...nagement.Api/Controllers/Employees/EmployeesController.cs
+33
-0
HomeController.cs
PSManagement.Api/Controllers/HomeController.cs
+2
-1
RolesController.cs
PSManagement.Api/Controllers/Roles/RolesController.cs
+62
-0
UserRolesController.cs
PSManagement.Api/Controllers/Roles/UserRolesController.cs
+58
-0
CustomerMapperConfiguration.cs
PSManagement.Api/Mappers/CustomerMapperConfiguration.cs
+1
-1
MapperConfigurations.cs
PSManagement.Api/Mappers/MapperConfigurations.cs
+4
-4
Startup.cs
PSManagement.Api/Startup.cs
+2
-2
appsettings.json
PSManagement.Api/appsettings.json
+3
-1
No files found.
PSManagement.Api/Controllers/ApiBase/APIController.cs
0 → 100644
View file @
69af1fba
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
PSManagement.Api.Controllers.ApiBase
{
[
Route
(
"api/[controller]"
)]
[
ApiController
]
public
class
APIController
:
ControllerBase
{
}
}
PSManagement.Api/Controllers/Authentication/AuthenticationController.cs
View file @
69af1fba
using
System.Linq
;
using
FluentResults
;
using
Ardalis.Result
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
PSManagement.Api.Controllers.ApiBase
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Contracts.Authentication
;
using
PSManagement.Contracts.Authentication
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
@@ -9,8 +10,7 @@ using AuthenticationResponse = PSManagement.Contracts.Authentication.Authenticat
...
@@ -9,8 +10,7 @@ using AuthenticationResponse = PSManagement.Contracts.Authentication.Authenticat
namespace
PSManagement.Api.Controllers.Authentication
namespace
PSManagement.Api.Controllers.Authentication
{
{
[
Route
(
"api/[controller]"
)]
[
Route
(
"api/[controller]"
)]
[
ApiController
]
public
class
AuthenticationController
:
APIController
public
class
AuthenticationController
:
ControllerBase
{
{
private
readonly
IAuthenticationService
_authenticationService
;
private
readonly
IAuthenticationService
_authenticationService
;
...
@@ -33,7 +33,7 @@ namespace PSManagement.Api.Controllers.Authentication
...
@@ -33,7 +33,7 @@ namespace PSManagement.Api.Controllers.Authentication
return
Ok
(
response
);
return
Ok
(
response
);
}
}
return
Problem
(
title
:
result
.
Errors
[
0
].
Message
,
detail
:
result
.
Errors
[
0
].
Reasons
[
0
]?.
Message
,
statusCode
:
401
);
return
Problem
(
title
:
result
.
ValidationErrors
.
FirstOrDefault
().
ErrorCode
,
detail
:
result
.
ValidationErrors
.
FirstOrDefault
().
Error
Message
,
statusCode
:
401
);
}
}
[
HttpPost
(
"Register"
)]
[
HttpPost
(
"Register"
)]
public
async
Task
<
IActionResult
>
Register
([
FromBody
]
RegisterRequest
registerRequest
)
public
async
Task
<
IActionResult
>
Register
([
FromBody
]
RegisterRequest
registerRequest
)
...
...
PSManagement.Api/Controllers/Customers/CustomersController.cs
View file @
69af1fba
...
@@ -15,16 +15,16 @@ using PSManagement.Application.Customers.UseCases.Commands.DeleteCustomer;
...
@@ -15,16 +15,16 @@ using PSManagement.Application.Customers.UseCases.Commands.DeleteCustomer;
using
PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
;
using
PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
;
using
PSManagement.Application.Customers.UseCases.Queries.ListAllCustomers
;
using
PSManagement.Application.Customers.UseCases.Queries.ListAllCustomers
;
using
PSManagement.Contracts.Customers.Responses
;
using
PSManagement.Contracts.Customers.Responses
;
using
FluentResults
;
using
PSManagement.Application.Customers.UseCases.Queries.GetCustomer
;
using
PSManagement.Application.Customers.UseCases.Queries.GetCustomer
;
using
PSManagement.Api.Controllers.ApiBase
;
using
Ardalis.Result
;
namespace
PSManagement.Api.Controllers.Customers
namespace
PSManagement.Api.Controllers.Customers
{
{
[
Route
(
"api/[controller]"
)]
[
Route
(
"api/[controller]"
)]
[
ApiController
]
// [Authorize]
// [Authorize]
public
class
CustomersController
:
ControllerBase
public
class
CustomersController
:
APIController
{
{
private
readonly
IMediator
_sender
;
private
readonly
IMediator
_sender
;
private
readonly
IMapper
_mapper
;
private
readonly
IMapper
_mapper
;
...
@@ -49,7 +49,7 @@ namespace PSManagement.Api.Controllers.Customers
...
@@ -49,7 +49,7 @@ namespace PSManagement.Api.Controllers.Customers
{
{
var
query
=
new
GetCustomerQuery
(
id
);
var
query
=
new
GetCustomerQuery
(
id
);
var
result
=
_mapper
.
Map
<
Result
<
CustomerRecord
>>(
await
_sender
.
Send
(
query
)
);
var
result
=
await
_sender
.
Send
(
query
);
return
Ok
(
result
);
return
Ok
(
result
);
}
}
...
@@ -59,7 +59,6 @@ namespace PSManagement.Api.Controllers.Customers
...
@@ -59,7 +59,6 @@ namespace PSManagement.Api.Controllers.Customers
var
command
=
_mapper
.
Map
<
CreateCustomerCommand
>(
request
);
var
command
=
_mapper
.
Map
<
CreateCustomerCommand
>(
request
);
var
result
=
await
_sender
.
Send
(
command
);
var
result
=
await
_sender
.
Send
(
command
);
return
Ok
(
result
);
return
Ok
(
result
);
}
}
...
...
PSManagement.Api/Controllers/Employees/EmployeesController.cs
0 → 100644
View file @
69af1fba
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
PSManagement.Api.Controllers.ApiBase
;
using
PSManagement.Application.Contracts.Providers
;
using
PSManagement.Application.Contracts.SyncData
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
PSManagement.Api.Controllers.Employees
{
[
Route
(
"api/[controller]"
)]
public
class
EmployeesController
:
APIController
{
private
readonly
ISyncEmployeesService
_syncEmployeesService
;
private
readonly
IEmployeesProvider
_employeesProvider
;
public
EmployeesController
(
ISyncEmployeesService
syncEmployeesService
)
{
_syncEmployeesService
=
syncEmployeesService
;
}
[
HttpPost
(
"SyncEmployees"
)]
public
async
Task
<
IActionResult
>
Post
()
{
SyncResponse
response
=
await
_syncEmployeesService
.
SyncEmployees
(
_employeesProvider
);
return
Ok
(
response
);
}
}
}
PSManagement.Api/Controllers/HomeController.cs
View file @
69af1fba
...
@@ -14,9 +14,10 @@ namespace PSManagement.Api.Controllers
...
@@ -14,9 +14,10 @@ namespace PSManagement.Api.Controllers
public
class
HomeController
:
ControllerBase
public
class
HomeController
:
ControllerBase
{
{
[
HttpGet
]
[
HttpGet
]
public
async
Task
<
IActionResult
>
Get
()
public
IActionResult
Get
()
{
{
return
Ok
(
new
{
message
=
"success"
});
return
Ok
(
new
{
message
=
"success"
});
}
}
...
...
PSManagement.Api/Controllers/Roles/RolesController.cs
0 → 100644
View file @
69af1fba
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
PSManagement.Api.Controllers.ApiBase
;
using
PSManagement.Application.Contracts.Authorization
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
PSManagement.Api.Controllers.Roles
{
[
Route
(
"api/[controller]"
)]
public
class
RolesController
:
APIController
{
private
readonly
IRoleService
_roleService
;
public
RolesController
(
IRoleService
roleService
)
{
_roleService
=
roleService
;
}
[
HttpGet
(
"GetRoles"
)]
public
async
Task
<
IActionResult
>
GetRoleAsync
()
{
var
getRoles
=
await
_roleService
.
GetRolesAsync
();
return
Ok
(
getRoles
);
}
[
Authorize
(
Roles
=
"Admin"
)]
[
HttpGet
(
"{id}"
)]
public
async
Task
<
IActionResult
>
GetRoleByIdAsync
(
int
id
)
{
var
getRolesById
=
await
_roleService
.
GetRoleByIdAsync
(
id
);
return
Ok
(
getRolesById
);
}
[
Authorize
(
Roles
=
"Admin"
)]
[
HttpPost
(
"Create"
)]
public
async
Task
<
IActionResult
>
CreateRoleAsync
(
string
roleName
)
{
var
roleCreated
=
await
_roleService
.
CreateRoleAsync
(
roleName
);
return
Ok
(
roleCreated
);
}
[
Authorize
(
Roles
=
"Admin"
)]
[
HttpDelete
(
"Delete/{id}"
)]
public
async
Task
<
IActionResult
>
DeleteRoleAsync
(
int
id
)
{
var
deleteRole
=
await
_roleService
.
DeleteRoleAsync
(
id
);
return
Ok
(
deleteRole
);
}
[
Authorize
(
Roles
=
"Admin"
)]
[
HttpPut
(
"Edit/{id}"
)]
public
async
Task
<
ActionResult
>
UpdateRoleAsync
(
int
id
,
string
roleName
)
{
var
updateRole
=
await
_roleService
.
UpdateRole
(
id
,
roleName
);
return
Ok
(
updateRole
);
}
}
}
PSManagement.Api/Controllers/Roles/UserRolesController.cs
0 → 100644
View file @
69af1fba
using
Microsoft.AspNetCore.Authentication.JwtBearer
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
PSManagement.Api.Controllers.ApiBase
;
using
PSManagement.Application.Contracts.Authorization
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
PSManagement.Api.Controllers.Roles
{
[
Route
(
"api/[controller]"
)]
public
class
UserRolesController
:
APIController
{
private
readonly
IUserRoleService
_userRoleService
;
public
UserRolesController
(
IUserRoleService
userRoleService
)
:
base
()
{
_userRoleService
=
userRoleService
;
}
[
HttpGet
(
"GetUserRolesAsync"
)]
public
async
Task
<
ActionResult
>
GetUserRolesAsync
(
string
email
)
{
var
userRoles
=
await
_userRoleService
.
GetUserRolesAsync
(
email
);
return
Ok
(
userRoles
);
}
[
Authorize
(
Roles
=
"Admin"
)]
[
HttpPost
(
"AssignUserToRoles"
)]
public
async
Task
<
ActionResult
>
AssignUserToRolesAsync
(
string
email
,
string
roleName
)
{
var
roleAssigned
=
await
_userRoleService
.
AssignUserToRole
(
email
,
roleName
);
return
Ok
(
roleAssigned
);
}
[
HttpGet
(
"IsInRole"
)]
public
async
Task
<
ActionResult
>
IsInRoleAsync
(
int
id
,
string
role
)
{
var
IsInRole
=
await
_userRoleService
.
IsInRoleAsync
(
id
,
role
);
return
Ok
(
IsInRole
);
}
[
Authorize
(
Roles
=
"Admin"
)]
[
HttpDelete
(
"DeleteUserRole"
)]
public
async
Task
<
IActionResult
>
RemoveUserFromRole
(
string
email
,
string
roleName
)
{
var
deleteUserFromRole
=
await
_userRoleService
.
RemoveUserFromRole
(
email
,
roleName
);
return
Ok
(
deleteUserFromRole
);
}
}
}
PSManagement.Api/Mappers/CustomerMapperConfiguration.cs
View file @
69af1fba
...
@@ -24,7 +24,7 @@ namespace PSManagement.Api.Mappers
...
@@ -24,7 +24,7 @@ namespace PSManagement.Api.Mappers
CreateMap
<
CustomerDTO
,
CustomerRecord
>();
CreateMap
<
CustomerDTO
,
CustomerRecord
>();
CreateMap
<
ContactInfoDTO
,
ContactInfoRecord
>();
CreateMap
<
ContactInfoDTO
,
ContactInfoRecord
>();
CreateMap
<
CustomerRecord
,
CustomerDTO
>().
ForMember
(
src
=>
src
.
ContactInfo
,
des
=>
des
.
Ignore
()
);
CreateMap
<
CustomerRecord
,
CustomerDTO
>().
ReverseMap
(
);
CreateMap
<
IEnumerable
<
CustomerRecord
>,
ListCustomersResponse
>()
CreateMap
<
IEnumerable
<
CustomerRecord
>,
ListCustomersResponse
>()
.
ConstructUsing
(
src
=>
new
ListCustomersResponse
(
src
));
.
ConstructUsing
(
src
=>
new
ListCustomersResponse
(
src
));
...
...
PSManagement.Api/Mappers/MapperConfigurations.cs
View file @
69af1fba
using
A
utoMapper
;
using
A
rdalis.Result
;
using
FluentResults
;
using
AutoMapper
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
...
@@ -21,11 +21,11 @@ namespace PSManagement.Api.Mappers
...
@@ -21,11 +21,11 @@ namespace PSManagement.Api.Mappers
if
(
source
.
IsSuccess
)
if
(
source
.
IsSuccess
)
{
{
var
mappedValue
=
context
.
Mapper
.
Map
<
TDestination
>(
source
.
Value
);
var
mappedValue
=
context
.
Mapper
.
Map
<
TDestination
>(
source
.
Value
);
return
Result
.
Ok
(
mappedValue
);
return
Result
.
Success
(
mappedValue
);
}
}
else
else
{
{
return
Result
.
Fail
<
TDestination
>(
source
.
Errors
);
return
Result
.
Invalid
(
source
.
Validation
Errors
);
}
}
}
}
}
}
...
...
PSManagement.Api/Startup.cs
View file @
69af1fba
...
@@ -36,8 +36,8 @@ namespace PSManagement.Api
...
@@ -36,8 +36,8 @@ namespace PSManagement.Api
.
AddAPI
()
.
AddAPI
()
.
AddPresentation
()
.
AddPresentation
()
.
AddApplication
()
.
AddApplication
()
.
Add
Infrastructur
e
(
Configuration
)
.
Add
Persistenc
e
(
Configuration
)
.
Add
Persistenc
e
(
Configuration
);
.
Add
Infrastructur
e
(
Configuration
);
}
}
...
...
PSManagement.Api/appsettings.json
View file @
69af1fba
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
},
},
"ConnectionStrings"
:
{
"ConnectionStrings"
:
{
"DefaultConnection"
:
"Data Source=.
\\
sqlexpress;Initial Catalog=PSManagement ;Integrated Security=True"
"DefaultConnection"
:
"Data Source=.
\\
sqlexpress;Initial Catalog=PSManagement ;Integrated Security=True"
},
"EmpoyeesSyncJobSettings"
:
{
"SyncIntervalInMinutes"
:
60
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment