Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SpringBoot-MicroServices
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
Simhadri Guntreddi
SpringBoot-MicroServices
Commits
52393c61
Commit
52393c61
authored
Feb 24, 2020
by
Simhadri Guntreddi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
second commit for new changes
parent
99c55f7a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
14 deletions
+27
-14
CatalogController.java
...va/com/training/catalog/controller/CatalogController.java
+9
-3
CatalogService.java
...ain/java/com/training/catalog/service/CatalogService.java
+2
-1
CatalogServiceImpl.java
...java/com/training/catalog/service/CatalogServiceImpl.java
+11
-6
BagService.java
...rc/main/java/com/training/product/service/BagService.java
+0
-2
BagServiceImpl.java
...ain/java/com/training/product/service/BagServiceImpl.java
+5
-2
No files found.
catalog-service/src/main/java/com/training/catalog/controller/CatalogController.java
View file @
52393c61
package
com
.
training
.
catalog
.
controller
;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -25,10 +26,15 @@ public class CatalogController {
return
new
ResponseEntity
<
List
<
Product
>>(
catalogService
.
getProducts
(),
HttpStatus
.
OK
);
}
@GetMapping
(
"/{name}"
)
public
ResponseEntity
<
Product
>
getProductWith
(
@PathVariable
(
"name"
)
String
name
)
{
// System.out.println("name-->" + name);
return
new
ResponseEntity
<
Product
>(
catalogService
.
getProduct
(
name
),
HttpStatus
.
OK
);
public
ResponseEntity
<
Optional
<
Product
>>
getProductWith
(
@PathVariable
(
"name"
)
String
name
)
{
Optional
<
Product
>
productName
=
catalogService
.
getProduct
(
name
);
if
(
productName
.
isPresent
())
{
return
new
ResponseEntity
<
Optional
<
Product
>
>(
productName
,
HttpStatus
.
OK
);
}
return
new
ResponseEntity
<
Optional
<
Product
>
>(
HttpStatus
.
NOT_FOUND
);
}
}
catalog-service/src/main/java/com/training/catalog/service/CatalogService.java
View file @
52393c61
package
com
.
training
.
catalog
.
service
;
import
java.util.List
;
import
java.util.Optional
;
import
com.training.catalog.model.Product
;
public
interface
CatalogService
{
public
List
<
Product
>
getProducts
();
public
Product
getProduct
(
String
name
)
;
public
Optional
<
Product
>
getProduct
(
String
name
)
;
}
catalog-service/src/main/java/com/training/catalog/service/CatalogServiceImpl.java
View file @
52393c61
...
...
@@ -3,6 +3,7 @@ package com.training.catalog.service;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.training.catalog.model.Product
;
...
...
@@ -11,8 +12,9 @@ import com.training.catalog.respository.CatalogRepository;
@Service
public
class
CatalogServiceImpl
implements
CatalogService
{
@Autowired
private
CatalogRepository
catalogRepository
;
@Override
public
List
<
Product
>
getProducts
()
{
List
<
Product
>
listOfProducts
=
catalogRepository
.
findAll
();
...
...
@@ -20,12 +22,15 @@ public class CatalogServiceImpl implements CatalogService {
}
@Override
public
Product
getProduct
(
String
name
)
{
Optional
<
Product
>
findById
=
catalogRepository
.
findById
(
name
);
if
(
findById
.
isPresent
())
{
return
findById
.
get
();
public
Optional
<
Product
>
getProduct
(
String
name
)
{
if
(
catalogRepository
.
existsById
(
name
))
{
Optional
<
Product
>
findById
=
catalogRepository
.
findById
(
name
);
if
(
findById
.
isPresent
())
{
return
findById
;
}
}
return
null
;
return
Optional
.
empty
()
;
}
}
product-service/src/main/java/com/training/product/service/BagService.java
View file @
52393c61
package
com
.
training
.
product
.
service
;
import
org.springframework.stereotype.Service
;
import
com.training.product.model.Product
;
public
interface
BagService
{
...
...
product-service/src/main/java/com/training/product/service/BagServiceImpl.java
View file @
52393c61
...
...
@@ -30,16 +30,19 @@ public class BagServiceImpl implements BagService {
product
.
setPrice
(
pro
.
getPrice
());
product
.
setQuantity
(
pro
.
getQuantity
());
bagRepository
.
save
(
product
);
return
"
u
pdated..!"
;
return
"
Product U
pdated..!"
;
}
return
"
Product Updated
"
;
return
"
There is a no product on this name
"
;
}
@Override
public
String
deleteProduct
(
String
name
)
{
if
(
bagRepository
.
existsById
(
name
))
{
bagRepository
.
deleteById
(
name
);
return
"Product Deleted "
;
}
return
"Please give correct product name/there is a no product on this name"
;
}
}
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