Skip to content
Snippets Groups Projects
Commit 1bc5555f authored by BEAUVAIS ANTOINE's avatar BEAUVAIS ANTOINE
Browse files

Merge branch 'develop' into 'master'

Merge 'develop' changes into 'master'.

See merge request !1
parents 47acf3ea daf3dfed
Branches
1 merge request!1Merge 'develop' changes into 'master'.
Showing
with 353 additions and 49 deletions
DROP TABLE IF EXISTS stocks;
DROP TABLE IF EXISTS registry;
DROP TABLE IF EXISTS transaction_types;
DROP TABLE IF EXISTS accounts;
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS categories;
......@@ -13,23 +15,37 @@ CREATE TABLE items (
name TEXT NOT NULL,
price REAL NOT NULL,
subscriberPrice REAL NOT NULL,
category INTEGER NOT NULL,
FOREIGN KEY (category) REFERENCES categories (id)
category INTEGER NOT NULL,
FOREIGN KEY (category) REFERENCES categories (id)
);
CREATE TABLE transaction_types (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
name TEXT NOT NULL
);
CREATE TABLE accounts (
id INTEGER PRIMARY KEY,
num INTEGER NOT NULL,
name TEXT NOT NULL
);
CREATE TABLE registry (
id INTEGER PRIMARY KEY,
dt INTEGER NOT NULL,
type INTEGER NOT NULL,
description TEXT NOT NULL,
debit REAL,
credit REAL,
remarks TEXT
dt INTEGER NOT NULL,
type INTEGER NOT NULL,
account_id INTEGER NOT NULL,
debit REAL,
credit REAL,
remarks TEXT,
FOREIGN KEY (account_id) REFERENCES accounts (id)
);
CREATE TABLE stocks (
id INTEGER PRIMARY KEY,
item INTEGER NOT NULL,
quantity INTEGER NOT NULL,
FOREIGN KEY (item) REFERENCES items (ref)
);
INSERT INTO categories (id, name)
......@@ -46,16 +62,32 @@ INSERT INTO transaction_types (id, name)
(2, "REGLEMENT"),
(3, "VENTE"),
(4, "ENCAISSEMENT");
INSERT INTO registry (id, dt, type, description, debit, credit, remarks)
VALUES (1, datetime("2021-09-21 01:00:00"), 4, "101 Capital", null, 500.0, null),
(2, datetime("2021-09-21 01:30:00"), 4, "512 Banque", 500.0, null, null),
(3, datetime("2021-09-21 02:00:00"), 1, "601 Achat", 152.0, null, "Facture d'achat"),
(4, datetime("2021-09-21 02:30:00"), 1, "401 Fournisseur", null, 152.0, "Facture Achat = dette au fournisseur"),
(5, datetime("2021-09-21 03:00:00"), 2, "401 Fournisseur", 152.0, null, "Règlement de la facture d'achat"),
(6, datetime("2021-09-21 03:30:00"), 2, "512 Banque", null, 152.0, "Règlement de la facture d'achat"),
(7, datetime("2021-09-21 04:00:00"), 3, "706 Vente", null, 60.0, "Vente"),
(8, datetime("2021-09-21 04:30:00"), 3, "445 TVA Collectée", null, 12.0, null),
(9, datetime("2021-09-21 05:00:00"), 3, "411 Client", 72.0, null, "Facture vente = Dette client"),
(10, datetime("2021-09-21 05:30:00"), 4, "411 Client", null, 72.0, "Encaissement de l'argent"),
(11, datetime("2021-09-21 06:00:00"), 4, "512 Banque", 72.0, null, "= La dette du client est soldée");
\ No newline at end of file
INSERT INTO accounts (id, num, name)
VALUES(1, 101, "Capital"),
(2, 512, "Banque"),
(3, 601, "Achat"),
(4, 401, "Fournisseur"),
(5, 706, "Vente"),
(6, 445, "TVA Collectée"),
(7, 411, "Client");
INSERT INTO registry (id, dt, type, account_id, debit, credit, remarks)
VALUES (1, datetime("2021-09-21 01:00:00"), 4, 1, null, 500.0, null),
(2, datetime("2021-09-21 01:30:00"), 4, 2, 500.0, null, null),
(3, datetime("2021-09-21 02:00:00"), 1, 3, 152.0, null, "Facture d'achat"),
(4, datetime("2021-09-21 02:30:00"), 1, 4, null, 152.0, "Facture Achat = dette au fournisseur"),
(5, datetime("2021-09-21 03:00:00"), 2, 4, 152.0, null, "Règlement de la facture d'achat"),
(6, datetime("2021-09-21 03:30:00"), 2, 2, null, 152.0, "Règlement de la facture d'achat"),
(7, datetime("2021-09-21 04:00:00"), 3, 5, null, 60.0, "Vente"),
(8, datetime("2021-09-21 04:30:00"), 3, 6, null, 12.0, null),
(9, datetime("2021-09-21 05:00:00"), 3, 7, 72.0, null, "Facture vente = Dette client"),
(10, datetime("2021-09-21 05:30:00"), 4, 7, null, 72.0, "Encaissement de l'argent"),
(11, datetime("2021-09-21 06:00:00"), 4, 2, 72.0, null, "= La dette du client est soldée");
INSERT INTO stocks (id, item, quantity)
VALUES(1, 1, 25),
(2, 2, 12),
(3, 3, 50);
\ No newline at end of file
File mode changed from 100644 to 100755
......@@ -22,4 +22,6 @@ public class Config {
public static final String MAPPING_SUBTRANSAC = URL_PREFIX +
"/submitTransaction";
public static final String MAPPING_GETSTOCKS = URL_PREFIX +
"/retrieveStocks";
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller;
import org.springframework.http.ResponseEntity;
/**
* Interface for designing access to categories.
* @author BEAUVAIS ANTOINE
*/
public interface IRetrieveCategoriesController {
/**
* Retrieves all categories.
* @return the response.
* @throws java.lang.Exception when the request cannot be served.
*/
public ResponseEntity<Object> getCategories() throws Exception;
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Interface for designing the retrieval of articles.
* @author BEAUVAIS ANTOINE
*/
public interface IRetrieveInfoController {
/**
* Retrieves the list of items.
* @param cat
* @return
* @throws Exception
*/
public ResponseEntity<Object> retrieveInfo(
@RequestParam(value = "category", defaultValue = "") String cat
) throws Exception;
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.ResponseEntity;
/**
* Interface for designing stocks access.
* @author BEAUVAIS ANTOINE
*/
public interface IRetrieveStocks {
public ResponseEntity<Object> retrieveStocks(HttpServletRequest request,
HttpServletResponse response) throws Exception;
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.ResponseEntity;
/**
* Interface for designing transaction submission.
* @author BEAUVAIS ANTOINE
*/
public interface ISubmitTransactionController {
/**
* Submits a transaction to the application.
* @param request the HTTP Servlet Request, provided by Spring Web
* @param response the HTTP Servlet Response, provided by Spring Web
* @return the response served to the user.
* @throws java.lang.Exception when the request cannot be served.
*/
public ResponseEntity<Object> submitTransaction(HttpServletRequest request,
HttpServletResponse response) throws Exception;
}
......@@ -2,7 +2,7 @@
* 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;
package fr.unistra.sil.erp.back.controller.api;
/**
* HTTP error 400 Bad Request for the API.
......
......@@ -2,9 +2,9 @@
* 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;
package fr.unistra.sil.erp.back.controller.api;
import fr.unistra.sil.erp.back.api.model.ErrorMessage;
import fr.unistra.sil.erp.back.model.ErrorMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
......
......@@ -2,11 +2,13 @@
* 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;
package fr.unistra.sil.erp.back.controller.api;
import static fr.unistra.sil.erp.back.Config.MAPPING_GETCATEGORIES;
import static fr.unistra.sil.erp.back.Config.MAPPING_GETSTOCKS;
import fr.unistra.sil.erp.back.DatabaseSystem;
import fr.unistra.sil.erp.back.api.model.Category;
import fr.unistra.sil.erp.back.controller.IRetrieveCategoriesController;
import fr.unistra.sil.erp.back.model.Category;
import fr.unistra.sil.erp.back.db.DatabaseConnectionException;
import fr.unistra.sil.erp.back.db.DatabaseInterface;
import java.util.List;
......@@ -22,7 +24,8 @@ import org.springframework.web.bind.annotation.RestController;
* @author BEAUVAIS ANTOINE
*/
@RestController
public class ApiRetrieveCategoriesController {
public class ApiRetrieveCategoriesController
implements IRetrieveCategoriesController {
/**
* Returns the list of categories in JSON format.
......@@ -30,6 +33,7 @@ public class ApiRetrieveCategoriesController {
* @throws ApiServerErrorException Database failure.
*/
@GetMapping(MAPPING_GETCATEGORIES)
@Override
public ResponseEntity<Object> getCategories() throws ApiServerErrorException
{
DatabaseInterface db;
......
......@@ -2,16 +2,18 @@
* 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;
package fr.unistra.sil.erp.back.controller.api;
import static fr.unistra.sil.erp.back.Config.MAPPING_RETRIEVEALL;
import fr.unistra.sil.erp.back.DatabaseSystem;
import fr.unistra.sil.erp.back.api.model.Item;
import fr.unistra.sil.erp.back.controller.IRetrieveInfoController;
import fr.unistra.sil.erp.back.model.Item;
import fr.unistra.sil.erp.back.db.DatabaseConnectionException;
import fr.unistra.sil.erp.back.db.DatabaseInterface;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -20,17 +22,17 @@ import org.springframework.web.bind.annotation.RestController;
/**
* REST controller for the item list.
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
* @author BEAUVAIS ANTOINE
*/
@RestController
public class ApiRetrieveInfoController {
public class ApiRetrieveInfoController implements IRetrieveInfoController {
/**
* Returns all products as a JSON response.
* @param cat an optional category.
* @return a JSON response.
* @throws fr.unistra.sil.erp.back.api.controller.ApiServerErrorException
* @throws fr.unistra.sil.erp.back.api.controller.ApiBadRequestException
* @throws fr.unistra.sil.erp.back.controller.api.ApiServerErrorException
* @throws fr.unistra.sil.erp.back.controller.api.ApiBadRequestException
*/
@GetMapping(MAPPING_RETRIEVEALL)
public ResponseEntity<Object> retrieveInfo(
......@@ -66,6 +68,8 @@ public class ApiRetrieveInfoController {
if(res == null)
throw new ApiServerErrorException("Failed to query info.");
else if(res.isEmpty())
return ResponseEntity.noContent().build();
return new ResponseEntity<>(res, HttpStatus.OK);
}
......
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller.api;
import static fr.unistra.sil.erp.back.Config.MAPPING_GETSTOCKS;
import fr.unistra.sil.erp.back.DatabaseSystem;
import fr.unistra.sil.erp.back.controller.IRetrieveStocks;
import fr.unistra.sil.erp.back.db.DatabaseConnectionException;
import fr.unistra.sil.erp.back.db.DatabaseInterface;
import fr.unistra.sil.erp.back.model.Stock;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Retrieves stocks in JSON format.
* @author BEAUVAIS ANTOINE
*/
@RestController
public class ApiRetrieveStocks implements IRetrieveStocks {
/**
* Sends the stocks as JSON format back to the client.
* @param request the HTTP request.
* @param response the HTTP response.
* @return the response.
* @throws fr.unistra.sil.erp.back.controller.api.ApiServerErrorException
*/
@GetMapping(MAPPING_GETSTOCKS)
@Override
public ResponseEntity<Object> retrieveStocks(HttpServletRequest request,
HttpServletResponse response) throws ApiServerErrorException {
DatabaseInterface db;
try {
db = DatabaseSystem.getInstance();
} catch (DatabaseConnectionException ex) {
Logger.getLogger(ApiRetrieveCategoriesController.class.getName())
.log(Level.SEVERE, "Failed to connect to database.", ex);
throw new ApiServerErrorException("Database failure.");
}
List<Stock> res = db.getStocks();
if(res == null)
throw new ApiServerErrorException("Database failure.");
return new ResponseEntity<>(res, HttpStatus.OK);
}
}
......@@ -2,7 +2,7 @@
* 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;
package fr.unistra.sil.erp.back.controller.api;
/**
* Returns HTTP 500 error page.
......
......@@ -2,11 +2,20 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package fr.unistra.sil.erp.back.api.controller;
package fr.unistra.sil.erp.back.controller.api;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import static fr.unistra.sil.erp.back.Config.MAPPING_SUBTRANSAC;
import fr.unistra.sil.erp.back.controller.ISubmitTransactionController;
import fr.unistra.sil.erp.back.model.Transaction;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -17,13 +26,47 @@ import org.springframework.web.bind.annotation.RestController;
* @author BEAUVAIS ANTOINE
*/
@RestController
public class ApiSubmitTransactionController {
public class ApiSubmitTransactionController
implements ISubmitTransactionController {
@RequestMapping(value=MAPPING_SUBTRANSAC, method = RequestMethod.POST)
@Override
public ResponseEntity<Object> submitTransaction(HttpServletRequest request,
HttpServletResponse response)
HttpServletResponse response) throws ApiBadRequestException
{
throw new UnsupportedOperationException("Not yet supported.");
Gson gson = new Gson();
String body;
try {
body = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
} catch (IOException ex) {
Logger.getLogger(ApiSubmitTransactionController.class.getName())
.log(Level.SEVERE, "Unparseable body.", ex);
throw new ApiBadRequestException("Unparseable body.");
}
if(body == null)
throw new ApiBadRequestException("Missing JSON body.");
Transaction t;
try
{
t = gson.fromJson(body, Transaction.class);
}
catch(JsonParseException ex)
{
throw new ApiBadRequestException("Invalid JSON: syntax error.");
}
if(t == null)
throw new ApiBadRequestException("Missing JSON body.");
if(!t.checkIfValid())
throw new ApiBadRequestException("Invalid JSON schema.");
System.out.println("Transaction : " + t.getItem() +
t.getType() + " " + t.getAmount());
return new ResponseEntity<>(t, HttpStatus.CREATED);
}
}
......@@ -4,8 +4,9 @@
*/
package fr.unistra.sil.erp.back.db;
import fr.unistra.sil.erp.back.api.model.Category;
import fr.unistra.sil.erp.back.api.model.Item;
import fr.unistra.sil.erp.back.model.Category;
import fr.unistra.sil.erp.back.model.Item;
import fr.unistra.sil.erp.back.model.Stock;
import java.util.List;
/**
......@@ -38,4 +39,11 @@ public interface DatabaseInterface {
*/
public List<Category> getCategories();
/**
* Returns the list of all stocks.
*
* @return the list of stocks.
*/
public List<Stock> getStocks();
}
......@@ -4,8 +4,9 @@
*/
package fr.unistra.sil.erp.back.db;
import fr.unistra.sil.erp.back.api.model.Category;
import fr.unistra.sil.erp.back.api.model.Item;
import fr.unistra.sil.erp.back.model.Category;
import fr.unistra.sil.erp.back.model.Item;
import fr.unistra.sil.erp.back.model.Stock;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
......@@ -18,7 +19,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* SQLite implementation of the Database interface.
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
*/
public class DatabaseSQLiteImpl implements DatabaseInterface {
......@@ -33,6 +34,11 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
private static final String SQL_GETCATEGORIES =
"SELECT id, name FROM categories";
private static final String SQL_GETSTOCKS =
"SELECT s.id AS id, s.item AS item, " +
"i.name AS name, s.quantity AS quantity FROM stocks s " +
"INNER JOIN items i ON s.item = i.ref";
private Connection conn;
public DatabaseSQLiteImpl()
......@@ -156,5 +162,29 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
return res;
}
@Override
public List<Stock> getStocks() {
ResultSet rs = this.query(SQL_GETSTOCKS);
if(rs == null)
return null;
List<Stock> res = new ArrayList<>();
try {
while(rs.next())
{
Stock s = new Stock(rs.getInt("id"),
rs.getInt("item"), rs.getString("name"),
rs.getInt("quantity"));
res.add(s);
}
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to fetch results.", ex);
return null;
}
return res;
}
}
......@@ -2,7 +2,7 @@
* 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;
package fr.unistra.sil.erp.back.model;
/**
* Category entity.
......
......@@ -2,7 +2,7 @@
* 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;
package fr.unistra.sil.erp.back.model;
/**
* JSON error message.
......
......@@ -2,7 +2,7 @@
* 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;
package fr.unistra.sil.erp.back.model;
import java.math.BigDecimal;
......
......@@ -2,7 +2,7 @@
* 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;
package fr.unistra.sil.erp.back.model;
import java.math.BigDecimal;
import java.time.LocalDateTime;
......@@ -16,19 +16,19 @@ public class RegistryEntry {
private final int id;
private final int transactionId;
private final LocalDateTime dt;
private final String description;
private final int accountId;
private final BigDecimal debit;
private final BigDecimal credit;
private final String remarks;
public RegistryEntry(int id, int transactionId, LocalDateTime dt,
String description, BigDecimal debit, BigDecimal credit,
int accountId, BigDecimal debit, BigDecimal credit,
String remarks)
{
this.id = id;
this.transactionId = transactionId;
this.dt = dt;
this.description = description;
this.accountId = accountId;
this.debit = debit;
this.credit = credit;
this.remarks = remarks;
......@@ -49,9 +49,9 @@ public class RegistryEntry {
return this.dt;
}
public String getDescription()
public int getAccountId()
{
return this.description;
return this.accountId;
}
public BigDecimal getDebit()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment