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
dbc2f6e0
Commit
dbc2f6e0
authored
Jul 27, 2022
by
Юнусов Ибрагим
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил валидацию
parent
2c7f0664
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
16 deletions
+46
-16
UserController.cs
Payments/Payment.WebApi/Controllers/UserController.cs
+15
-13
UserCreateRequestModel.cs
...bApi/Models/RequestModels/Users/UserCreateRequestModel.cs
+10
-0
UserEditRequestModel.cs
...WebApi/Models/RequestModels/Users/UserEditRequestModel.cs
+2
-2
UserResponseModel.cs
...nt.WebApi/Models/RequestModels/Users/UserResponseModel.cs
+1
-1
Payment.WebApi.csproj
Payments/Payment.WebApi/Payment.WebApi.csproj
+1
-0
Program.cs
Payments/Payment.WebApi/Program.cs
+2
-0
UserRequestModelValidator.cs
...ts/Payment.WebApi/Validators/UserRequestModelValidator.cs
+15
-0
No files found.
Payments/Payment.WebApi/Controllers/UserController.cs
View file @
dbc2f6e0
...
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
...
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using
Payment.WebApi.Enums
;
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.Models.RequestModels.Users
;
using
Payment.WebApi.Repositories.Interfaces
;
using
Payment.WebApi.Repositories.Interfaces
;
using
Swashbuckle.AspNetCore.Annotations
;
using
Swashbuckle.AspNetCore.Annotations
;
...
@@ -50,6 +51,7 @@ public class UserController : Controller
...
@@ -50,6 +51,7 @@ public class UserController : Controller
[
HttpPost
]
[
HttpPost
]
[
ActionName
(
"Create"
)]
[
ActionName
(
"Create"
)]
[
ProducesResponseType
(
200
)]
[
ProducesResponseType
(
200
)]
[
ProducesResponseType
(
400
)]
[
ProducesResponseType
(
500
)]
[
ProducesResponseType
(
500
)]
[
SwaggerOperation
[
SwaggerOperation
(
(
...
@@ -58,17 +60,17 @@ public class UserController : Controller
...
@@ -58,17 +60,17 @@ public class UserController : Controller
Tags
=
new
[]{
"Users"
}
Tags
=
new
[]{
"Users"
}
)
)
]
]
public
ActionResult
<
DefaultResponse
>
Create
(
User
RequestModel
r
equestModel
)
public
ActionResult
<
DefaultResponse
>
Create
(
User
CreateRequestModel
createR
equestModel
)
{
{
try
try
{
{
_userRepository
.
Create
(
new
User
_userRepository
.
Create
(
new
User
{
{
FirstName
=
r
equestModel
.
FirstName
,
FirstName
=
createR
equestModel
.
FirstName
,
LastName
=
r
equestModel
.
LastName
,
LastName
=
createR
equestModel
.
LastName
,
MiddleName
=
r
equestModel
.
MiddleName
,
MiddleName
=
createR
equestModel
.
MiddleName
,
Age
=
r
equestModel
.
Age
,
Age
=
createR
equestModel
.
Age
,
Email
=
r
equestModel
.
Email
,
Email
=
createR
equestModel
.
Email
,
IsActive
=
true
IsActive
=
true
});
});
_userRepository
.
Save
();
_userRepository
.
Save
();
...
@@ -94,18 +96,18 @@ public class UserController : Controller
...
@@ -94,18 +96,18 @@ public class UserController : Controller
Tags
=
new
[]{
"Users"
}
Tags
=
new
[]{
"Users"
}
)
)
]
]
public
ActionResult
<
DefaultResponse
>
Edit
(
User
RequestModel
r
equestModel
)
public
ActionResult
<
DefaultResponse
>
Edit
(
User
EditRequestModel
createR
equestModel
)
{
{
try
try
{
{
var
user
=
_userRepository
.
GetFirstOrDefaultByEmail
(
r
equestModel
.
Email
);
var
user
=
_userRepository
.
GetFirstOrDefaultByEmail
(
createR
equestModel
.
Email
);
if
(
user
is
null
)
if
(
user
is
null
)
return
Ok
(
new
DefaultResponse
return
Ok
(
new
DefaultResponse
{
{
ResponseStatusType
=
ResponseStatusType
.
NotFound
ResponseStatusType
=
ResponseStatusType
.
NotFound
});
});
_userRepository
.
Update
(
UpdateUser
(
user
,
r
equestModel
));
_userRepository
.
Update
(
UpdateUser
(
user
,
createR
equestModel
));
_userRepository
.
Save
();
_userRepository
.
Save
();
return
Ok
(
new
DefaultResponse
return
Ok
(
new
DefaultResponse
...
@@ -148,11 +150,11 @@ public class UserController : Controller
...
@@ -148,11 +150,11 @@ public class UserController : Controller
});
});
}
}
private
static
User
UpdateUser
(
User
user
,
User
RequestModel
r
equestModel
)
private
static
User
UpdateUser
(
User
user
,
User
EditRequestModel
createR
equestModel
)
{
{
user
.
FirstName
=
r
equestModel
.
FirstName
;
user
.
FirstName
=
createR
equestModel
.
FirstName
;
user
.
LastName
=
r
equestModel
.
LastName
;
user
.
LastName
=
createR
equestModel
.
LastName
;
user
.
MiddleName
=
r
equestModel
.
MiddleName
;
user
.
MiddleName
=
createR
equestModel
.
MiddleName
;
user
.
Age
=
user
.
Age
;
user
.
Age
=
user
.
Age
;
return
user
;
return
user
;
}
}
...
...
Payments/Payment.WebApi/Models/RequestModels/Users/UserCreateRequestModel.cs
0 → 100644
View file @
dbc2f6e0
namespace
Payment.WebApi.Models.RequestModels.Users
;
public
class
UserCreateRequestModel
{
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
;
}
}
\ No newline at end of file
Payments/Payment.WebApi/Models/RequestModels/UserRequestModel.cs
→
Payments/Payment.WebApi/Models/RequestModels/User
s/UserEdit
RequestModel.cs
View file @
dbc2f6e0
namespace
Payment.WebApi.Models.RequestModels
;
namespace
Payment.WebApi.Models.RequestModels
.Users
;
public
class
UserRequestModel
public
class
User
Edit
RequestModel
{
{
public
string
FirstName
{
get
;
set
;
}
public
string
FirstName
{
get
;
set
;
}
public
string
?
LastName
{
get
;
set
;
}
public
string
?
LastName
{
get
;
set
;
}
...
...
Payments/Payment.WebApi/Models/RequestModels/UserResponseModel.cs
→
Payments/Payment.WebApi/Models/RequestModels/User
s/User
ResponseModel.cs
View file @
dbc2f6e0
namespace
Payment.WebApi.Models.RequestModels
;
namespace
Payment.WebApi.Models.RequestModels
.Users
;
public
class
UserResponseModel
public
class
UserResponseModel
{
{
...
...
Payments/Payment.WebApi/Payment.WebApi.csproj
View file @
dbc2f6e0
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PrivateAssets>all</PrivateAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
...
...
Payments/Payment.WebApi/Program.cs
View file @
dbc2f6e0
using
FluentValidation.AspNetCore
;
using
Payment.WebApi.Extensions
;
using
Payment.WebApi.Extensions
;
var
builder
=
WebApplication
.
CreateBuilder
(
args
);
var
builder
=
WebApplication
.
CreateBuilder
(
args
);
...
@@ -14,6 +15,7 @@ services.AddSwaggerGen(s =>
...
@@ -14,6 +15,7 @@ services.AddSwaggerGen(s =>
s
.
EnableAnnotations
();
s
.
EnableAnnotations
();
});
});
services
.
AddAppServices
(
builder
.
Configuration
);
services
.
AddAppServices
(
builder
.
Configuration
);
services
.
AddFluentValidation
(
opt
=>
opt
.
RegisterValidatorsFromAssemblyContaining
<
Program
>());
var
app
=
builder
.
Build
();
var
app
=
builder
.
Build
();
...
...
Payments/Payment.WebApi/Validators/UserRequestModelValidator.cs
0 → 100644
View file @
dbc2f6e0
using
FluentValidation
;
using
Payment.WebApi.Models.RequestModels
;
using
Payment.WebApi.Models.RequestModels.Users
;
namespace
Payment.WebApi.Validators
;
public
class
UserRequestModelValidator
:
AbstractValidator
<
UserCreateRequestModel
>
{
public
UserRequestModelValidator
()
{
RuleFor
(
s
=>
s
.
FirstName
).
NotEmpty
().
WithMessage
(
"Имя обязательно для заполнения"
);
RuleFor
(
s
=>
s
.
Email
).
NotEmpty
().
WithMessage
(
"Email обязателен для заполнения"
);
RuleFor
(
s
=>
s
.
Age
).
GreaterThan
(
0
).
WithMessage
(
"Возраст не должен быть меньше либо равен нулю"
);
}
}
\ No newline at end of file
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