diff --git a/pom.xml b/pom.xml index 312961d110e7e9d69773c6663c7f5b91f0194dd0..e82c115dcfc34e1e3cb1156fa435d96e3aa89628 100644 --- a/pom.xml +++ b/pom.xml @@ -56,13 +56,12 @@ <version>6.1.7.Final</version> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13.2</version> - <scope>test</scope> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13.2</version> + <scope>test</scope> </dependency> </dependencies> - <build> <plugins> <plugin> diff --git a/src/main/java/no/ntnu/queryeng/controller/ParcelController.java b/src/main/java/no/ntnu/queryeng/controller/ParcelController.java new file mode 100644 index 0000000000000000000000000000000000000000..69727aad26d69620abd6a77287c36b5483129784 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/controller/ParcelController.java @@ -0,0 +1,34 @@ +package no.ntnu.queryeng.controller; + +import no.ntnu.queryeng.service.ParcelService; +import org.springframework.graphql.data.method.annotation.Argument; +import org.springframework.graphql.data.method.annotation.QueryMapping; +import org.springframework.stereotype.Controller; + +/** + * This class takes use of GraphQL for making queries using the notation: @QueryMapping and @SchemaMapping + * //ToDo: Fill in a more complete Description of the class + * //TODO: Currently used odins documentation. + * //TODO: As soon as its sure what we are going to use of it, + * //TODO: the documentation will be replaced + * + * + * @author Joakim Røren Melum + * @version 0.1 + * @date 01.03.2023 + */ +@Controller +public class ParcelController { + /** + * Fetches the "type query" defined in resoruces/graphql/schema.graphqls in order to fetch the Parcel + * of a given id (an int), if found it returns the Parcel with the id matching int requested. + * Example: input 1, output (1, "Arrived") + * + * @param id the integer value of the parcel you wish to search for + * @return the parcel with the matching id + */ + @QueryMapping + public ParcelService ParcelById(@Argument int id) { + return ParcelService.getById(id); + } +} \ No newline at end of file diff --git a/src/main/java/no/ntnu/queryeng/controller/StatusController.java b/src/main/java/no/ntnu/queryeng/controller/StatusController.java index 687076142f91eb3dc6bfcdf9876746ad439ba015..9a8bd4617b76d731b535d804888a21e52df9124d 100644 --- a/src/main/java/no/ntnu/queryeng/controller/StatusController.java +++ b/src/main/java/no/ntnu/queryeng/controller/StatusController.java @@ -1,5 +1,9 @@ package no.ntnu.queryeng.controller; +import no.ntnu.queryeng.entity.Status; +import no.ntnu.queryeng.entity.Terminal; +import no.ntnu.queryeng.repository.StatusRepo; +import no.ntnu.queryeng.repository.TerminalRepo; import no.ntnu.queryeng.service.StatusService; import org.springframework.graphql.data.method.annotation.Argument; import org.springframework.graphql.data.method.annotation.QueryMapping; @@ -15,6 +19,12 @@ import org.springframework.stereotype.Controller; @Controller public class StatusController { + + private StatusRepo statusRepo; + + public StatusController(StatusRepo statusRepo) { + this.statusRepo = statusRepo; + } /** * Fetches the "type query" defined in resoruces/graphql/schema.graphqls in order to fetch the Status * of a given id (an int), if found it returns the status with the id matching int requested. @@ -24,7 +34,7 @@ public class StatusController { * @return the status with the matching id */ @QueryMapping - public StatusService statusById(@Argument int id) { - return StatusService.getById(id); + public Status statusById(@Argument int id) { + return statusRepo.getById(id); } } diff --git a/src/main/java/no/ntnu/queryeng/controller/TerminalController.java b/src/main/java/no/ntnu/queryeng/controller/TerminalController.java index d0267cdd0164611203b623ed0e5caa5dc6ae638f..5bf65b12c30224679a8c724e18a3ed51d10b9308 100644 --- a/src/main/java/no/ntnu/queryeng/controller/TerminalController.java +++ b/src/main/java/no/ntnu/queryeng/controller/TerminalController.java @@ -1,5 +1,7 @@ package no.ntnu.queryeng.controller; +import no.ntnu.queryeng.entity.Terminal; +import no.ntnu.queryeng.repository.TerminalRepo; import no.ntnu.queryeng.service.TerminalService; import org.springframework.graphql.data.method.annotation.Argument; import org.springframework.graphql.data.method.annotation.QueryMapping; @@ -11,11 +13,18 @@ import org.springframework.stereotype.Controller; * //ToDo: Fill in a more complete Description of the class * * @author odin - * @version 1.0.0 + * @version 1.1.0 */ @Controller public class TerminalController { + + private TerminalRepo terminalRepo; + + public TerminalController(TerminalRepo terminalRepo) { + this.terminalRepo = terminalRepo; + } + /** * Fetches the "type query" defined in resoruces/graphql/schema.graphqls in order to fetch the Terminal * of a given id (an int), if found it returns the terminal with the id matching int requested. @@ -25,7 +34,12 @@ public class TerminalController { * @return the terminal with the matching id */ @QueryMapping - public TerminalService terminalById(@Argument int id) { - return TerminalService.getById(id); + public Terminal terminalById(@Argument int id) { + return terminalRepo.getById(id); + } + + @QueryMapping + public Terminal terminalByName(@Argument String name) { + return terminalRepo.findTerminalByName(name); } } diff --git a/src/main/java/no/ntnu/queryeng/entity/AdditionalService.java b/src/main/java/no/ntnu/queryeng/entity/AdditionalService.java new file mode 100644 index 0000000000000000000000000000000000000000..45f8d86ff0fa5ffe8160a62a033b6a1ffa1d6bfc --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/entity/AdditionalService.java @@ -0,0 +1,93 @@ +package no.ntnu.queryeng.entity; + +import jakarta.persistence.*; + + +/** + * Class represents additional service that can be added to a shipping order. + * <p> + * author aleksander + * version 1.0-SNAPSHOT + */ + +@Entity +@Table(name = "additional_service") +public class AdditionalService { + + // unique id of the additional service + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + // the name of the additional service + @Column(name = "additional_service_name") + private String additionalServiceName; + + // description of the additional service + @Column(name = "description") + private String description; + + // the cost of the service + @Column(name = "cost") + private double cost; + + /** + * No argument constructor for additional service + */ + public AdditionalService() { + + } + + /** + * Constructs an instance of this class + * + * @param additionalServiceName the name of the additional service + * @param description description of additional service + * @param cost cost of the additional service + */ + public AdditionalService(String additionalServiceName, String description, double cost) { + this.additionalServiceName = additionalServiceName; + this.description = description; + this.cost = cost; + } + + // ------------------ Getter methods --------------------- + + + public int getId() { + return id; + } + + public String getAdditionalServiceName() { + return additionalServiceName; + } + + public String getDescription() { + return description; + } + + public double getCost() { + return cost; + } + + // ----------------- Setter methods ------------------- + + + public void setId(int id) { + if (id >= 0) { + this.id = id; + } + } + + public void setAdditionalServiceName(String additionalServiceName) { + this.additionalServiceName = additionalServiceName; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setCost(double cost) { + this.cost = cost; + } +} diff --git a/src/main/java/no/ntnu/queryeng/entity/Customer.java b/src/main/java/no/ntnu/queryeng/entity/Customer.java new file mode 100644 index 0000000000000000000000000000000000000000..5d081ea1dce779ff317c55e5dd6cf513298c5c20 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/entity/Customer.java @@ -0,0 +1,44 @@ +package no.ntnu.queryeng.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +/** + * Represents a customer table in the database. + */ +@AllArgsConstructor +@NoArgsConstructor +@Entity +@Table(name = "customer") +public class Customer { + // Unique id of the customer. + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + // Firstname of the customer + @Column(name = "first_name") + private String firstName; + + // Lastname of the customer + @Column(name = "last_name") + private String lastName; + + // Address of the customer + private String address; + + // Postal number of the customer + @Column(name = "postal_number") + private String postalNumber; + + // Postal code of the customer + @Column(name = "postal_code") + private String postalCode; + + // Mobile number of the customer + private String mobile; + + // email address of the customer + private String email; +} diff --git a/src/main/java/no/ntnu/queryeng/entity/Invoice.java b/src/main/java/no/ntnu/queryeng/entity/Invoice.java new file mode 100644 index 0000000000000000000000000000000000000000..54451ff0690d14d605a74dcf05d093fb81f77812 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/entity/Invoice.java @@ -0,0 +1,81 @@ +package no.ntnu.queryeng.entity; + +import jakarta.persistence.*; +/** + * Class represents a simplified invoice in the system. + * + * @author aleksander + * @version 1.0-SNAPSHOT + */ + +@Entity +@Table(name = "invoice") +public class Invoice { + // int id, int shipping_order_id, int invoice_payer_type_id, int third_party_id, int customer_id + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + @Column(name = "shipping_order_id") + private int shippingOrderId; + @Column(name = "invoice_payer_type_id") + private int invoicePayerTypeId; + @Column(name = "third_party_id") + private int thirdPartyId; + @Column(name = "customer_id") + private int customerId; + + /** + * No argument constructor + */ + public Invoice() { + + } + + // --------------- Getter methods ----------------- + + + public int getId() { + return id; + } + + public int getShippingOrderId() { + return shippingOrderId; + } + + public int getInvoicePayerTypeId() { + return invoicePayerTypeId; + } + + public int getThirdPartyId() { + return thirdPartyId; + } + + public int getCustomerId() { + return customerId; + } + + // ----------------- Setter methods ------------------- + + + public void setId(int id) { + if (id >= 0) { + this.id = id; + } + } + + public void setShippingOrderId(int shippingOrderId) { + this.shippingOrderId = shippingOrderId; + } + + public void setInvoicePayerTypeId(int invoicePayerTypeId) { + this.invoicePayerTypeId = invoicePayerTypeId; + } + + public void setThirdPartyId(int thirdPartyId) { + this.thirdPartyId = thirdPartyId; + } + + public void setCustomerId(int customerId) { + this.customerId = customerId; + } +} diff --git a/src/main/java/no/ntnu/queryeng/entity/Parcel.java b/src/main/java/no/ntnu/queryeng/entity/Parcel.java new file mode 100644 index 0000000000000000000000000000000000000000..6833f614359ab85b86c1b38d58fe7c969230a812 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/entity/Parcel.java @@ -0,0 +1,139 @@ +package no.ntnu.queryeng.entity; + +import jakarta.persistence.*; +import org.springframework.data.annotation.Id; + +/** + * Represents a parcel-object in the query engine application. + * + * @author Joakim Røren Melum + * @version 0.1 + * @date 01.03.2023 + */ +@Entity +@Table(name = "parcel") +public class Parcel { + + /*** + * The ID of the parcel. + */ + @jakarta.persistence.Id + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "parcel_id") + private long parcel_id; + + /** + * The weight of the parcel. + */ + @Column(name = "parcel_weight") + private double parcel_weight; + + /** + * The status of the parcel. + */ + @Column(name = "parcel_status") + private int parcel_status; + + /** + * The Tracking Number of the parcel. + */ + @Column(name = "parcel_tracking_number") + private long parcel_tracking_number; + + /** + * Creates an instance of a parcel. + * + * @param parcel_id of the parcel. + * @param parcel_tracking_number of the parcel. + * @param parcel_status of the parcel. + * @param parcel_tracking_number of the parcel. + */ + public Parcel(long parcel_id, double parcel_weight, int parcel_status, long parcel_tracking_number) { + this.parcel_id = parcel_id; + this.parcel_weight = parcel_weight; + this.parcel_status = parcel_status; + this.parcel_tracking_number = parcel_tracking_number; + } + + /** + * Creates an instance of a parcel. + * Intentionally left blank. + */ + public Parcel() { + } + + /** + * @return the ID of the parcel. + */ + public long getId() { + return parcel_id; + } + + /** + * Sets the ID of the parcel. + * + * @param parcel_id of the parcel. + */ + public void setId(long parcel_id) { + this.parcel_id = parcel_id; + } + + /** + * @return the parcel_tracking_number of the parcel. + */ + public double getWeight() { + return parcel_weight; + } + + /** + * Sets the parcel_tracking_number of the parcel. + * + * @param parcel_weight of the parcel. + */ + public void setWeight(double parcel_weight) { + this.parcel_weight = parcel_weight; + } + + /** + * @return the parcel_status of the parcel. + */ + public int getStatus() { + return parcel_status; + } + + /** + * Sets the parcel_status of the parcel. + * + * @param parcel_status of the parcel. + */ + public void setStatus(int parcel_status) { + // There are 4 types of parcel_statuses. Therefore, it cannot be less than 0 or more than 3 + if (parcel_status > 0 && parcel_status < 3){ + this.parcel_status = parcel_status; + } + + } + + /** + * @return the tracking number of the parcel. + */ + public long getTrackingNumber() { + return parcel_tracking_number; + } + + /** + * Sets the tracking number of the parcel + * + * @param parcel_tracking_number of the parcel + */ + public void setTrackingNumber(long parcel_tracking_number) { + this.parcel_tracking_number = parcel_tracking_number; + } + + + @Override + public String toString() { + return "Parcel [parcel_id=" + parcel_id + ", parcel_weight=" + parcel_weight + ", parcel_status=" + parcel_status + ", parcel_tracking_number=" + parcel_tracking_number + "]"; + } +} diff --git a/src/main/java/no/ntnu/queryeng/entity/Status.java b/src/main/java/no/ntnu/queryeng/entity/Status.java index 5de78ba1c756144064fa7b64bb00abc27e8a53e0..6b6ecba0943c1672c705f1eb2d22498be2930f76 100644 --- a/src/main/java/no/ntnu/queryeng/entity/Status.java +++ b/src/main/java/no/ntnu/queryeng/entity/Status.java @@ -5,6 +5,9 @@ import jakarta.persistence.*; /** * This class represents the Constructor of a Status entity. * It's content features the different attributes the Status table has in the DB + * + * @author odin + * @version 1.0.0 */ @Entity @Table (name = "Status") diff --git a/src/main/java/no/ntnu/queryeng/entity/ThirdParty.java b/src/main/java/no/ntnu/queryeng/entity/ThirdParty.java new file mode 100644 index 0000000000000000000000000000000000000000..4fd377422202e87939d93f40ed4fa48c4dd27d0e --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/entity/ThirdParty.java @@ -0,0 +1,41 @@ +package no.ntnu.queryeng.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +/** + * Represents a third party table in the database. + * Third party refers to the payers other than sender and receiver + */ +@AllArgsConstructor +@NoArgsConstructor +@Entity +@Table(name = "third_party") +public class ThirdParty { + + // Unique id of the third party + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + // Name of the third party + private String name; + + // Address of the third party + private String address; + + // Postal number of the third party + @Column(name = "postal_number") + private String postalNumber; + + // Postal code of the third party + @Column(name = "postal_code") + private String postalCode; + + // Mobile number of the third party + private String mobile; + + // Email address of the third party + private String email; +} diff --git a/src/main/java/no/ntnu/queryeng/repository/AdditionalServiceRepo.java b/src/main/java/no/ntnu/queryeng/repository/AdditionalServiceRepo.java new file mode 100644 index 0000000000000000000000000000000000000000..3768809a268005e10d7de5cbc4b001aabcd1077d --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/repository/AdditionalServiceRepo.java @@ -0,0 +1,14 @@ +package no.ntnu.queryeng.repository; + +import no.ntnu.queryeng.entity.AdditionalService; +import org.springframework.data.repository.CrudRepository; + +/** + * Repository class for additional service + * + * @author aleksander + * @version 1.0-SNAPSHOT + */ + +public interface AdditionalServiceRepo extends CrudRepository<AdditionalService, Integer> { +} diff --git a/src/main/java/no/ntnu/queryeng/repository/CustomerRepo.java b/src/main/java/no/ntnu/queryeng/repository/CustomerRepo.java new file mode 100644 index 0000000000000000000000000000000000000000..8e25002b20c3e7abb8a1f5bedbbf9cfe00ae22e1 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/repository/CustomerRepo.java @@ -0,0 +1,10 @@ +package no.ntnu.queryeng.repository; + +import no.ntnu.queryeng.entity.Customer; +import org.springframework.data.repository.CrudRepository; + +/** + * Represents customer repository. + */ +public interface CustomerRepo extends CrudRepository<Customer, Integer> { +} diff --git a/src/main/java/no/ntnu/queryeng/repository/InvoiceRepo.java b/src/main/java/no/ntnu/queryeng/repository/InvoiceRepo.java new file mode 100644 index 0000000000000000000000000000000000000000..8b30b929c6872b08d5c16fb54e1ebf37f7673726 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/repository/InvoiceRepo.java @@ -0,0 +1,14 @@ +package no.ntnu.queryeng.repository; + +import no.ntnu.queryeng.entity.Invoice; +import org.springframework.data.repository.CrudRepository; + +/** + * Reposotiry class for invoice. + * + * @author aleksander + * @version 1.0-SNAPSHOT + */ +public interface InvoiceRepo extends CrudRepository<Invoice, Integer> { +} + diff --git a/src/main/java/no/ntnu/queryeng/repository/ParcelRepository.java b/src/main/java/no/ntnu/queryeng/repository/ParcelRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..9a36bfd6a37d7fb268be7c63d2f79b8a8e49348d --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/repository/ParcelRepository.java @@ -0,0 +1,16 @@ +package no.ntnu.queryeng.repository; + +import no.ntnu.queryeng.entity.Parcel; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +/** + * Represents a parcel repository. + * @author Joakim Røren Melum + * @version 0.1 + * @date 01.03.2023 + */ +@Repository +public interface ParcelRepository extends CrudRepository<Parcel, Long> { + // Left empty intentionally... +} diff --git a/src/main/java/no/ntnu/queryeng/repository/StatusRepo.java b/src/main/java/no/ntnu/queryeng/repository/StatusRepo.java index b7ec93d9059ac92cdec9cf23527bd07e0c7fa095..7c4f62d4c4d5d98a437a52adee6c903d15325d31 100644 --- a/src/main/java/no/ntnu/queryeng/repository/StatusRepo.java +++ b/src/main/java/no/ntnu/queryeng/repository/StatusRepo.java @@ -1,11 +1,21 @@ package no.ntnu.queryeng.repository; import no.ntnu.queryeng.entity.Status; +import no.ntnu.queryeng.entity.Terminal; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; /** - * Represents the Status Repository + * Represents the Status Repository, adapted for GraphQL + * In the repository classes we'll define queries to be made. this class has a connection to the + * StatusController class in such a way that controller fetches methods from this interface + * + * @author odin + * @version 1.0.0 */ public interface StatusRepo extends CrudRepository<Status, Integer>{ // Left empty intentionally... + + @Query(value = "SELECT * FROM Status WHERE id = ?1", nativeQuery = true) + Status getById(int id); } diff --git a/src/main/java/no/ntnu/queryeng/repository/TerminalRepo.java b/src/main/java/no/ntnu/queryeng/repository/TerminalRepo.java index 3dbd46bfd3b9e473ad2e0bb177917def6e8bab2b..3dfad5c5137f07dcbbde2894ec0e066116ba616f 100644 --- a/src/main/java/no/ntnu/queryeng/repository/TerminalRepo.java +++ b/src/main/java/no/ntnu/queryeng/repository/TerminalRepo.java @@ -1,11 +1,41 @@ package no.ntnu.queryeng.repository; import no.ntnu.queryeng.entity.Terminal; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; /** - * Represents the Terminal Repository + * Represents the Terminal Repository, adapted for GraphQL + * In the repository classes we'll define queries to be made. this class has a connection to the + * TerminalController class in such a way that controller fetches methods from this interface + * + * @author odin + * @version 1.1.0 */ public interface TerminalRepo extends CrudRepository<Terminal, Integer> { // Left empty intentionally... + + /** + * QUERY fetching the name of a terminal by its name. The syntax + * 'name = ?1' where the question-mark defines the String to be searched for + * 1 is the first parameter of the method + * ? defines what to be searched for + * + * @param name of the terminal you wish to search for + * @return the first terminal with matching name + */ + @Query(value = "SELECT * FROM Terminal WHERE name = ?1", nativeQuery = true) + Terminal findTerminalByName(String name); + + /** + * QUERY fetching the id of a terminal by the terminals id number. The syntax + * 'id = ?1' where the question mark defines the int id to be searched for. + * 1 is the first parameter of the method + * ? defines what to be searched for + * + * @param id of the terminal you wish to search for + * @return the first terminal with matching id + */ + @Query(value = "SELECT * FROM Terminal WHERE id = ?1", nativeQuery = true) + Terminal getById(int id); } diff --git a/src/main/java/no/ntnu/queryeng/repository/ThirdPartyRepo.java b/src/main/java/no/ntnu/queryeng/repository/ThirdPartyRepo.java new file mode 100644 index 0000000000000000000000000000000000000000..cb7eafe883546ffdfa7d55b9837cf311bd9eddc6 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/repository/ThirdPartyRepo.java @@ -0,0 +1,10 @@ +package no.ntnu.queryeng.repository; + +import no.ntnu.queryeng.entity.ThirdParty; +import org.springframework.data.repository.CrudRepository; + +/** + * Represents a third party repo. + */ +public interface ThirdPartyRepo extends CrudRepository<ThirdParty, Integer> { +} diff --git a/src/main/java/no/ntnu/queryeng/service/ParcelService.java b/src/main/java/no/ntnu/queryeng/service/ParcelService.java new file mode 100644 index 0000000000000000000000000000000000000000..638769808ea246fdaed30661085ec8340c3b2e82 --- /dev/null +++ b/src/main/java/no/ntnu/queryeng/service/ParcelService.java @@ -0,0 +1,122 @@ +package no.ntnu.queryeng.service; + +import java.util.Arrays; +import java.util.List; + +/** + * Represents a service for the parcel. + * + * * //ToDo: Fill in a more complete Description of the class + * * //TODO: Currently used some of odins documentation. + * * //TODO: As soon as its sure what we are going to use of it, + * * //TODO: the documentation will be replaced + * + * @author Joakim Røren Melum + * @version 0.1 + * @date 01.03.2023 + */ +public record ParcelService(long id, double weight, int status, long trackingNumber) { + + + + // Example on GraphQL: + // https://www.baeldung.com/java-call-graphql-service + // Code fetched from: + // https://spring.io/guides/gs/graphql-server/ + + /** + * Generates a Arraylist filled with predetermined dummy data + */ + private static List<ParcelService> parcels = Arrays.asList( + new ParcelService(1, 1.1, 1, 12345678), + new ParcelService(2, 2.2, 2, 2345678) + ); + + /** + * Business logic for fetching the id of a parcel using a lambda stream + * + * @param id is the unique int value for the parcel + * @return if <code>TRUE</code> it returns the list of parcels with the matching id + * else <code>FALSE</code> it returns null. + */ + public static ParcelService getById(int id) { + return parcels.stream() + .filter(parcels -> parcels.id() == parcels.id) + .findFirst() + .orElse(null); + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + +// +// +// +// +// /** +// * @return all the parcels stored in the register. +// */ +// public List<Parcel> getAllParcels(){ +// List<Parcel> parcels = new ArrayList<>(); +// parcelRepository.findAll().forEach(parcels::add); +// return new ArrayList<>((Collection) parcelRepository.findAll()); +// } +// +// +// /** +// * Return parcel with specific ID. +// * @param id of the parcel to return. +// * @return parcel with specific ID. +// */ +// public Parcel getParcel(long id) { +// return parcelRepository.findById(id).get(); +// } +// +// /** +// * Add a parcel to the register. +// * @param parcel to be added to the register. +// */ +// public void addParcel(Parcel parcel) { +// parcelRepository.save(parcel); +// } +// +// /** +// * Update the information of a specific parcel. +// * @param id of the parcel to be updated. +// * @param parcel to be updated. +// */ +// public void updateParcel(long id, Parcel parcel) { +// parcelRepository.save(parcel); +// } +// +// /** +// * Delete a specific parcel based on ID. +// * @param id of the parcel to be deleted. +// */ +// public void deleteParcel(long id) { +// parcelRepository.deleteById(id); +// } \ No newline at end of file diff --git a/src/main/java/no/ntnu/queryeng/service/StatusService.java b/src/main/java/no/ntnu/queryeng/service/StatusService.java index 8e6a184be3e38f5eb884d3a71173f26db1dff582..b18f70061b5c25a88cdde7bb14a9cea2ad0d8944 100644 --- a/src/main/java/no/ntnu/queryeng/service/StatusService.java +++ b/src/main/java/no/ntnu/queryeng/service/StatusService.java @@ -7,6 +7,8 @@ import java.util.List; * Represents a service to be used for the Status. Current Service is read only and does * not provide adding new statuses into the repository. * + * //ToDo: Class is redundant for the moment until further developing for the project + * * @author odin * @version 1.0.0 */ @@ -18,25 +20,4 @@ public record StatusService(int id, String status) { // Code fetched from: // https://spring.io/guides/gs/graphql-server/ - /** - * Generates a Arraylist filled with predetermined dummy data - */ - private static List<StatusService> statuses = Arrays.asList( - new StatusService(1, "Terminal-1"), - new StatusService(2, "Terminal-2") - ); - - /** - * Business logic for fetching the id of a status using a lambda stream - * - * @param id is the unique int value for the status - * @return if <code>TRUE</code> it returns the list of statuses with the matching id - * else <code>FALSE</code> it returns null. - */ - public static StatusService getById(int id) { - return statuses.stream() - .filter(statuses -> statuses.id() == statuses.id) - .findFirst() - .orElse(null); - } } diff --git a/src/main/java/no/ntnu/queryeng/service/TerminalService.java b/src/main/java/no/ntnu/queryeng/service/TerminalService.java index 347b2b7423f3f314d0317caca0cbb93c5f85b5df..bfb89f360f4a283fd2453dc6f47bd1a57f0af42a 100644 --- a/src/main/java/no/ntnu/queryeng/service/TerminalService.java +++ b/src/main/java/no/ntnu/queryeng/service/TerminalService.java @@ -6,6 +6,9 @@ import java.util.List; /** * Represents a service to be used for the Terminal. Current Service is read only and does * not provide adding new terminals into the repository. + * + * //ToDo: Class is redundant for the moment until further developing for the project + * * @author odin * @version 1.0.0 */ @@ -17,27 +20,6 @@ public record TerminalService(int id, String name, String address, int cost) { // Code fetched from: // https://spring.io/guides/gs/graphql-server/ - /** - * Generates a Arraylist filled with predetermined dummy data - */ - private static List<TerminalService> terminals = Arrays.asList( - new TerminalService(1, "Terminal-1", "Ørsta", 20), - new TerminalService(2, "Terminal-2", "Volda", 30) - ); - - /** - * Business logic for fetching the id of a terminal using a lambda stream - * - * @param id is the unique int value for the terminal - * @return if <code>TRUE</code> it returns the list of terminals with the matching id - * else <code>FALSE</code> it returns null. - */ - public static TerminalService getById(int id) { - return terminals.stream() - .filter(terminals -> terminals.id() == terminals.id) - .findFirst() - .orElse(null); - } } diff --git a/src/main/resources/graphql/schema.graphqls b/src/main/resources/graphql/schema.graphqls index a700e0df4908400c095efc10202700ce43154837..390940d6e51038df10028cbe4f9a8ac36ed97efb 100644 --- a/src/main/resources/graphql/schema.graphqls +++ b/src/main/resources/graphql/schema.graphqls @@ -3,22 +3,7 @@ # localhost:{insert port nr here}/graphiql type Query { - terminalById(id: ID): Terminal - statusById(id: ID): Status -} - -type Terminal { - id: ID - name: String - address: String - cost: Int -} - -type Status { - id: ID - status: String -} - -schema { - query: Query -} + # Left empty on purpose! + # This file acts a like a super() method where Query's of the same type + # extends from this file, sort of like an interface if you wish. +} \ No newline at end of file diff --git a/src/main/resources/graphql/status.graphqls b/src/main/resources/graphql/status.graphqls new file mode 100644 index 0000000000000000000000000000000000000000..84cddf6127d7d9b7ea816c4cf27753b2321a51fe --- /dev/null +++ b/src/main/resources/graphql/status.graphqls @@ -0,0 +1,8 @@ +extend type Query { + statusById(id: ID): Status +} + +type Status { + id: ID + status: String +} \ No newline at end of file diff --git a/src/main/resources/graphql/terminal.graphqls b/src/main/resources/graphql/terminal.graphqls new file mode 100644 index 0000000000000000000000000000000000000000..bd0932e115ee228d452c3778e416c8d124b9baab --- /dev/null +++ b/src/main/resources/graphql/terminal.graphqls @@ -0,0 +1,11 @@ +extend type Query { + terminalById(id: ID): Terminal + terminalByName(name: String): Terminal +} + +type Terminal { + id: ID + name: String + address: String + cost: Int +} \ No newline at end of file diff --git a/src/test/java/no/ntnu/queryeng/entity/AdditionalServiceTest.java b/src/test/java/no/ntnu/queryeng/entity/AdditionalServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6853c37370895eb648d90a49eeeb9a3c45c23be0 --- /dev/null +++ b/src/test/java/no/ntnu/queryeng/entity/AdditionalServiceTest.java @@ -0,0 +1,63 @@ +package no.ntnu.queryeng.entity; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Class for unit testing of Additional Service + * + * @author aleksander + * @version 1.0-SNAPSHOT + */ +public class AdditionalServiceTest { + + AdditionalService addSer = new AdditionalService("change address", "additional service for changing the address", 10.0); + + // ======================= POSITIVE TESTS ============================== + + /** + * Tests that name of the additional service is correct - positive test. + * + */ + @Test + @DisplayName("testing name of add. service - positive") + void additionalServiceNameIsCorrectTest() { + assertEquals("change address", addSer.getAdditionalServiceName()); + } + + /** + * Tests that description is correct - positive test + */ + @Test + @DisplayName("testing description of add. service - positive") + void additionalServiceDescriptionIsCorrectTest() { + assertEquals("additional service for changing the address", addSer.getDescription()); + } + + /** + * Tests that cost of additional service is correct - positive test. + */ + @Test + @DisplayName("testing cost is correct - positive") + void additionalServiceCostIsCorrectTest() { + assertEquals(10.0, addSer.getCost()); + } + + // ======================= NEGATIVE TESTS ============================== + + /** + * Testing that negative id values in test fail - negative test. + */ + @Test + @DisplayName("checking that negative id fails - negative test") + void additionalServiceIdIsIncorrectTest() { + addSer.setId(-1); + assertTrue(addSer.getId() != -1); + } + + + +} diff --git a/src/test/java/no/ntnu/queryeng/entity/ParcelTest.java b/src/test/java/no/ntnu/queryeng/entity/ParcelTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f407c91ba35732e31356e6c7f9db6db2dadb6edd --- /dev/null +++ b/src/test/java/no/ntnu/queryeng/entity/ParcelTest.java @@ -0,0 +1,107 @@ +package no.ntnu.queryeng.entity; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Class for testing if the Parcel class acts like it is supposed to. + */ +class ParcelTest { + Parcel parcel1 = new Parcel(1, 1.1, 1, 12345678); + + /** + * Checks if getId() Returns the expected value. + */ + @Test + @DisplayName("Test Get ID") + void getId() { + assertEquals(1,parcel1.getId()); + } + + /** + * Checks if setId() sets the expected value. + */ + @Test + @DisplayName("Test Set ID") + void setId() { + parcel1.setId(2); + assertEquals(2, parcel1.getId()); + } + + /** + * Checks if getWeight() Returns the expected value. + */ + @Test + @DisplayName("Test Get Weight") + void getWeight() { + assertEquals(1.1, parcel1.getWeight()); + } + + /** + * Checks if setWeight() sets the expected value. + */ + @Test + @DisplayName("Test Set Weight") + void setWeight() { + parcel1.setWeight(1.2); + assertEquals(1.2, parcel1.getWeight()); + } + + /** + * Checks if getStatus() Returns the expected value. + */ + @Test + @DisplayName("Test Get Status") + void getStatus() { + assertEquals(1, parcel1.getStatus()); + } + + /** + * Checks if setStatus() sets the expected value. + */ + @Test + @DisplayName("Test Set Status") + void setStatus() { + parcel1.setStatus(2); + assertEquals(2, parcel1.getStatus()); + } + + /** + * Checks if getTrackingNumber() Returns the expected value. + */ + @Test + @DisplayName("Test Get TrackingNumber") + void getTrackingNumber() { + assertEquals(12345678, parcel1.getTrackingNumber()); + } + + /** + * Checks if setTrackingNumber() sets the expected value. + */ + @Test + @DisplayName("Test Set TrackingNumber") + void setTrackingNumber() { + parcel1.setTrackingNumber(123456789); + assertEquals(123456789, parcel1.getTrackingNumber()); + } + + /** + * Checks if toString() Returns the expected value. + */ + @Test + @DisplayName("Test toString") + void testToString() { + String toString = "Parcel [parcel_id=" + 1 + + ", parcel_weight=" + 1.1 + + ", parcel_status=" + 1 + + ", parcel_tracking_number=" + 12345678 + "]"; + if (parcel1.toString() != null){ + assertEquals(toString, parcel1.toString()); + } else { + fail(); + } + } + +} \ No newline at end of file