From f3b016aee992cdf4cedeb42a28570c60294492e4 Mon Sep 17 00:00:00 2001 From: BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr> Date: Mon, 20 Sep 2021 21:01:31 +0200 Subject: [PATCH] Simple RESTful API with test Item. --- gradle.properties | 4 + .../controller/ApiRetrieveInfoController.java | 27 ++++++ .../unistra/sil/erp/back/api/model/Item.java | 84 +++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 gradle.properties create mode 100644 src/main/java/fr/unistra/sil/erp/back/api/controller/ApiRetrieveInfoController.java create mode 100644 src/main/java/fr/unistra/sil/erp/back/api/model/Item.java diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..2637353 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +version=1.0 + +license=https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html +netbeans.license=cecill-b diff --git a/src/main/java/fr/unistra/sil/erp/back/api/controller/ApiRetrieveInfoController.java b/src/main/java/fr/unistra/sil/erp/back/api/controller/ApiRetrieveInfoController.java new file mode 100644 index 0000000..aa3e6e9 --- /dev/null +++ b/src/main/java/fr/unistra/sil/erp/back/api/controller/ApiRetrieveInfoController.java @@ -0,0 +1,27 @@ +/* + * CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B + * https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html + */ +package fr.unistra.sil.erp.back.api.controller; + +import fr.unistra.sil.erp.back.api.model.Item; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * REST controller for the item list. + * @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr> + */ +@RestController +public class ApiRetrieveInfoController { + + /** + * Returns an Item as a JSON response. + * @return an Item. + */ + @GetMapping("/erp-back/api/v1/retrieveInfo") + public Item retrieveInfo() + { + return new Item(1, "Test", 1.0, 0.5); + } +} diff --git a/src/main/java/fr/unistra/sil/erp/back/api/model/Item.java b/src/main/java/fr/unistra/sil/erp/back/api/model/Item.java new file mode 100644 index 0000000..3657fc4 --- /dev/null +++ b/src/main/java/fr/unistra/sil/erp/back/api/model/Item.java @@ -0,0 +1,84 @@ +/* + * CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B + * https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html + */ +package fr.unistra.sil.erp.back.api.model; + +/** + * Item description. + * @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr> + */ +public class Item { + + /** + * The product's reference number. + */ + private final int ref; + + /** + * The product's name. + */ + private final String name; + + /** + * The product's regular price. + */ + private final double price; + + /** + * The product's price for subscribers. + */ + private final double subscriberPrice; + + /** + * Class constructor. + * @param ref The item's reference number. + * @param name The item's name. + * @param price The item's price. + * @param subscriberPrice The item's price for subscribers. + */ + public Item(int ref, String name, double price, + double subscriberPrice) + { + this.ref = ref; + this.name = name; + this.price = price; + this.subscriberPrice = subscriberPrice; + } + + /** + * Returns the current item's reference number. + * @return the reference number. + */ + public int getRef() + { + return this.ref; + } + + /** + * Returns the current item's name. + * @return the name. + */ + public String getName() + { + return this.name; + } + + /** + * Returns the current item's price. + * @return the price. + */ + public double getPrice() + { + return this.price; + } + + /** + * Returns the current item's price for subscribers. + * @return the price for subscribers. + */ + public double getSubscriberPrice() + { + return this.subscriberPrice; + } +} -- GitLab