You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.7 KiB
89 lines
2.7 KiB
package cmpt213.assignment4.packagedeliveries.webappserver.controllers;
|
|
|
|
import cmpt213.assignment4.packagedeliveries.webappserver.control.PackageManager;
|
|
import cmpt213.assignment4.packagedeliveries.webappserver.model.PackageInfo;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@RestController
|
|
public class PackageController {
|
|
@GetMapping("/ping")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public String ping(){
|
|
return "system is up";
|
|
}
|
|
|
|
PackageManager manager=PackageManager.getInstance();
|
|
@GetMapping("/listAll")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public String getAllPackages(){
|
|
return manager.getAllPackages();
|
|
}
|
|
|
|
@GetMapping("/listOverduePackage")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public String getOverduePackages() {
|
|
return manager.overDuePackages();
|
|
}
|
|
|
|
@GetMapping("/listUpcomingPackage")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public String getUpcomingPackages() {
|
|
return manager.upcomingPackages();
|
|
}
|
|
|
|
@PostMapping("/addBook")
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public String addBook(@RequestBody String bookString){
|
|
System.out.println(bookString+"----------------->bookString");
|
|
//bookString = bookString.trim();
|
|
PackageInfo p=manager.deserializePackage(bookString);
|
|
System.out.println(p + " addBook p");
|
|
System.out.println(p.getType() + " package type");
|
|
manager.addPackage(p);
|
|
return manager.getAllPackages();
|
|
}
|
|
|
|
@PostMapping("/addPerishable")
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public String addPerishable(@RequestBody String perishableString){
|
|
PackageInfo p=manager.deserializePackage(perishableString);
|
|
manager.addPackage(p);
|
|
return manager.getAllPackages();
|
|
}
|
|
|
|
@PostMapping("/addElectronic")
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public String addElectronic(@RequestBody String electronicString){
|
|
PackageInfo p=manager.deserializePackage(electronicString);
|
|
manager.addPackage(p);
|
|
return manager.getAllPackages();
|
|
}
|
|
|
|
@PostMapping("/removePackage")
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public String removePackage(@RequestBody String pkg) {
|
|
PackageInfo p = manager.deserializePackage(pkg);
|
|
manager.removePackage(p);
|
|
return manager.getAllPackages();
|
|
}
|
|
|
|
@PostMapping("/markPackageAsDelivered")
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public String markPackageAsDelivered(@RequestBody String pkg) {
|
|
PackageInfo p = manager.deserializePackage(pkg);
|
|
manager.setDelivered(p);
|
|
return manager.getAllPackages();
|
|
}
|
|
|
|
@GetMapping("/exit")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public void savePackages() {
|
|
manager.save();
|
|
}
|
|
|
|
}
|
|
|