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
Muhammad Abdul Qadeer Farooqui
java-training-project-final
Commits
910f2f77
Commit
910f2f77
authored
2 years ago
by
Muhammad Abdul Qadeer Farooqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
model, controller added
parent
b1d025a1
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
231 additions
and
12 deletions
+231
-12
pom.xml
customer-service/pom.xml
+16
-1
restock
customer-service/restock
+4
-0
CustomerServiceApplication.java
.../java/com/qadeer/customer/CustomerServiceApplication.java
+2
-0
CustomerController.java
...va/com/qadeer/customer/controller/CustomerController.java
+20
-3
ProductDto.java
...ice/src/main/java/com/qadeer/customer/dto/ProductDto.java
+15
-0
FeignService.java
...src/main/java/com/qadeer/customer/feign/FeignService.java
+19
-0
Customer.java
...ice/src/main/java/com/qadeer/customer/model/Customer.java
+2
-1
CustomerService.java
...ain/java/com/qadeer/customer/service/CustomerService.java
+26
-0
restock.csv
inventory-service/restock.csv
+6
-0
InventoryController.java
.../com/qadeer/inventory/controller/InventoryController.java
+33
-3
Product.java
...ice/src/main/java/com/qadeer/inventory/model/Product.java
+8
-1
ProductRepository.java
...va/com/qadeer/inventory/repository/ProductRepository.java
+5
-0
ProductService.java
...ain/java/com/qadeer/inventory/service/ProductService.java
+52
-0
restock.csv
seller-service/restock.csv
+21
-0
SellerController.java
...n/java/com/qadeer/seller/controller/SellerController.java
+1
-0
Seller.java
...service/src/main/java/com/qadeer/seller/model/Seller.java
+1
-3
No files found.
customer-service/pom.xml
View file @
910f2f77
...
...
@@ -15,8 +15,13 @@
<description>
Final project
</description>
<properties>
<java.version>
1.8
</java.version>
<spring-cloud.version>
2021.0.3
</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
...
...
@@ -48,7 +53,17 @@
<artifactId>
spring-boot-starter-validation
</artifactId>
</dependency>
</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>
<plugins>
<plugin>
...
...
This diff is collapsed.
Click to expand it.
customer-service/restock
0 → 100644
View file @
910f2f77
1,noodles,250,5,12
1,noodles,250,5,12
1,noodles,250,5,12
1,noodles,250,5,12
\ No newline at end of file
This diff is collapsed.
Click to expand it.
customer-service/src/main/java/com/qadeer/customer/CustomerServiceApplication.java
View file @
910f2f77
...
...
@@ -2,8 +2,10 @@ package com.qadeer.customer;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
@SpringBootApplication
@EnableFeignClients
public
class
CustomerServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
This diff is collapsed.
Click to expand it.
customer-service/src/main/java/com/qadeer/customer/controller/CustomerController.java
View file @
910f2f77
package
com
.
qadeer
.
customer
.
controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.qadeer.customer.dto.ProductDto
;
import
com.qadeer.customer.model.Customer
;
import
com.qadeer.customer.service.CustomerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/customer"
)
public
class
CustomerController
{
@Autowired
private
CustomerService
service
;
@GetMapping
(
"/hello"
)
public
String
hello
()
{
return
"Hello"
;
}
@GetMapping
(
"/buy/{productName}/{quantity}"
)
public
ResponseEntity
<
List
<
ProductDto
>>
buy
(
@PathVariable
(
"productName"
)
String
productName
,
@PathVariable
(
"quantity"
)
int
productQuantity
)
{
List
<
ProductDto
>
productDtoList
=
service
.
buyProducts
(
productName
,
String
.
valueOf
(
productQuantity
));
return
new
ResponseEntity
<
List
<
ProductDto
>>(
productDtoList
,
HttpStatus
.
OK
);
}
}
This diff is collapsed.
Click to expand it.
customer-service/src/main/java/com/qadeer/customer/dto/ProductDto.java
0 → 100644
View file @
910f2f77
package
com
.
qadeer
.
customer
.
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
;
}
This diff is collapsed.
Click to expand it.
customer-service/src/main/java/com/qadeer/customer/feign/FeignService.java
0 → 100644
View file @
910f2f77
package
com
.
qadeer
.
customer
.
feign
;
import
com.qadeer.customer.dto.ProductDto
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
java.util.List
;
@FeignClient
(
name
=
"inventory-api"
,
url
=
"http://localhost:8083/inventory"
)
public
interface
FeignService
{
@GetMapping
(
"/product/{id}"
)
ProductDto
getProductById
(
@PathVariable
int
id
);
@GetMapping
(
"/product/{productName}/{productQuantity}"
)
ResponseEntity
<
List
<
ProductDto
>>
buyProducts
(
@PathVariable
(
"productName"
)
String
productName
,
@PathVariable
(
"productQuantity"
)
String
productQuantity
);
}
This diff is collapsed.
Click to expand it.
customer-service/src/main/java/com/qadeer/customer/model/Customer.java
View file @
910f2f77
...
...
@@ -15,5 +15,6 @@ public class Customer {
@Id
private
int
id
;
private
String
name
;
private
int
budget
;
private
String
phoneNo
;
private
String
creditCardNo
;
}
This diff is collapsed.
Click to expand it.
customer-service/src/main/java/com/qadeer/customer/service/CustomerService.java
0 → 100644
View file @
910f2f77
package
com
.
qadeer
.
customer
.
service
;
import
com.qadeer.customer.dto.ProductDto
;
import
com.qadeer.customer.feign.FeignService
;
import
com.qadeer.customer.repository.CustomerRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
CustomerService
{
@Autowired
private
CustomerRepository
repository
;
@Autowired
private
FeignService
feignService
;
public
List
<
ProductDto
>
buyProducts
(
String
productName
,
String
productQuantity
)
{
ResponseEntity
<
List
<
ProductDto
>>
productDto
=
feignService
.
buyProducts
(
productName
,
productQuantity
);
return
productDto
.
getBody
();
}
}
This diff is collapsed.
Click to expand it.
inventory-service/restock.csv
0 → 100644
View file @
910f2f77
product_name,product_price,product_quantity
Cheese,120,3
Cream,250,5
Shortbread,200,3
Sprite,230,5
Vinegar,400,3
This diff is collapsed.
Click to expand it.
inventory-service/src/main/java/com/qadeer/inventory/controller/InventoryController.java
View file @
910f2f77
package
com
.
qadeer
.
inventory
.
controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.qadeer.inventory.model.Product
;
import
com.qadeer.inventory.service.ProductService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/inventory"
)
public
class
InventoryController
{
@Autowired
private
ProductService
service
;
@GetMapping
(
"/hello"
)
public
String
hello
()
{
return
"Hello"
;
}
@PostMapping
(
"/restock"
)
public
ResponseEntity
<?>
restock
(
MultipartFile
file
)
throws
IOException
{
List
<
Product
>
productList
=
service
.
restock
(
file
);
return
new
ResponseEntity
<
List
<
Product
>>(
productList
,
HttpStatus
.
OK
);
}
@GetMapping
(
"/product/{id}"
)
public
ResponseEntity
<?>
getProductById
(
@PathVariable
int
id
)
{
Product
product
=
service
.
getProductById
(
id
);
return
new
ResponseEntity
<
Product
>(
product
,
HttpStatus
.
OK
);
}
@GetMapping
(
"/product/{productName}/{productQuantity}"
)
public
ResponseEntity
<?>
buyProducts
(
@PathVariable
(
"productName"
)
String
productName
,
@PathVariable
(
"productQuantity"
)
int
productQuantity
)
{
List
<
Product
>
productList
=
service
.
buyProducts
(
productName
,
productQuantity
);
return
new
ResponseEntity
<
List
<
Product
>>(
productList
,
HttpStatus
.
OK
);
}
}
This diff is collapsed.
Click to expand it.
inventory-service/src/main/java/com/qadeer/inventory/model/Product.java
View file @
910f2f77
...
...
@@ -5,6 +5,8 @@ import lombok.Data;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
@Entity
...
...
@@ -13,10 +15,15 @@ import javax.persistence.Id;
@NoArgsConstructor
public
class
Product
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
int
id
;
private
String
name
;
private
int
price
;
private
int
quantity
;
private
int
sellerId
;
public
Product
(
String
name
,
int
price
,
int
quantity
)
{
this
.
name
=
name
;
this
.
price
=
price
;
this
.
quantity
=
quantity
;
}
}
This diff is collapsed.
Click to expand it.
inventory-service/src/main/java/com/qadeer/inventory/repository/ProductRepository.java
View file @
910f2f77
...
...
@@ -2,6 +2,11 @@ package com.qadeer.inventory.repository;
import
com.qadeer.inventory.model.Product
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
ProductRepository
extends
JpaRepository
<
Product
,
Integer
>
{
List
<
Product
>
findByName
(
String
productName
);
}
This diff is collapsed.
Click to expand it.
inventory-service/src/main/java/com/qadeer/inventory/service/ProductService.java
View file @
910f2f77
package
com
.
qadeer
.
inventory
.
service
;
import
com.qadeer.inventory.model.Product
;
import
com.qadeer.inventory.repository.ProductRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.List
;
@Service
public
class
ProductService
{
@Autowired
private
ProductRepository
repository
;
public
List
<
Product
>
getAllProducts
()
{
return
repository
.
findAll
();
}
public
Product
getProductById
(
int
id
)
{
return
repository
.
findById
(
id
).
get
();
}
public
void
createProduct
(
Product
product
)
{
repository
.
save
(
product
);
}
public
List
<
Product
>
restock
(
MultipartFile
file
)
throws
IOException
{
InputStreamReader
ir
=
new
InputStreamReader
(
file
.
getInputStream
());
BufferedReader
br
=
new
BufferedReader
(
ir
);
String
line
=
br
.
readLine
();
line
=
br
.
readLine
();
List
<
Product
>
productList
=
new
ArrayList
<>();
while
(
line
!=
null
)
{
String
[]
content
=
line
.
split
(
","
);
String
name
=
content
[
0
].
trim
();
int
price
=
Integer
.
parseInt
(
content
[
1
]);
int
quantity
=
Integer
.
parseInt
(
content
[
2
]);
Product
product
=
new
Product
(
name
,
price
,
quantity
);
repository
.
save
(
product
);
productList
.
add
(
product
);
line
=
br
.
readLine
();
}
return
productList
;
}
public
List
<
Product
>
buyProducts
(
String
productName
,
int
productQuantity
)
{
List
<
Product
>
product
=
repository
.
findByName
(
productName
);
return
product
;
}
}
This diff is collapsed.
Click to expand it.
seller-service/restock.csv
0 → 100644
View file @
910f2f77
product_name,product_quantity
Cheese,3
Cream,5
Shortbread,3
Sprite,5
Vinegar3
Mussels,2
Croissant,5
Beef,1
Bandage,2
Tea,5
Fond,5
Cake,5
Fudge,2
Wine,1
Spinach,2
Fish,1
Mushroom,5
Mustard,4
Food Colouring,5
Bread,3
\ No newline at end of file
This diff is collapsed.
Click to expand it.
seller-service/src/main/java/com/qadeer/seller/controller/SellerController.java
View file @
910f2f77
...
...
@@ -26,4 +26,5 @@ public class SellerController {
public
Seller
getProduct
(
@PathVariable
int
id
)
{
return
sellerService
.
getProduct
(
id
);
}
}
This diff is collapsed.
Click to expand it.
seller-service/src/main/java/com/qadeer/seller/model/Seller.java
View file @
910f2f77
...
...
@@ -17,9 +17,7 @@ import javax.validation.constraints.Pattern;
@NoArgsConstructor
public
class
Seller
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
int
id
;
private
String
name
;
private
String
address
;
private
int
phoneNo
;
private
int
productId
;
}
This diff is collapsed.
Click to expand it.
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