Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
ECommerceSystem
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
1516160
ECommerceSystem
Commits
d71a3831
Commit
d71a3831
authored
Aug 04, 2023
by
1516160
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
05b0d0a5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
163 additions
and
0 deletions
+163
-0
AdminDbConsoleService.java
...d/candidate/assessment/service/AdminDbConsoleService.java
+163
-0
No files found.
src/main/java/com/altimetrik/playground/candidate/assessment/service/AdminDbConsoleService.java
0 → 100644
View file @
d71a3831
package
com
.
altimetrik
.
playground
.
candidate
.
assessment
.
service
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.altimetrik.playground.candidate.assessment.entity.Customer
;
import
com.altimetrik.playground.candidate.assessment.entity.CustomerCart
;
import
com.altimetrik.playground.candidate.assessment.entity.CustomerCartID
;
import
com.altimetrik.playground.candidate.assessment.entity.Product
;
import
com.altimetrik.playground.candidate.assessment.repository.CustomerCartRepo
;
import
com.altimetrik.playground.candidate.assessment.repository.CustomerRepo
;
import
com.altimetrik.playground.candidate.assessment.repository.ProductRepo
;
import
com.altimetrik.playground.candidate.assessment.request.CustomerReq
;
import
com.altimetrik.playground.candidate.assessment.request.ProductReq
;
@Service
public
class
AdminDbConsoleService
implements
IAdminDbConsole
{
@Autowired
private
CustomerRepo
repo
;
@Autowired
private
CustomerCartRepo
ccRepo
;
@Autowired
private
ProductRepo
pRepo
;
@Override
public
String
newCustomer
(
CustomerReq
request
)
{
if
(
repo
.
findById
(
request
.
getEmail
()).
isPresent
())
{
return
"Already Customer available"
;
}
else
{
Customer
cust
=
new
Customer
();
cust
.
setAddress
(
request
.
getAddress
());
cust
.
setAge
(
request
.
getAge
());
cust
.
setEmail
(
request
.
getEmail
());
cust
.
setGender
(
request
.
getGender
());
cust
.
setName
(
request
.
getName
());
cust
.
setPassword
(
request
.
getPassword
());
repo
.
save
(
cust
);
}
return
"Customer Created"
;
}
@Override
public
String
addProduct
(
ProductReq
request
)
{
CustomerCartID
id
=
new
CustomerCartID
();
id
.
setEmail
(
request
.
getEmail
());
id
.
setProdId
(
request
.
getProdId
());
if
(
ccRepo
.
findById
(
id
).
isPresent
())
{
return
"Product already Added"
;
}
else
{
CustomerCart
cc
=
new
CustomerCart
();
cc
.
setCheckOutStatus
(
'N'
);
cc
.
setCustomerName
(
repo
.
findById
(
request
.
getEmail
()).
get
().
getName
());
cc
.
setPrice
(
request
.
getPrice
());
cc
.
setProdname
(
request
.
getProdname
());
cc
.
setQuantity
(
request
.
getQuantity
());
cc
.
setId
(
id
);
ccRepo
.
save
(
cc
);
}
return
"Product added in the cart"
;
}
@Override
public
String
removeItem
(
ProductReq
request
)
{
CustomerCartID
id
=
new
CustomerCartID
();
id
.
setEmail
(
request
.
getEmail
());
id
.
setProdId
(
request
.
getProdId
());
ccRepo
.
deleteById
(
id
);
return
"Successfully removed the item from the Cart"
;
}
@Override
public
String
updateProduct
(
ProductReq
request
)
{
CustomerCartID
id
=
new
CustomerCartID
();
id
.
setEmail
(
request
.
getEmail
());
id
.
setProdId
(
request
.
getProdId
());
CustomerCart
cc
=
new
CustomerCart
();
cc
.
setCheckOutStatus
(
'N'
);
cc
.
setCustomerName
(
repo
.
findById
(
request
.
getEmail
()).
get
().
getName
());
cc
.
setPrice
(
request
.
getPrice
());
cc
.
setProdname
(
request
.
getProdname
());
cc
.
setQuantity
(
request
.
getQuantity
());
cc
.
setId
(
id
);
ccRepo
.
save
(
cc
);
return
"Cart Item is updated"
;
}
@Override
public
List
<
ProductReq
>
getCartdetails
(
String
email
)
{
List
<
CustomerCart
>
list
=
ccRepo
.
findByIdEmailAndCheckOutStatus
(
email
,
'N'
);
List
<
ProductReq
>
res
=
new
ArrayList
<
ProductReq
>();
for
(
CustomerCart
cc
:
list
)
{
ProductReq
prod
=
new
ProductReq
();
prod
.
setEmail
(
email
);
prod
.
setPrice
(
cc
.
getPrice
());
prod
.
setProdId
(
cc
.
getId
().
getProdId
());
prod
.
setProdname
(
cc
.
getProdname
());
prod
.
setQuantity
(
cc
.
getQuantity
());
res
.
add
(
prod
);
}
return
res
;
}
@Override
public
String
doCheckOut
(
List
<
ProductReq
>
request
)
{
String
email
=
request
.
get
(
0
).
getEmail
();
List
<
Integer
>
prodIds
=
request
.
stream
().
map
(
i
->
i
.
getProdId
()).
distinct
().
collect
(
Collectors
.
toList
());
ccRepo
.
updateCheckOutstatus
(
'Y'
,
email
,
prodIds
);
return
null
;
}
@Override
public
List
<
ProductReq
>
getProduct
(
String
prodName
)
{
List
<
Product
>
product
=
pRepo
.
getProduct
(
prodName
);
List
<
ProductReq
>
res
=
new
LinkedList
<
ProductReq
>();
for
(
Product
p
:
product
)
{
ProductReq
prod
=
new
ProductReq
();
prod
.
setPrice
(
p
.
getPrice
());
prod
.
setProdId
(
p
.
getProdId
());
prod
.
setProdname
(
p
.
getProdname
());
res
.
add
(
prod
);
}
return
res
;
}
}
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