Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ecom-customer
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Ashok Kumar K
ecom-customer
Commits
a1954127
Commit
a1954127
authored
Jun 01, 2020
by
Ashok Kumar K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added cloud config client and externalized config in git
parent
67bff2ac
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
48 deletions
+50
-48
build.gradle
build.gradle
+7
-6
CustomerController.java
...com/nisum/ecomcustomer/controller/CustomerController.java
+7
-3
NumericId.java
...ain/java/com/nisum/ecomcustomer/validators/NumericId.java
+18
-0
NumericIdValidator.java
...com/nisum/ecomcustomer/validators/NumericIdValidator.java
+11
-0
application-development.yml
src/main/resources/application-development.yml
+0
-10
application-test.yml
src/main/resources/application-test.yml
+0
-13
application.yml
src/main/resources/application.yml
+0
-15
bootstrap.yml
src/main/resources/bootstrap.yml
+7
-1
No files found.
build.gradle
View file @
a1954127
...
...
@@ -19,29 +19,30 @@ repositories {
}
ext
{
set
(
'spring
BootAdminVersion'
,
"2.2.3
"
)
set
(
'spring
CloudVersion'
,
"Hoxton.SR4
"
)
}
dependencies
{
implementation
'org.springframework.boot:spring-boot-starter-actuator'
implementation
'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'de.codecentric:spring-boot-admin-starter-client'
compile
'org.springframework.boot:spring-boot-starter-validation'
implementation
'org.springframework.cloud:spring-cloud-starter-config'
implementation
'org.springframework.boot:spring-boot-starter-actuator'
implementation
'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compileOnly
'org.projectlombok:lombok'
annotationProcessor
'org.projectlombok:lombok'
compile
"io.springfox:springfox-swagger2:2.9.2"
compile
"io.springfox:springfox-swagger-ui:2.9.2"
developmentOnly
'org.springframework.boot:spring-boot-devtools'
//
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation
(
'org.springframework.boot:spring-boot-starter-test'
)
{
exclude
group:
'org.junit.vintage'
,
module:
'junit-vintage-engine'
}
testImplementation
'io.projectreactor:reactor-test'
}
dependencyManagement
{
imports
{
mavenBom
"
de.codecentric:spring-boot-admin-dependencies:${springBootAdmin
Version}"
mavenBom
"
org.springframework.cloud:spring-cloud-dependencies:${springCloud
Version}"
}
}
...
...
src/main/java/com/nisum/ecomcustomer/controller/CustomerController.java
View file @
a1954127
...
...
@@ -4,6 +4,7 @@ import com.nisum.ecomcustomer.model.Customer;
import
com.nisum.ecomcustomer.model.CustomerType
;
import
com.nisum.ecomcustomer.service.CustomerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -13,11 +14,12 @@ import org.springframework.web.bind.annotation.*;
import
javax.validation.Valid
;
import
javax.validation.constraints.Email
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Pattern
;
import
java.time.LocalDate
;
import
java.util.List
;
@RefreshScope
@RestController
@RequestMapping
(
"/customer"
)
@Validated
public
class
CustomerController
{
...
...
@@ -45,7 +47,8 @@ public class CustomerController {
}
@GetMapping
(
"/id/{id}"
)
public
ResponseEntity
<
Customer
>
getCustomerById
(
@PathVariable
Long
id
)
{
public
ResponseEntity
<
Customer
>
getCustomerById
(
@PathVariable
(
"id"
)
@Pattern
(
regexp
=
"^[1-9][\\d]*$"
,
message
=
"must be a numeric id"
)
String
idStr
)
{
long
id
=
Long
.
parseLong
(
idStr
);
return
ResponseEntity
.
ok
(
customerService
.
getCustomerById
(
id
));
}
...
...
@@ -82,7 +85,8 @@ public class CustomerController {
}
@DeleteMapping
(
"/id/{id}"
)
public
ResponseEntity
<
Void
>
deleteById
(
@PathVariable
Long
id
)
{
public
ResponseEntity
<
Void
>
deleteById
(
@PathVariable
(
"id"
)
@Pattern
(
regexp
=
"^[1-9][\\d]*$"
,
message
=
"must be a numeric id"
)
String
idStr
)
{
long
id
=
Long
.
parseLong
(
idStr
);
customerService
.
deleteById
(
id
);
return
ResponseEntity
.
noContent
().
build
();
}
...
...
src/main/java/com/nisum/ecomcustomer/validators/NumericId.java
0 → 100644
View file @
a1954127
package
com
.
nisum
.
ecomcustomer
.
validators
;
import
javax.validation.Constraint
;
import
javax.validation.Payload
;
import
java.lang.annotation.*
;
@Target
({
ElementType
.
FIELD
,
ElementType
.
PARAMETER
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Constraint
(
validatedBy
=
{
NumericIdValidator
.
class
})
@Documented
public
@interface
NumericId
{
String
message
()
default
"must be a numeric id matching pattern [1-9][\\d]*"
;
Class
<?>[]
groups
()
default
{};
Class
<?
extends
Payload
>[]
payload
()
default
{};
}
src/main/java/com/nisum/ecomcustomer/validators/NumericIdValidator.java
0 → 100644
View file @
a1954127
package
com
.
nisum
.
ecomcustomer
.
validators
;
import
javax.validation.ConstraintValidator
;
import
javax.validation.ConstraintValidatorContext
;
public
class
NumericIdValidator
implements
ConstraintValidator
<
NumericId
,
String
>
{
@Override
public
boolean
isValid
(
String
value
,
ConstraintValidatorContext
context
)
{
return
value
.
matches
(
"[1-9][\\d]*"
);
}
}
src/main/resources/application-development.yml
View file @
a1954127
spring
:
data
:
mongodb
:
host
:
localhost
port
:
27017
database
:
ecom
logging
:
level
:
web
:
debug
\ No newline at end of file
src/main/resources/application-test.yml
View file @
a1954127
server
:
port
:
8181
spring
:
data
:
mongodb
:
host
:
localhost
port
:
27017
database
:
ecom-test
logging
:
level
:
web
:
debug
\ No newline at end of file
src/main/resources/application.yml
View file @
a1954127
server
:
port
:
8008
spring
:
profiles
:
active
:
development
data
:
mongodb
:
host
:
localhost
port
:
27017
database
:
ecom
management
:
endpoints
:
web
:
exposure
:
include
:
'
*'
src/main/resources/bootstrap.yml
View file @
a1954127
spring
:
application
:
name
:
customer
\ No newline at end of file
name
:
ecom-customer
profiles
:
active
:
development
cloud
:
config
:
uri
:
http://localhost:8888
#http://localhost:8888 is default we can change it if needed
\ 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