Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
M
Micro_Services
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
ali.saeed
Micro_Services
Commits
af1cdb99
Commit
af1cdb99
authored
Apr 24, 2024
by
Ali Saeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init rest controller for users service
parent
84780d4a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
197 additions
and
0 deletions
+197
-0
InvoicingServiceApplication.java
...rc/main/java/org/example/InvoicingServiceApplication.java
+2
-0
Invoice.java
...ing-service/src/main/java/org/example/models/Invoice.java
+68
-0
User.java
invoicing-service/src/main/java/org/example/models/User.java
+46
-0
UserResource.java
...ice/src/main/java/org/example/resources/UserResource.java
+81
-0
No files found.
invoicing-service/src/main/java/org/example/InvoicingServiceApplication.java
View file @
af1cdb99
...
@@ -2,10 +2,12 @@ package org.example;
...
@@ -2,10 +2,12 @@ package org.example;
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.context.annotation.Bean
;
@SpringBootApplication
@SpringBootApplication
public
class
InvoicingServiceApplication
{
public
class
InvoicingServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
InvoicingServiceApplication
.
class
,
args
);
SpringApplication
.
run
(
InvoicingServiceApplication
.
class
,
args
);
}
}
}
}
invoicing-service/src/main/java/org/example/models/Invoice.java
0 → 100644
View file @
af1cdb99
package
org
.
example
.
models
;
public
class
Invoice
{
private
String
invoiceID
;
private
String
userID
;
private
String
description
;
private
boolean
status
;
private
double
value
;
public
Invoice
(
String
invoiceID
,
String
userID
,
String
description
,
boolean
status
,
double
value
)
{
this
.
invoiceID
=
invoiceID
;
this
.
userID
=
userID
;
this
.
description
=
description
;
this
.
status
=
status
;
this
.
value
=
value
;
}
public
String
getInvoiceID
()
{
return
invoiceID
;
}
public
void
setInvoiceID
(
String
invoiceID
)
{
this
.
invoiceID
=
invoiceID
;
}
public
String
getUserID
()
{
return
userID
;
}
public
void
setUserID
(
String
userID
)
{
this
.
userID
=
userID
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
boolean
isStatus
()
{
return
status
;
}
public
void
setStatus
(
boolean
status
)
{
this
.
status
=
status
;
}
public
double
getValue
()
{
return
value
;
}
public
void
setValue
(
double
value
)
{
this
.
value
=
value
;
}
@Override
public
String
toString
()
{
return
"Invoice{"
+
"invoiceID='"
+
invoiceID
+
'\''
+
", userID='"
+
userID
+
'\''
+
", description='"
+
description
+
'\''
+
", status="
+
status
+
", value="
+
value
+
'}'
;
}
}
invoicing-service/src/main/java/org/example/models/User.java
0 → 100644
View file @
af1cdb99
package
org
.
example
.
models
;
public
class
User
{
private
String
userId
;
private
String
name
;
private
double
balance
;
public
User
(
String
userId
,
String
name
,
double
balance
)
{
this
.
userId
=
userId
;
this
.
name
=
name
;
this
.
balance
=
balance
;
}
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
double
getBalance
()
{
return
balance
;
}
public
void
setBalance
(
double
balance
)
{
this
.
balance
=
balance
;
}
@Override
public
String
toString
()
{
return
"User{"
+
"userId='"
+
userId
+
'\''
+
", name='"
+
name
+
'\''
+
", balance="
+
balance
+
'}'
;
}
}
invoicing-service/src/main/java/org/example/resources/UserResource.java
0 → 100644
View file @
af1cdb99
package
org
.
example
.
resources
;
import
org.example.models.Invoice
;
import
org.example.models.User
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/users"
)
public
class
UserResource
{
@RequestMapping
(
"/{userId}"
)
public
List
<
Invoice
>
getUnPaidInvoices
(
@PathVariable
(
"userId"
)
String
userId
){
Invoice
inv1
=
new
Invoice
(
"1"
,
"1"
,
"ssssssd"
,
true
,
55.0
);
Invoice
inv2
=
new
Invoice
(
"2"
,
"1"
,
"dddddddddd"
,
false
,
545.0
);
System
.
out
.
println
(
userId
);
ArrayList
<
Invoice
>
inv
=
new
ArrayList
<
Invoice
>();
inv
.
add
(
inv1
);
inv
.
add
(
inv2
);
return
inv
;
}
@RequestMapping
(
"/{userId}/{invoiceId}"
)
public
boolean
payInvoice
(
@PathVariable
(
"userId"
)
String
userId
,
@PathVariable
(
"invoiceId"
)
String
invoiceId
){
User
user
=
new
User
(
"1"
,
"Ali"
,
500.0
);
Invoice
invoice
=
new
Invoice
(
"2"
,
"1"
,
"dddddddddd"
,
false
,
545.0
);
if
(
user
.
getBalance
()
>=
invoice
.
getValue
()){
user
.
setBalance
(
user
.
getBalance
()
-
invoice
.
getValue
());
invoice
.
setStatus
(
true
);
return
true
;
}
else
{
System
.
out
.
println
(
"you do not have enough balance!!!"
);
return
false
;
}
}
@RequestMapping
()
public
HashMap
<
User
,
Invoice
>
getAllUsersHaveUnPaidInvoices
(){
User
user1
=
new
User
(
"1"
,
"Ali"
,
500.0
);
User
user2
=
new
User
(
"2"
,
"Hasan"
,
5000.0
);
Invoice
invoice1
=
new
Invoice
(
"2"
,
"1"
,
"dddddddddd"
,
false
,
545.0
);
Invoice
invoice2
=
new
Invoice
(
"3"
,
"2"
,
"dddddddddd"
,
false
,
545.0
);
ArrayList
<
Invoice
>
inv
=
new
ArrayList
<
Invoice
>();
inv
.
add
(
invoice1
);
inv
.
add
(
invoice2
);
HashMap
<
User
,
Invoice
>
userInvoiceHashMap
=
new
HashMap
<>();
for
(
Invoice
invoice:
inv
)
{
String
id
=
invoice
.
getUserID
();
}
userInvoiceHashMap
.
put
(
user1
,
invoice1
);
userInvoiceHashMap
.
put
(
user2
,
invoice2
);
return
userInvoiceHashMap
;
}
@RequestMapping
()
public
HashMap
<
User
,
Invoice
>
getAllUsersHavePaidInvoices
(){
User
user1
=
new
User
(
"1"
,
"Ali"
,
500.0
);
User
user2
=
new
User
(
"2"
,
"Hasan"
,
5000.0
);
Invoice
invoice1
=
new
Invoice
(
"2"
,
"1"
,
"dddddddddd"
,
true
,
545.0
);
Invoice
invoice2
=
new
Invoice
(
"3"
,
"2"
,
"dddddddddd"
,
true
,
545.0
);
ArrayList
<
Invoice
>
inv
=
new
ArrayList
<
Invoice
>();
inv
.
add
(
invoice1
);
inv
.
add
(
invoice2
);
HashMap
<
User
,
Invoice
>
userInvoiceHashMap
=
new
HashMap
<>();
for
(
Invoice
invoice:
inv
)
{
String
id
=
invoice
.
getUserID
();
}
userInvoiceHashMap
.
put
(
user1
,
invoice1
);
userInvoiceHashMap
.
put
(
user2
,
invoice2
);
return
userInvoiceHashMap
;
}
}
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