Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
payments
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
Юнусов Ибрагим
payments
Commits
daab1daa
Commit
daab1daa
authored
Jul 27, 2022
by
Юнусов Ибрагим
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Расширил описание методов в сваггере
parent
962d7eab
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
6 deletions
+83
-6
UserController.cs
Payments/Payment.WebApi/Controllers/UserController.cs
+61
-5
UserResponseModel.cs
.../Payment.WebApi/Models/RequestModels/UserResponseModel.cs
+17
-0
Payment.WebApi.csproj
Payments/Payment.WebApi/Payment.WebApi.csproj
+1
-0
Program.cs
Payments/Payment.WebApi/Program.cs
+4
-1
No files found.
Payments/Payment.WebApi/Controllers/UserController.cs
View file @
daab1daa
...
@@ -3,11 +3,13 @@ using Payment.WebApi.Enums;
...
@@ -3,11 +3,13 @@ using Payment.WebApi.Enums;
using
Payment.WebApi.Models.DbModels
;
using
Payment.WebApi.Models.DbModels
;
using
Payment.WebApi.Models.RequestModels
;
using
Payment.WebApi.Models.RequestModels
;
using
Payment.WebApi.Repositories.Interfaces
;
using
Payment.WebApi.Repositories.Interfaces
;
using
Swashbuckle.AspNetCore.Annotations
;
namespace
Payment.WebApi.Controllers
;
namespace
Payment.WebApi.Controllers
;
[ApiController]
[ApiController]
[Route("Users/[action]
")]
[Route("Users/[action]
")]
[Produces("applications/json")]
public
class
UserController
:
Controller
public
class
UserController
:
Controller
{
{
private
readonly
IUserRepository
_userRepository
;
private
readonly
IUserRepository
_userRepository
;
...
@@ -19,15 +21,25 @@ public class UserController : Controller
...
@@ -19,15 +21,25 @@ public class UserController : Controller
[
HttpGet
]
[
HttpGet
]
[
ActionName
(
"GetById"
)]
[
ActionName
(
"GetById"
)]
public
ActionResult
<
User
>
GetUser
(
int
id
)
[
ProducesResponseType
(
200
)]
[
ProducesResponseType
(
204
)]
[
ProducesResponseType
(
500
)]
[
SwaggerOperation
(
Description
=
"Получение данных по пользователю по его айди. Если пользователь не найден, то возвращается 204 статус"
,
OperationId
=
"GetByUserId"
,
Tags
=
new
[]{
"Users"
}
)
]
public
ActionResult
<
UserResponseModel
>
GetUser
(
int
id
)
{
{
try
try
{
{
var
user
=
_userRepository
.
GetFirstOrDefaultById
(
id
);
var
user
=
_userRepository
.
GetFirstOrDefaultById
(
id
);
if
(
user
is
null
)
if
(
user
is
null
)
return
No
tFound
();
return
No
Content
();
return
Ok
(
user
);
return
Ok
(
UserMap
(
user
)
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -37,6 +49,15 @@ public class UserController : Controller
...
@@ -37,6 +49,15 @@ public class UserController : Controller
[
HttpPost
]
[
HttpPost
]
[
ActionName
(
"Create"
)]
[
ActionName
(
"Create"
)]
[
ProducesResponseType
(
200
)]
[
ProducesResponseType
(
500
)]
[
SwaggerOperation
(
Description
=
"Создание пользователя"
,
OperationId
=
"CreateUser"
,
Tags
=
new
[]{
"Users"
}
)
]
public
ActionResult
<
DefaultResponse
>
Create
(
UserRequestModel
requestModel
)
public
ActionResult
<
DefaultResponse
>
Create
(
UserRequestModel
requestModel
)
{
{
try
try
...
@@ -64,6 +85,15 @@ public class UserController : Controller
...
@@ -64,6 +85,15 @@ public class UserController : Controller
[
HttpPut
]
[
HttpPut
]
[
ActionName
(
"Edit"
)]
[
ActionName
(
"Edit"
)]
[
ProducesResponseType
(
200
)]
[
ProducesResponseType
(
500
)]
[
SwaggerOperation
(
Description
=
"Редактирование данных пользователя, пока что без почты"
,
OperationId
=
"UpdateUser"
,
Tags
=
new
[]{
"Users"
}
)
]
public
ActionResult
<
DefaultResponse
>
Edit
(
UserRequestModel
requestModel
)
public
ActionResult
<
DefaultResponse
>
Edit
(
UserRequestModel
requestModel
)
{
{
try
try
...
@@ -91,6 +121,15 @@ public class UserController : Controller
...
@@ -91,6 +121,15 @@ public class UserController : Controller
[
HttpDelete
]
[
HttpDelete
]
[
ActionName
(
"Delete"
)]
[
ActionName
(
"Delete"
)]
[
ProducesResponseType
(
200
)]
[
ProducesResponseType
(
500
)]
[
SwaggerOperation
(
Description
=
"Деактивация пользователя. К деактивированным пользователям имеет доступ только администратор системы"
,
OperationId
=
"DeleteUser"
,
Tags
=
new
[]{
"Users"
}
)
]
public
ActionResult
<
DefaultResponse
>
Delete
(
int
id
)
public
ActionResult
<
DefaultResponse
>
Delete
(
int
id
)
{
{
var
user
=
_userRepository
.
GetFirstOrDefaultById
(
id
);
var
user
=
_userRepository
.
GetFirstOrDefaultById
(
id
);
...
@@ -117,4 +156,21 @@ public class UserController : Controller
...
@@ -117,4 +156,21 @@ public class UserController : Controller
user
.
Age
=
user
.
Age
;
user
.
Age
=
user
.
Age
;
return
user
;
return
user
;
}
}
private
static
UserResponseModel
UserMap
(
User
user
)
{
return
new
UserResponseModel
{
FirstName
=
user
.
FirstName
,
LastName
=
user
.
LastName
,
MiddleName
=
user
.
MiddleName
,
Age
=
user
.
Age
,
Email
=
user
.
Email
,
Balances
=
user
.
Balances
.
Select
(
s
=>
new
UserBalancesResponseModel
{
Currency
=
s
.
Currency
,
Amount
=
s
.
Amount
}).
ToList
()
};
}
}
}
\ No newline at end of file
Payments/Payment.WebApi/Models/RequestModels/UserResponseModel.cs
0 → 100644
View file @
daab1daa
namespace
Payment.WebApi.Models.RequestModels
;
public
class
UserResponseModel
{
public
string
FirstName
{
get
;
set
;
}
public
string
?
LastName
{
get
;
set
;
}
public
string
?
MiddleName
{
get
;
set
;
}
public
string
Email
{
get
;
set
;
}
public
int
Age
{
get
;
set
;
}
public
List
<
UserBalancesResponseModel
>
Balances
{
get
;
set
;
}
}
public
class
UserBalancesResponseModel
{
public
decimal
Amount
{
get
;
set
;
}
public
string
Currency
{
get
;
set
;
}
}
\ No newline at end of file
Payments/Payment.WebApi/Payment.WebApi.csproj
View file @
daab1daa
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
</PackageReference>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.4.0" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
Payments/Payment.WebApi/Program.cs
View file @
daab1daa
...
@@ -9,7 +9,10 @@ var services = builder.Services;
...
@@ -9,7 +9,10 @@ var services = builder.Services;
services
.
AddControllers
();
services
.
AddControllers
();
services
.
AddEndpointsApiExplorer
();
services
.
AddEndpointsApiExplorer
();
services
.
AddSwaggerGen
();
services
.
AddSwaggerGen
(
s
=>
{
s
.
EnableAnnotations
();
});
services
.
AddAppServices
(
builder
.
Configuration
);
services
.
AddAppServices
(
builder
.
Configuration
);
var
app
=
builder
.
Build
();
var
app
=
builder
.
Build
();
...
...
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