Skip to content

Commit

Permalink
Implementation of set4 controller completed
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyhoa committed Oct 18, 2023
1 parent 837871d commit c00676e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import java.sql.Date;
import ca.mcgill.ecse.assetplus.application.AssetPlusApplication;
import ca.mcgill.ecse.assetplus.model.AssetPlus;
import ca.mcgill.ecse.assetplus.model.Guest;
import ca.mcgill.ecse.assetplus.model.MaintenanceTicket;
import ca.mcgill.ecse.assetplus.model.SpecificAsset;
import ca.mcgill.ecse.assetplus.model.User;

public class AssetPlusFeatureSet4Controller {
private static AssetPlus ap = AssetPlusApplication.getAssetPlus();

// assetNumber -1 means that no asset is specified
public static String addMaintenanceTicket(int id, Date raisedOnDate, String description, String email, int assetNumber) {
Guest g = Util.getGuest(email);
User g = Util.getUser(email);
if (g.equals(null)) {
return "User does not exists";
return "The ticket raiser does not exist";
}
MaintenanceTicket t = ap.addMaintenanceTicket(id, raisedOnDate, description, g);
t.setAsset(ap.getSpecificAsset(assetNumber));
Expand All @@ -23,13 +24,45 @@ public static String addMaintenanceTicket(int id, Date raisedOnDate, String desc
// newAssetNumber -1 means that no asset is specified
public static String updateMaintenanceTicket(int id, Date newRaisedOnDate, String newDescription,
String newEmail, int newAssetNumber) {
// Remove this exception when you implement this method
throw new UnsupportedOperationException("Not Implemented!");
MaintenanceTicket current = ap.getMaintenanceTicket(id);
if (current == null) {
return "";
}

current.setRaisedOnDate(newRaisedOnDate);

if (newDescription.isBlank()) {
return "Ticket description cannot be empty";
}

current.setDescription(newDescription);

User u = Util.getUser(newEmail);
if (u == null) {
return "Email does not match any guests";
}

SpecificAsset a;
if (newAssetNumber == 0) {
a = null;
} else {
a = ap.getSpecificAsset(newAssetNumber);
if (a == null) {
return "The asset does not exist";
}
}

current.setTicketRaiser(u);
current.setAsset(a);
return "";
}

public static void deleteMaintenanceTicket(int id) {
// Remove this exception when you implement this method
throw new UnsupportedOperationException("Not Implemented!");
MaintenanceTicket t = ap.getMaintenanceTicket(id);
if (t == null) {
return;
}
t.delete();
}

}
17 changes: 11 additions & 6 deletions src/main/java/ca/mcgill/ecse/assetplus/controller/Util.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package ca.mcgill.ecse.assetplus.controller;

import java.util.Collections;
import java.util.List;
import ca.mcgill.ecse.assetplus.application.AssetPlusApplication;
import ca.mcgill.ecse.assetplus.model.AssetPlus;
import ca.mcgill.ecse.assetplus.model.Guest;
import ca.mcgill.ecse.assetplus.model.User;

public class Util {
private static AssetPlus ap = AssetPlusApplication.getAssetPlus();

public static Guest getGuest(String email) {
List<Guest> guests = ap.getGuests();
for (Guest guest: guests) {
if (guest.getEmail().equals(email)) {
return guest;
public static User getUser(String email) {
List<User> allUsers = Collections.emptyList();
allUsers.addAll(ap.getGuests());
allUsers.addAll(ap.getEmployees());
allUsers.add(ap.getManager());

for (User u: allUsers) {
if (u.getEmail().equals(email)) {
return u;
}
}
return null;
Expand Down

0 comments on commit c00676e

Please sign in to comment.