Skip to content
Snippets Groups Projects
Commit c24e40bc authored by Yokiza's avatar Yokiza
Browse files

Merge branch 'develop' into shippingOrder

parents e3717700 3f9a7362
No related branches found
No related tags found
4 merge requests!71Added invoices test data,!30Had to edit the server port in Application properties due to default port 8080...,!27Had to edit the server port in Application properties due to default port 8080...,!18Request for merging shipping order branch to develop
Showing
with 701 additions and 54 deletions
......@@ -62,7 +62,6 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
......
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
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);
}
}
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);
}
}
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;
}
}
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;
}
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;
}
}
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 + "]";
}
}
......@@ -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")
......
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;
}
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> {
}
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> {
}
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> {
}
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...
}
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);
}
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);
}
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> {
}
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
......@@ -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);
}
}
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment