Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
spring-boot-data-mongodb-curd
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
Syed Javed Ali
spring-boot-data-mongodb-curd
Commits
0b91886f
Commit
0b91886f
authored
Mar 10, 2021
by
Syed Javed Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added javax validation to end points
parent
879181ba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
1 deletion
+16
-1
build.gradle
build.gradle
+3
-0
EmployeeController.java
.../nisum/example/mongodb/controller/EmployeeController.java
+5
-1
Employee.java
src/main/java/com/nisum/example/mongodb/model/Employee.java
+6
-0
application.properties
src/main/resources/application.properties
+2
-0
No files found.
build.gradle
View file @
0b91886f
...
...
@@ -29,6 +29,9 @@ dependencies {
implementation
'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor
'org.mapstruct:mapstruct-processor:1.4.2.Final'
implementation
group:
'javax.validation'
,
name:
'validation-api'
,
version:
'2.0.1.Final'
}
test
{
...
...
src/main/java/com/nisum/example/mongodb/controller/EmployeeController.java
View file @
0b91886f
...
...
@@ -7,15 +7,19 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
javax.validation.Valid
;
/**
* Controller class having http POST, GET, UPDATE and DELETE methods
*/
@Slf4j
@RestController
@Validated
public
class
EmployeeController
{
@Autowired
...
...
@@ -31,7 +35,7 @@ public class EmployeeController {
*/
@PostMapping
(
path
=
"/create"
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
public
Mono
<
Employee
>
create
(
@RequestBody
Employee
employee
)
{
public
Mono
<
Employee
>
create
(
@
Valid
@
RequestBody
Employee
employee
)
{
log
.
info
(
"Calling service insert method..."
);
return
employeeService
.
insert
(
employeeMapper
.
toDto
(
employee
))
...
...
src/main/java/com/nisum/example/mongodb/model/Employee.java
View file @
0b91886f
...
...
@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.validation.constraints.DecimalMax
;
import
javax.validation.constraints.NotNull
;
/**
* Model class for Employee
...
...
@@ -13,9 +16,12 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
public
class
Employee
{
private
Integer
id
;
@NotNull
(
message
=
"Name cannot be null"
)
private
String
name
;
@DecimalMax
(
value
=
"1000"
,
message
=
"Value cannot be more than 1000"
)
private
Long
salary
;
...
...
src/main/resources/application.properties
View file @
0b91886f
server.port
=
8081
spring.data.mongodb.database
=
testdb
spring.data.mongodb.port
=
27017
\ 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