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
37c7f934
Commit
37c7f934
authored
Jul 16, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use the result pattern for response.
parent
d9535ed1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
22 deletions
+57
-22
AuthenticationController.cs
...pi/Controllers/Authentication/AuthenticationController.cs
+27
-16
HomeController.cs
PSManagement.Api/Controllers/HomeController.cs
+3
-1
Startup.cs
PSManagement.Api/Startup.cs
+25
-3
appsettings.json
PSManagement.Api/appsettings.json
+2
-2
No files found.
PSManagement.Api/Controllers/Authentication/AuthenticationController.cs
View file @
37c7f934
...
@@ -2,10 +2,12 @@
...
@@ -2,10 +2,12 @@
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Contracts.Authentication
;
using
PSManagement.Contracts.Authentication
;
using
PSManagement.SharedKernel.Utilities
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
AuthenticationResponse
=
PSManagement
.
Contracts
.
Authentication
.
AuthenticationResponse
;
namespace
PSManagement.Api.Controllers.Authentication
namespace
PSManagement.Api.Controllers.Authentication
{
{
...
@@ -22,33 +24,42 @@ namespace PSManagement.Api.Controllers.Authentication
...
@@ -22,33 +24,42 @@ namespace PSManagement.Api.Controllers.Authentication
[
HttpPost
(
"Login"
)]
[
HttpPost
(
"Login"
)]
public
async
Task
<
IActionResult
>
Login
([
FromBody
]
LoginRequest
loginRequest
)
public
async
Task
<
IActionResult
>
Login
([
FromBody
]
LoginRequest
loginRequest
)
{
{
AuthenticationResult
result
=
await
_authenticationService
.
Login
(
loginRequest
.
Email
,
loginRequest
.
PassWorrd
);
Result
<
AuthenticationResult
>
result
=
await
_authenticationService
.
Login
(
loginRequest
.
Email
,
loginRequest
.
PassWorrd
);
AuthenticationResponse
response
=
new
AuthenticationResponse
(
if
(
result
.
IsSuccess
)
{
result
.
Id
,
AuthenticationResponse
response
=
new
(
result
.
FirstName
,
result
.
Value
.
Id
,
result
.
LastName
,
result
.
Value
.
FirstName
,
result
.
Email
,
result
.
Value
.
LastName
,
result
.
Token
);
result
.
Value
.
Email
,
return
Ok
(
response
);
result
.
Value
.
Token
);
return
Ok
(
response
);
}
return
Problem
(
title
:
"An Errorr Occured"
,
detail
:
result
.
Error
.
Name
,
statusCode
:
400
);
}
}
[
HttpPost
(
"Register"
)]
[
HttpPost
(
"Register"
)]
public
async
Task
<
IActionResult
>
Register
([
FromBody
]
RegisterRequest
registerRequest
)
public
async
Task
<
IActionResult
>
Register
([
FromBody
]
RegisterRequest
registerRequest
)
{
{
AuthenticationResult
result
=
await
_authenticationService
.
Register
(
Result
<
AuthenticationResult
>
result
=
await
_authenticationService
.
Register
(
registerRequest
.
Email
,
registerRequest
.
Email
,
registerRequest
.
FirstName
,
registerRequest
.
FirstName
,
registerRequest
.
LastName
,
registerRequest
.
LastName
,
registerRequest
.
Password
);
registerRequest
.
Password
);
if
(
result
.
IsSuccess
)
{
AuthenticationResponse
response
=
new
(
result
.
Value
.
Id
,
result
.
Value
.
FirstName
,
result
.
Value
.
LastName
,
result
.
Value
.
Email
,
result
.
Value
.
Token
);
return
Ok
(
response
);
}
AuthenticationResponse
response
=
new
AuthenticationResponse
(
return
Problem
(
title
:
"An Errorr Occured"
,
detail
:
result
.
Error
.
Name
,
statusCode
:
400
);
result
.
Id
,
result
.
FirstName
,
result
.
LastName
,
result
.
Email
,
result
.
Token
);
return
Ok
(
response
);
}
}
}
}
...
...
PSManagement.Api/Controllers/HomeController.cs
View file @
37c7f934
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
@@ -9,6 +10,7 @@ namespace PSManagement.Api.Controllers
...
@@ -9,6 +10,7 @@ namespace PSManagement.Api.Controllers
{
{
[
Route
(
"api/[controller]"
)]
[
Route
(
"api/[controller]"
)]
[
ApiController
]
[
ApiController
]
[
Authorize
]
public
class
HomeController
:
ControllerBase
public
class
HomeController
:
ControllerBase
{
{
[
HttpGet
]
[
HttpGet
]
...
...
PSManagement.Api/Startup.cs
View file @
37c7f934
...
@@ -34,9 +34,31 @@ namespace PSManagement.Api
...
@@ -34,9 +34,31 @@ namespace PSManagement.Api
services
.
AddInfrastructure
(
Configuration
);
services
.
AddInfrastructure
(
Configuration
);
services
.
AddControllers
();
services
.
AddControllers
();
services
.
AddSwaggerGen
(
c
=>
services
.
AddSwaggerGen
(
options
=>
{
{
c
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Title
=
"PSManagement.Api"
,
Version
=
"v1"
});
options
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Title
=
"PSManagement.Api"
,
Version
=
"v1"
});
options
.
AddSecurityDefinition
(
"Bearer"
,
new
OpenApiSecurityScheme
()
{
Name
=
"Authorization"
,
In
=
ParameterLocation
.
Header
,
Type
=
SecuritySchemeType
.
Http
,
Scheme
=
"Bearer"
});
options
.
AddSecurityRequirement
(
new
OpenApiSecurityRequirement
{
{
new
OpenApiSecurityScheme
{
Reference
=
new
OpenApiReference
{
Type
=
ReferenceType
.
SecurityScheme
,
Id
=
"Bearer"
}
},
Array
.
Empty
<
string
>()
}
});
});
});
}
}
...
@@ -54,8 +76,8 @@ namespace PSManagement.Api
...
@@ -54,8 +76,8 @@ namespace PSManagement.Api
app
.
UseRouting
();
app
.
UseRouting
();
app
.
UseAuthentication
();
app
.
UseAuthorization
();
app
.
UseAuthorization
();
app
.
UseEndpoints
(
endpoints
=>
app
.
UseEndpoints
(
endpoints
=>
{
{
endpoints
.
MapControllers
();
endpoints
.
MapControllers
();
...
...
PSManagement.Api/appsettings.json
View file @
37c7f934
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
"JwtSettings"
:
{
"JwtSettings"
:
{
"secret"
:
"super-secret-key"
,
"secret"
:
"super-secret-key"
,
"ExpireMinutes"
:
60
,
"ExpireMinutes"
:
60
,
"Issuer"
:
"HIAST-PS-Management"
,
"Issuer"
:
"HIAST-PS-Management
-Server
"
,
"Audience"
:
""
"Audience"
:
"
All
"
}
}
}
}
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