Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-training-project-final
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
Gopi Ayinala Ayinala
java-training-project-final
Commits
867d2c3e
Commit
867d2c3e
authored
Jul 28, 2022
by
Muhammad Abdul Qadeer Farooqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orders logs, feign update in seller
parent
910f2f77
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
169 additions
and
7 deletions
+169
-7
CustomerController.java
...va/com/qadeer/customer/controller/CustomerController.java
+6
-0
FeignService.java
...src/main/java/com/qadeer/customer/feign/FeignService.java
+1
-1
CustomerService.java
...ain/java/com/qadeer/customer/service/CustomerService.java
+5
-0
ProductService.java
...ain/java/com/qadeer/inventory/service/ProductService.java
+34
-3
orders.csv
seller-service/orders.csv
+5
-0
pom.xml
seller-service/pom.xml
+17
-0
SellerServiceApplication.java
...main/java/com/qadeer/seller/SellerServiceApplication.java
+2
-0
SellerController.java
...n/java/com/qadeer/seller/controller/SellerController.java
+11
-3
ProductDto.java
...rvice/src/main/java/com/qadeer/seller/dto/ProductDto.java
+23
-0
FeignService.java
...e/src/main/java/com/qadeer/seller/feign/FeignService.java
+14
-0
SellerService.java
...rc/main/java/com/qadeer/seller/service/SellerService.java
+51
-0
No files found.
customer-service/src/main/java/com/qadeer/customer/controller/CustomerController.java
View file @
867d2c3e
...
@@ -28,4 +28,10 @@ public class CustomerController {
...
@@ -28,4 +28,10 @@ public class CustomerController {
List
<
ProductDto
>
productDtoList
=
service
.
buyProducts
(
productName
,
String
.
valueOf
(
productQuantity
));
List
<
ProductDto
>
productDtoList
=
service
.
buyProducts
(
productName
,
String
.
valueOf
(
productQuantity
));
return
new
ResponseEntity
<
List
<
ProductDto
>>(
productDtoList
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<
List
<
ProductDto
>>(
productDtoList
,
HttpStatus
.
OK
);
}
}
@GetMapping
(
"/product/{id}"
)
public
ResponseEntity
<?>
getProductById
(
@PathVariable
int
id
)
{
ProductDto
productDto
=
service
.
getProductById
(
id
);
return
ResponseEntity
.
ok
(
productDto
);
}
}
}
customer-service/src/main/java/com/qadeer/customer/feign/FeignService.java
View file @
867d2c3e
...
@@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.PathVariable;
...
@@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import
java.util.List
;
import
java.util.List
;
@FeignClient
(
name
=
"
inventory-api"
,
url
=
"http://localhost:8083/inventory
"
)
@FeignClient
(
name
=
"
seller-api"
,
url
=
"http://localhost:8082/seller
"
)
public
interface
FeignService
{
public
interface
FeignService
{
@GetMapping
(
"/product/{id}"
)
@GetMapping
(
"/product/{id}"
)
...
...
customer-service/src/main/java/com/qadeer/customer/service/CustomerService.java
View file @
867d2c3e
...
@@ -23,4 +23,9 @@ public class CustomerService {
...
@@ -23,4 +23,9 @@ public class CustomerService {
ResponseEntity
<
List
<
ProductDto
>>
productDto
=
feignService
.
buyProducts
(
productName
,
productQuantity
);
ResponseEntity
<
List
<
ProductDto
>>
productDto
=
feignService
.
buyProducts
(
productName
,
productQuantity
);
return
productDto
.
getBody
();
return
productDto
.
getBody
();
}
}
public
ProductDto
getProductById
(
int
id
)
{
ProductDto
productDto
=
feignService
.
getProductById
(
id
);
return
productDto
;
}
}
}
inventory-service/src/main/java/com/qadeer/inventory/service/ProductService.java
View file @
867d2c3e
...
@@ -49,8 +49,39 @@ public class ProductService {
...
@@ -49,8 +49,39 @@ public class ProductService {
return
productList
;
return
productList
;
}
}
public
List
<
Product
>
buyProducts
(
String
productName
,
int
productQuantity
)
{
public
List
<
Product
>
buyProducts
(
String
productName
,
int
requiredQuant
)
{
List
<
Product
>
product
=
repository
.
findByName
(
productName
);
List
<
Product
>
productList
=
repository
.
findByName
(
productName
);
return
product
;
List
<
Product
>
myProducts
=
new
ArrayList
<>();
int
requiredProducts
=
0
;
for
(
Product
product:
productList
)
{
if
(
product
.
getQuantity
()
>=
requiredQuant
)
{
// create copy of product object.
Product
deliverProduct
=
new
Product
();
deliverProduct
.
setId
(
product
.
getId
());
deliverProduct
.
setName
(
product
.
getName
());
deliverProduct
.
setPrice
(
product
.
getPrice
());
deliverProduct
.
setQuantity
(
requiredQuant
);
myProducts
.
add
(
deliverProduct
);
product
.
setQuantity
(
product
.
getQuantity
()
-
requiredQuant
);
repository
.
save
(
product
);
}
else
if
(
product
.
getQuantity
()
>
0
&&
product
.
getQuantity
()
<
requiredQuant
){
requiredProducts
=
requiredQuant
-
product
.
getQuantity
();
// create copy of product object.
Product
deliverProduct
=
new
Product
();
deliverProduct
.
setId
(
product
.
getId
());
deliverProduct
.
setName
(
product
.
getName
());
deliverProduct
.
setPrice
(
product
.
getPrice
());
deliverProduct
.
setQuantity
(
product
.
getQuantity
());
System
.
out
.
println
(
requiredProducts
);
myProducts
.
add
(
deliverProduct
);
product
.
setQuantity
(
0
);
repository
.
save
(
product
);
}
else
{
myProducts
.
add
(
null
);
}
}
return
myProducts
;
}
}
}
}
seller-service/orders.csv
0 → 100644
View file @
867d2c3e
id=11, name='Cheese', price=120, quantity=0 28/Jul/2022 20:20:30
id=12, name='Cream', price=250, quantity=5 28/Jul/2022 20:20:31
id=13, name='Shortbread', price=200, quantity=0 28/Jul/2022 20:20:33
id=14, name='Sprite', price=230, quantity=5 28/Jul/2022 20:20:34
id=15, name='Vinegar', price=400, quantity=3 28/Jul/2022 20:20:34
seller-service/pom.xml
View file @
867d2c3e
...
@@ -15,8 +15,13 @@
...
@@ -15,8 +15,13 @@
<description>
Final project
</description>
<description>
Final project
</description>
<properties>
<properties>
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
<spring-cloud.version>
2021.0.3
</spring-cloud.version>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
...
@@ -47,6 +52,18 @@
...
@@ -47,6 +52,18 @@
</dependency>
</dependency>
</dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
${spring-cloud.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
...
...
seller-service/src/main/java/com/qadeer/seller/SellerServiceApplication.java
View file @
867d2c3e
...
@@ -2,8 +2,10 @@ package com.qadeer.seller;
...
@@ -2,8 +2,10 @@ package com.qadeer.seller;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
@SpringBootApplication
@SpringBootApplication
@EnableFeignClients
public
class
SellerServiceApplication
{
public
class
SellerServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
seller-service/src/main/java/com/qadeer/seller/controller/SellerController.java
View file @
867d2c3e
package
com
.
qadeer
.
seller
.
controller
;
package
com
.
qadeer
.
seller
.
controller
;
import
com.qadeer.seller.dto.ProductDto
;
import
com.qadeer.seller.model.Seller
;
import
com.qadeer.seller.model.Seller
;
import
com.qadeer.seller.service.SellerService
;
import
com.qadeer.seller.service.SellerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@RestController
...
@@ -10,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -10,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
public
class
SellerController
{
public
class
SellerController
{
@Autowired
@Autowired
private
SellerService
se
llerSe
rvice
;
private
SellerService
service
;
@GetMapping
(
"/hello"
)
@GetMapping
(
"/hello"
)
public
String
hello
()
{
public
String
hello
()
{
...
@@ -19,12 +21,18 @@ public class SellerController {
...
@@ -19,12 +21,18 @@ public class SellerController {
@PostMapping
@PostMapping
public
void
createProduct
(
@RequestBody
Seller
seller
)
{
public
void
createProduct
(
@RequestBody
Seller
seller
)
{
se
llerSe
rvice
.
saveProduct
(
seller
);
service
.
saveProduct
(
seller
);
}
}
@GetMapping
(
"/{id}"
)
@GetMapping
(
"/{id}"
)
public
Seller
getProduct
(
@PathVariable
int
id
)
{
public
Seller
getProduct
(
@PathVariable
int
id
)
{
return
sellerService
.
getProduct
(
id
);
return
service
.
getProduct
(
id
);
}
@GetMapping
(
"/product/{id}"
)
public
ResponseEntity
<?>
getProductById
(
@PathVariable
int
id
)
{
ProductDto
productDto
=
service
.
getProductById
(
id
);
return
ResponseEntity
.
ok
(
productDto
);
}
}
}
}
seller-service/src/main/java/com/qadeer/seller/dto/ProductDto.java
0 → 100644
View file @
867d2c3e
package
com
.
qadeer
.
seller
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
ProductDto
{
private
int
id
;
private
String
name
;
private
int
price
;
private
int
quantity
;
@Override
public
String
toString
()
{
return
"id="
+
id
+
", name='"
+
name
+
'\''
+
", price="
+
price
+
", quantity="
+
quantity
;
}
}
seller-service/src/main/java/com/qadeer/seller/feign/FeignService.java
0 → 100644
View file @
867d2c3e
package
com
.
qadeer
.
seller
.
feign
;
import
com.qadeer.seller.dto.ProductDto
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
@FeignClient
(
name
=
"inventory-api"
,
url
=
"http://localhost:8083/inventory"
)
public
interface
FeignService
{
@GetMapping
(
"/product/{id}"
)
ProductDto
getProductById
(
@PathVariable
int
id
);
}
seller-service/src/main/java/com/qadeer/seller/service/SellerService.java
View file @
867d2c3e
package
com
.
qadeer
.
seller
.
service
;
package
com
.
qadeer
.
seller
.
service
;
import
com.qadeer.seller.dto.ProductDto
;
import
com.qadeer.seller.feign.FeignService
;
import
com.qadeer.seller.model.Seller
;
import
com.qadeer.seller.model.Seller
;
import
com.qadeer.seller.repository.SellerRepository
;
import
com.qadeer.seller.repository.SellerRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.nio.file.StandardOpenOption
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.format.DateTimeFormatter
;
import
static
java
.
awt
.
SystemColor
.
text
;
@Service
@Service
public
class
SellerService
{
public
class
SellerService
{
@Autowired
@Autowired
private
SellerRepository
repository
;
private
SellerRepository
repository
;
@Autowired
private
FeignService
feignService
;
String
path
=
"/Users/aqadeer/Desktop/java-training-project-final/seller-service/orders.csv"
;
FileWriter
fw
=
new
FileWriter
(
path
);
public
SellerService
()
throws
IOException
{
}
public
void
saveProduct
(
Seller
seller
){
public
void
saveProduct
(
Seller
seller
){
repository
.
save
(
seller
);
repository
.
save
(
seller
);
};
};
...
@@ -18,4 +43,30 @@ public class SellerService {
...
@@ -18,4 +43,30 @@ public class SellerService {
public
Seller
getProduct
(
int
id
)
{
public
Seller
getProduct
(
int
id
)
{
return
repository
.
findById
(
id
).
get
();
return
repository
.
findById
(
id
).
get
();
}
}
public
ProductDto
getProductById
(
int
id
)
{
ProductDto
productDto
=
feignService
.
getProductById
(
id
);
orderLogs
(
productDto
);
return
productDto
;
}
public
void
orderLogs
(
ProductDto
productDto
)
{
// String path = "/Users/aqadeer/Desktop/java-training-project-final/seller-service/orders.csv";
// BufferedWriter bw = null;
try
{
DateTimeFormatter
dtf
=
DateTimeFormatter
.
ofPattern
(
"dd/MMM/yyyy HH:mm:ss"
);
LocalDateTime
now
=
LocalDateTime
.
now
();
String
myTime
=
dtf
.
format
(
now
);
String
text
=
productDto
.
toString
()
+
" "
+
myTime
+
"\n"
;
Files
.
write
(
Paths
.
get
(
path
),
text
.
getBytes
(),
StandardOpenOption
.
APPEND
);
// bw = new BufferedWriter(fw);
// bw.append(productDto.toString());
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
// bw.close();
}
}
}
}
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