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
f607ef4d
Commit
f607ef4d
authored
May 22, 2020
by
Ashok Kumar K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mongoConfig and basic setup of repo and model classes
parent
8840cd1b
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
337 additions
and
5 deletions
+337
-5
build.gradle
build.gradle
+2
-2
gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+3
-2
EcomCustomerApplication.java
.../java/com/nisum/ecomcustomer/EcomCustomerApplication.java
+2
-0
CustomMongoConverters.java
...um/ecomcustomer/config/mongodb/CustomMongoConverters.java
+51
-0
MongoConfig.java
...va/com/nisum/ecomcustomer/config/mongodb/MongoConfig.java
+57
-0
CustomerController.java
...com/nisum/ecomcustomer/controller/CustomerController.java
+29
-0
Address.java
src/main/java/com/nisum/ecomcustomer/model/Address.java
+23
-0
AddressType.java
src/main/java/com/nisum/ecomcustomer/model/AddressType.java
+33
-0
Customer.java
src/main/java/com/nisum/ecomcustomer/model/Customer.java
+28
-0
CustomerType.java
src/main/java/com/nisum/ecomcustomer/model/CustomerType.java
+33
-0
CustomerRepository.java
...com/nisum/ecomcustomer/repository/CustomerRepository.java
+7
-0
CustomerService.java
.../java/com/nisum/ecomcustomer/service/CustomerService.java
+12
-0
CustomerServiceImpl.java
.../nisum/ecomcustomer/service/impl/CustomerServiceImpl.java
+26
-0
application-development.yml
src/main/resources/application-development.yml
+10
-0
application.properties
src/main/resources/application.properties
+0
-1
application.yml
src/main/resources/application.yml
+18
-0
bootstrap.yml
src/main/resources/bootstrap.yml
+3
-0
No files found.
build.gradle
View file @
f607ef4d
...
...
@@ -24,12 +24,12 @@ ext {
dependencies
{
implementation
'org.springframework.boot:spring-boot-starter-actuator'
implementation
'org.springframework.boot:spring-boot-starter-data-mongodb
-reactive
'
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'
compileOnly
'org.projectlombok:lombok'
developmentOnly
'org.springframework.boot:spring-boot-devtools'
annotationProcessor
'org.projectlombok:lombok'
developmentOnly
'org.springframework.boot:spring-boot-devtools'
testImplementation
(
'org.springframework.boot:spring-boot-starter-test'
)
{
exclude
group:
'org.junit.vintage'
,
module:
'junit-vintage-engine'
}
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
f607ef4d
#Thu May 21 11:20:32 IST 2020
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-6.3-all.zip
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
src/main/java/com/nisum/ecomcustomer/EcomCustomerApplication.java
View file @
f607ef4d
...
...
@@ -2,7 +2,9 @@ package com.nisum.ecomcustomer;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.data.mongodb.repository.config.EnableMongoRepositories
;
@EnableMongoRepositories
@SpringBootApplication
public
class
EcomCustomerApplication
{
...
...
src/main/java/com/nisum/ecomcustomer/config/mongodb/CustomMongoConverters.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
config
.
mongodb
;
import
com.nisum.ecomcustomer.model.AddressType
;
import
com.nisum.ecomcustomer.model.CustomerType
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.data.convert.ReadingConverter
;
import
org.springframework.data.convert.WritingConverter
;
public
class
CustomMongoConverters
{
@WritingConverter
static
class
CustomerTypeToIntegerConverter
implements
Converter
<
CustomerType
,
Integer
>
{
@Override
public
Integer
convert
(
CustomerType
source
)
{
return
source
.
getValue
();
}
}
@ReadingConverter
static
class
IntegerToCustomerTypeConverter
implements
Converter
<
Integer
,
CustomerType
>
{
@Override
public
CustomerType
convert
(
Integer
source
)
{
return
CustomerType
.
of
(
source
);
}
}
@WritingConverter
static
class
AddressTypeToStringConverter
implements
Converter
<
AddressType
,
String
>
{
@Override
public
String
convert
(
AddressType
source
)
{
return
source
.
getValue
();
}
}
@ReadingConverter
static
class
StringToAddressTypeConverter
implements
Converter
<
String
,
AddressType
>
{
@Override
public
AddressType
convert
(
String
source
)
{
return
AddressType
.
of
(
source
);
}
}
}
src/main/java/com/nisum/ecomcustomer/config/mongodb/MongoConfig.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
config
.
mongodb
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.mongodb.config.AbstractMongoClientConfiguration
;
import
org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper
;
import
static
com
.
nisum
.
ecomcustomer
.
config
.
mongodb
.
CustomMongoConverters
.*;
import
static
com
.
nisum
.
ecomcustomer
.
config
.
mongodb
.
CustomMongoConverters
.
CustomerTypeToIntegerConverter
;
import
static
com
.
nisum
.
ecomcustomer
.
config
.
mongodb
.
CustomMongoConverters
.
IntegerToCustomerTypeConverter
;
import
static
org
.
springframework
.
data
.
mongodb
.
core
.
convert
.
MongoCustomConversions
.
MongoConverterConfigurationAdapter
;
@Configuration
public
class
MongoConfig
extends
AbstractMongoClientConfiguration
{
@Value
(
"${spring.data.mongodb.database}"
)
private
String
databaseName
;
@Override
protected
String
getDatabaseName
()
{
return
databaseName
;
}
//TODO - know about the good practices.
// @Bean
// @Override
// public MappingMongoConverter mappingMongoConverter(MongoDatabaseFactory databaseFactory, MongoCustomConversions customConversions, MongoMappingContext mappingContext) {
// MappingMongoConverter mmc = super.mappingMongoConverter(databaseFactory, customConversions, mappingContext);
// mmc.setTypeMapper(getTypeMapper());
// return mmc;
// }
//
// @Bean
// public MongoTypeMapper getTypeMapper() {
// return new CustomMongoTypeMapper();
// }
@Override
protected
void
configureConverters
(
MongoConverterConfigurationAdapter
adapter
)
{
adapter
.
registerConverter
(
new
CustomerTypeToIntegerConverter
());
adapter
.
registerConverter
(
new
IntegerToCustomerTypeConverter
());
adapter
.
registerConverter
(
new
AddressTypeToStringConverter
());
adapter
.
registerConverter
(
new
StringToAddressTypeConverter
());
}
}
class
CustomMongoTypeMapper
extends
DefaultMongoTypeMapper
{
CustomMongoTypeMapper
()
{
super
(
null
);
}
}
src/main/java/com/nisum/ecomcustomer/controller/CustomerController.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
controller
;
import
com.nisum.ecomcustomer.model.Customer
;
import
com.nisum.ecomcustomer.service.CustomerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
public
class
CustomerController
{
@Autowired
CustomerService
customerService
;
@PostMapping
(
"/"
)
public
Customer
register
(
@RequestBody
Customer
customer
)
{
return
customerService
.
register
(
customer
);
}
@GetMapping
(
"/"
)
public
List
<
Customer
>
getAllCustomers
()
{
return
customerService
.
getAllCustomers
();
}
}
src/main/java/com/nisum/ecomcustomer/model/Address.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
model
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
org.springframework.data.mongodb.core.mapping.Field
;
@Data
public
class
Address
{
// @Field("id")
// private Long addressId;
@Field
(
"type"
)
private
AddressType
addressType
;
@Field
(
"line1"
)
private
String
addressLine1
;
@Field
(
"line2"
)
private
String
addressLine2
;
@JsonProperty
(
"isDefault"
)
private
boolean
isDefault
;
private
String
city
;
private
String
state
;
private
String
country
;
private
String
zipCode
;
}
src/main/java/com/nisum/ecomcustomer/model/AddressType.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
model
;
import
com.fasterxml.jackson.annotation.JsonValue
;
import
lombok.Getter
;
public
enum
AddressType
{
SHIPPING
(
"ship"
),
BILLING
(
"bill"
);
@Getter
@JsonValue
private
String
value
;
@Override
public
String
toString
()
{
return
value
;
}
AddressType
(
String
value
)
{
this
.
value
=
value
;
}
public
static
AddressType
of
(
String
value
)
{
switch
(
value
)
{
case
"ship"
:
return
AddressType
.
SHIPPING
;
case
"bill"
:
return
AddressType
.
BILLING
;
default
:
throw
new
IllegalArgumentException
(
value
+
" can't be converted to type AddressType"
);
}
}
}
src/main/java/com/nisum/ecomcustomer/model/Customer.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
model
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.TypeAlias
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Field
;
import
java.util.List
;
//TODO - check the relevance of annotations
@NoArgsConstructor
@Data
@TypeAlias
(
"customer"
)
@Document
(
"customers"
)
public
class
Customer
{
@Id
private
String
id
;
@Field
(
"fName"
)
private
String
firstName
;
@Field
(
"lName"
)
private
String
lastName
;
private
String
email
;
private
String
dayPhone
;
private
CustomerType
customerType
;
List
<
Address
>
addresses
;
}
src/main/java/com/nisum/ecomcustomer/model/CustomerType.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
model
;
import
com.fasterxml.jackson.annotation.JsonValue
;
import
lombok.Getter
;
@Getter
public
enum
CustomerType
{
REGULAR
(
0
),
LOYAL
(
1
);
@JsonValue
private
int
value
;
CustomerType
(
int
value
)
{
this
.
value
=
value
;
}
@Override
public
String
toString
()
{
return
Integer
.
toString
(
value
);
}
public
static
CustomerType
of
(
int
value
)
{
switch
(
value
)
{
case
0
:
return
CustomerType
.
REGULAR
;
case
1
:
return
CustomerType
.
LOYAL
;
default
:
throw
new
IllegalArgumentException
(
value
+
" can't be converted to type CustomerType"
);
}
}
}
src/main/java/com/nisum/ecomcustomer/repository/CustomerRepository.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
repository
;
import
com.nisum.ecomcustomer.model.Customer
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
public
interface
CustomerRepository
extends
MongoRepository
<
Customer
,
String
>
{
}
src/main/java/com/nisum/ecomcustomer/service/CustomerService.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
service
;
import
com.nisum.ecomcustomer.model.Customer
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
interface
CustomerService
{
public
Customer
register
(
Customer
customer
);
public
List
<
Customer
>
getAllCustomers
();
}
src/main/java/com/nisum/ecomcustomer/service/impl/CustomerServiceImpl.java
0 → 100644
View file @
f607ef4d
package
com
.
nisum
.
ecomcustomer
.
service
.
impl
;
import
com.nisum.ecomcustomer.model.Customer
;
import
com.nisum.ecomcustomer.repository.CustomerRepository
;
import
com.nisum.ecomcustomer.service.CustomerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
CustomerServiceImpl
implements
CustomerService
{
@Autowired
CustomerRepository
customerRepository
;
@Override
public
Customer
register
(
Customer
customer
)
{
return
customerRepository
.
save
(
customer
);
}
@Override
public
List
<
Customer
>
getAllCustomers
()
{
return
customerRepository
.
findAll
();
}
}
src/main/resources/application-development.yml
0 → 100644
View file @
f607ef4d
spring
:
data
:
mongodb
:
host
:
localhost
port
:
27017
database
:
ecom
logging
:
level
:
web
:
debug
\ No newline at end of file
src/main/resources/application.properties
deleted
100644 → 0
View file @
8840cd1b
src/main/resources/application.yml
0 → 100644
View file @
f607ef4d
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
0 → 100644
View file @
f607ef4d
spring
:
application
:
name
:
customer
\ 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