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
Show 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 @@
using
Microsoft.AspNetCore.Mvc
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Contracts.Authentication
;
using
PSManagement.SharedKernel.Utilities
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
AuthenticationResponse
=
PSManagement
.
Contracts
.
Authentication
.
AuthenticationResponse
;
namespace
PSManagement.Api.Controllers.Authentication
{
...
...
@@ -22,34 +24,43 @@ namespace PSManagement.Api.Controllers.Authentication
[
HttpPost
(
"Login"
)]
public
async
Task
<
IActionResult
>
Login
([
FromBody
]
LoginRequest
loginRequest
)
{
AuthenticationResult
result
=
await
_authenticationService
.
Login
(
loginRequest
.
Email
,
loginRequest
.
PassWorrd
);
AuthenticationResponse
response
=
new
AuthenticationResponse
(
result
.
Id
,
result
.
FirstName
,
result
.
LastName
,
result
.
Email
,
result
.
Token
);
Result
<
AuthenticationResult
>
result
=
await
_authenticationService
.
Login
(
loginRequest
.
Email
,
loginRequest
.
PassWorrd
);
if
(
result
.
IsSuccess
)
{
AuthenticationResponse
response
=
new
(
result
.
Value
.
Id
,
result
.
Value
.
FirstName
,
result
.
Value
.
LastName
,
result
.
Value
.
Email
,
result
.
Value
.
Token
);
return
Ok
(
response
);
}
return
Problem
(
title
:
"An Errorr Occured"
,
detail
:
result
.
Error
.
Name
,
statusCode
:
400
);
}
[
HttpPost
(
"Register"
)]
public
async
Task
<
IActionResult
>
Register
([
FromBody
]
RegisterRequest
registerRequest
)
{
AuthenticationResult
result
=
await
_authenticationService
.
Register
(
Result
<
AuthenticationResult
>
result
=
await
_authenticationService
.
Register
(
registerRequest
.
Email
,
registerRequest
.
FirstName
,
registerRequest
.
LastName
,
registerRequest
.
Password
);
AuthenticationResponse
response
=
new
AuthenticationResponse
(
result
.
Id
,
result
.
FirstName
,
result
.
LastName
,
result
.
Email
,
result
.
Token
);
if
(
result
.
IsSuccess
)
{
AuthenticationResponse
response
=
new
(
result
.
Value
.
Id
,
result
.
Value
.
FirstName
,
result
.
Value
.
LastName
,
result
.
Value
.
Email
,
result
.
Value
.
Token
);
return
Ok
(
response
);
}
return
Problem
(
title
:
"An Errorr Occured"
,
detail
:
result
.
Error
.
Name
,
statusCode
:
400
);
}
}
}
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
System
;
using
System.Collections.Generic
;
...
...
@@ -9,6 +10,7 @@ namespace PSManagement.Api.Controllers
{
[
Route
(
"api/[controller]"
)]
[
ApiController
]
[
Authorize
]
public
class
HomeController
:
ControllerBase
{
[
HttpGet
]
...
...
PSManagement.Api/Startup.cs
View file @
37c7f934
...
...
@@ -34,9 +34,31 @@ namespace PSManagement.Api
services
.
AddInfrastructure
(
Configuration
);
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
app
.
UseRouting
();
app
.
UseAuthentication
();
app
.
UseAuthorization
();
app
.
UseEndpoints
(
endpoints
=>
{
endpoints
.
MapControllers
();
...
...
PSManagement.Api/appsettings.json
View file @
37c7f934
...
...
@@ -10,7 +10,7 @@
"JwtSettings"
:
{
"secret"
:
"super-secret-key"
,
"ExpireMinutes"
:
60
,
"Issuer"
:
"HIAST-PS-Management"
,
"Audience"
:
""
"Issuer"
:
"HIAST-PS-Management
-Server
"
,
"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