Commit 2ad6a1d6 authored by Ali Saeed's avatar Ali Saeed

init rest controller for invoices service

parent dc8f7a5e
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 +
'}';
}
}
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 +
'}';
}
}
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("/invoices")
public class InvoiceResource {
@RequestMapping("/{userId}")
public List<Invoice> getUnPaidInvoicesForSpecificUser(@PathVariable("userId") String userId){
Invoice inv1 = new Invoice("1", "1","ssssssd",false,55.0);
Invoice inv2 = new Invoice("2", "1","dddddddddd",false,545.0);
ArrayList<Invoice> inv = new ArrayList<Invoice>();
inv.add(inv1);
inv.add(inv2);
return inv;
}
@RequestMapping("/{invoiceId}")
public boolean updateInvoiceStatus(@PathVariable("invoiceId") String invoiceId){
Invoice invoice = new Invoice("2", "1","dddddddddd",false,545.0);
invoice.setStatus(true);
return true;
}
@RequestMapping()
public List<Invoice> getUnPaidInvoices(){
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);
return inv;
}
@RequestMapping()
public List<Invoice> getPaidInvoices(){
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);
return inv;
}
}
......@@ -16,7 +16,7 @@ public class UserResource {
@RequestMapping("/{userId}")
public List<Invoice> getUnPaidInvoices(@PathVariable("userId") String userId){
Invoice inv1 = new Invoice("1", "1","ssssssd",true,55.0);
Invoice inv1 = new Invoice("1", "1","ssssssd",false,55.0);
Invoice inv2 = new Invoice("2", "1","dddddddddd",false,545.0);
System.out.println(userId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment