Skip to content
Snippets Groups Projects
Commit b56fb115 authored by Tormod Mork Müller's avatar Tormod Mork Müller :computer:
Browse files

Merge branch 'main' of https://git.gvk.idi.ntnu.no/aleksaab/stillastracker into Tormod

parents 1fbf0482 23e35196
No related branches found
No related tags found
1 merge request!116Tormod
Showing
with 295 additions and 20 deletions
# stillasTracker
# Version 0.1
#
stillasTracker is a software solution which provides MB-Stillas with an API, a database and two-front end solutions.
The readme will serve as endpoint documentation for the stillastracker API as well as a brief user guide for both of the front end solutions in the repository
## Endpoint-Documentation:
The following endpoints are available in the current version of the API:
### Scaffolding (stillasdel) endpoints
The scaffolding endpoint has GET, POST, PUT and DELETE functionality. Get requests are used
get information regarding scaffolding parts, you can get scaffolding parts based on the queries listed
in the table below.
**GET requests**
The GET requests fetches scaffolding parts from the database
```
/stillastracking/v1/api/unit?type={:type}&id={:id}
/stillastracking/v1/api/unit?type={:type}
/stillastracking/v1/api/unit
```
**POST and PUT requests**
The post and put requests are used to add in new scaffolding parts or update them.
```
/stillastracking/v1/api/unit
Example body:
{
"id": "AB23GW",
"type": "Flooring",
"project": "CCHamar",
"batteryLevel": 100
}
```
**DELETE**
The delete request deletes scaffolding units from the database
```
/stillastracking/v1/api/unit
Example body:
[
{
"id": "4A6352"
},
{
"id": "56GWAG"
},
{
"id": "8GTW21"
},
{
"id": "LPW123"
}
]
```
### Project (byggeprosjekt) endpoints
This endpoint handles all data regarding projects in the database.
**GET**
These endpoints are used to fetch information regarding projects from the database. Adding scaffolding=true
after the endpoint will list all the scaffolding parts associated with the project.
```
/stillastracking/v1/api/project?id={:id}&scaffolding={:scaffolding}
/stillastracking/v1/api/project?name={:name}&scaffolding={:scaffolding}
/stillastracking/v1/api/project?id={:id}
/stillastracking/v1/api/project?name={:name}
/stillastracking/v1/api/project?id={:id}
/stillastracking/v1/api/project?scaffolding={:scaffolding}
/stillastracking/v1/api/project
/stillastracking/v1/api/storage
```
**POST and PUT**
The following endpoint is used to add in new scaffoldingparts
```
/stillastracking/v1/api/project
Example body
{
"projectID":2321112,
"projectName":"MBStillas",
"latitude":60.79077759591496,
"longitude":10.683249543160402,
"state":"Active",
"size":322,
"period":{
"startDate":"25-04-2022",
"endDate":"30-04-2022"
},
"customer":{
"name":"Martin Ivers",
"number":98435621,
"email":"martin@mail.no"
},
"address":{
"street":"Halsetsvea 40",
"zipcode":"2323",
"municipality":"Ingeberg",
"county":"Innlandet"
},
"geofence":{
"w-position":{"latitude":-73.98326396942211,"longitude":40.69287790858968},
"x-position":{"latitude":-73.98387551307742,"longitude":40.6922433936175},
"y-position":{"latitude":-73.98255586624245,"longitude":40.691999347788055},
"z-position":{"latitude":-73.98124694824298,"longitude":40.69267453906423}
}
}
/stillastracking/v1/api/project/scaffold
Example body:
{
"toProjectID":755,
"fromProjectID":12,
"scaffold":[{
"type":"Bunnskrue",
"quantity":1
},]
}
```
**DELETE**
The endpoint is used to delete projects
```
/stillastracking/v1/api/project
Example body:
[
{
"id": 430
},
{
"id": 420
}
]
```
### Profile (bruker) endpoints
The endpoint handles user creation,updates and removals.
**GET**
The endpoints below fetches users from the database
```
/stillastracking/v1/api/user?id={:id}
/stillastracking/v1/api/user?role={:role}
/stillastracking/v1/api/user
```
**POST or PUT**
The endpoint creates or updates users
```
/stillastracking/v1/api/user
Example body:
{
"employeeID": 232,
"name": "Ola Nordmann",
"dateOfBirth": "01.04.1988",
"role": "Storage",
"admin": true
}
```
**DELETE**
The endpoint deletes users from the database
```
/stillastracking/v1/api/user
Example body:
[
{"id" : "12521"},
{"id" : "12521"},
{"id" : "12521"},
{"id" : "12521"},
]
```
### Gateway endpoints
The endpoint handles all management of BLE Gateways in the database
**GET**
The following endpoints can be used to fetch gateways from the database
```
/stillastracking/v1/api/gateway?id={:id}
/stillastracking/v1/api/gateway?projectName={:projectName}
/stillastracking/v1/api/gateway?projectID={:projectID}
/stillastracking/v1/api/gateway
```
**POST or PUT**
The endpoint creates and updates gateways
```
/stillastracking/v1/api/gateway
Example body:
{
"Status": true
"gatewayID": "34AB954B54E4"
"latitude": 59.911491
"longitude": 10.757933
"projectID": 4
"projectName": "CCHamar"
}
```
**DELETE**
The endpoint deletes gateways
```
/stillastracking/v1/api/gateway
Example body:
[
{"id" : "34AB954B54E4"},
{"id" : "34AB954BABEE4"},
{"id" : "34TQWD21SDAE4"},
{"id" : "1241WADQWDQW4"},
]
```
......@@ -9,6 +9,12 @@ import (
"strings"
)
/*
Class basicTools contains functions for assisting API endpoints
Last update 19.05.2022 Martin Ivesren
@version 1.0
*/
func CreatePath(segments []string) string {
var finalPath string
for _, s := range segments {
......
......@@ -10,7 +10,7 @@ Code inspired by:
Page authored by Matt Silverlock from questionable serviecs
Last visit: 08.03.2022
version 0.1
version 1.0
Last edited 08.03.2022 by Martin Iversen
*/
......
......@@ -9,7 +9,7 @@ import (
/**
Class main
Will run the api
Version 0.1
Version 1.0
Last update 08.03.2022 Martin Iversen
*/
......
......@@ -11,6 +11,11 @@ import (
"path/filepath"
)
/*
Class databaseSetup.go created for communicating with database
Last update 19.05.2022
@version 1.0
*/
// Ctx Initializing the context to be used with firebase
var Ctx context.Context
......
......@@ -13,7 +13,7 @@ Class APIHandler.go
Class forwards requests to the appropriate endpoint and assigns the port of the program
Last modified by martiiv@stud.ntnu.no
Date: 06.04.2022
Version 0.8
Version 1.0
*/
var (
InfoLogger *log.Logger
......
......@@ -16,6 +16,11 @@ import (
"strconv"
)
/**
Class gateway.go created for managing gateways
@version 1.0
Last edit 19.05.2022
*/
var gatewayCollection *firestore.CollectionRef
var projectCollection *firestore.DocumentRef
......
......@@ -6,6 +6,12 @@ import (
tool "stillasTracker/api/apiTools"
)
/**
Class homepage.go created but never used,
@version 1.0
last edit 19.05.2022
*/
func homePage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
......
......@@ -20,7 +20,7 @@ import (
/**
Class profiles
This class will contain all data formatting and modification regarding the users of the system
Version 0.9
Version 1.0
Last modified Martin Iversen 07.04.2022
TODO Maybe modularize som functionality the marshall, unmarshall encode routine is repeated often
*/
......
......@@ -17,7 +17,7 @@ import (
/*
projectTools File contains tools used in the projects.go file
Last edited Martin Iversen 07.04.2022
Version 0.9
Version 1.0
TODO Delete checkProjectBody? It isn't used
*/
......
......@@ -22,7 +22,7 @@ import (
Class projects
This class will contain all data formatting and handling of the clients projects
Class contains the following functions:
Version 0.9
Version 1.0
Last modified Martin Iversen 07.04.2022
TODO Find alternative for strings.Title since the function is deprecated
TODO If possible modularize the unmarshalling and encoding of lists since there is a lot of duplicate code doing this
......
......@@ -15,7 +15,7 @@ import (
/**
Class scaffolding
This class will contain all functions used for the handling of scaffolding units
Version 0.9
Version 1.0
Last modified Martin Iversen 07.04.2022
TODO make type non case sensitive
*/
......
......@@ -24,8 +24,8 @@ Class gateway
The class wil handle all information regarding the cellular gateways in the system
The class will contain the following functions:
Version 0.1
Last modified Martin Iversen
Version 1.0
Last modified Martin Iversen 19.05.2022
*/
func UpdatePosition(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
......
......@@ -10,6 +10,12 @@ import (
"strings"
)
/**
Class mqttBroker.go created for implementing an mqtt broker
This functionality was never implemented fully given time constraints
@version 0.5
last edited Martin Iversen 19.05.2022
*/
type AdvPacket struct {
msg *igs.Message
packet *ibs.Payload
......
package tests
package tests
import (
"github.com/gorilla/mux"
"github.com/steinfletcher/apitest"
"net/http"
"net/http/httptest"
"stillasTracker/api/endpoints"
"testing"
)
......@@ -13,12 +15,15 @@ Function for testing the scaffolding endpoint
*/
func Test_ScaffoldingAPITEST(t *testing.T) {
dataBaseTestConnection()
handler := http.HandlerFunc(endpoints.ScaffoldingRequest)
r := mux.NewRouter()
//Add list of Scaffoldingparts which sends a post request and creates 12 scaffolding parts
t.Run("Add list of Scaffoldingparts", func(t *testing.T) {
r.HandleFunc("/stillastracking/v1/api/unit/", endpoints.ScaffoldingRequest)
ts := httptest.NewServer(r)
defer ts.Close()
apitest.New().
HandlerFunc(handler).
Handler(r).
Post("/stillastracking/v1/api/unit/").
Body(`[ { "id": 1, "type": "Spire", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address":null } }, { "id": 2, "type": "Flooring", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 3, "type": "Short-Flooring", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 4, "type": "Staircase", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 5, "type": "Bottom-Screw", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 6, "type": "Diagonals", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 7, "type": "Beam1", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 8, "type": "Beam2", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 9, "type": "Flooring", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 10, "type": "Flooring", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 11, "type": "Spire", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } }, { "id": 12, "type": "Railing", "batteryLevel": 100, "location": { "longitude": null, "latitude": null, "address": null } } ]`).
Expect(t).
......@@ -29,8 +34,11 @@ func Test_ScaffoldingAPITEST(t *testing.T) {
//Gets all Scaffolding parts
t.Run("Get all Scaffolding parts", func(t *testing.T) {
r.HandleFunc("/stillastracking/v1/api/unit/", endpoints.ScaffoldingRequest)
ts := httptest.NewServer(r)
defer ts.Close()
apitest.New().
HandlerFunc(handler).
HandlerFunc(endpoints.ScaffoldingRequest).
Get("/stillastracking/v1/api/unit/").
Expect(t).
Body("{\"batteryLevel\":100,\"id\":7,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Beam1\"}\n{\"batteryLevel\":100,\"id\":8,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Beam2\"}\n{\"batteryLevel\":100,\"id\":5,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Bottom-Screw\"}\n{\"batteryLevel\":100,\"id\":6,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Diagonals\"}\n{\"batteryLevel\":100,\"id\":10,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Flooring\"}\n{\"batteryLevel\":100,\"id\":2,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Flooring\"}\n{\"batteryLevel\":100,\"id\":9,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Flooring\"}\n{\"batteryLevel\":100,\"id\":12,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Railing\"}\n{\"batteryLevel\":100,\"id\":3,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Short-Flooring\"}\n{\"batteryLevel\":100,\"id\":1,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Spire\"}\n{\"batteryLevel\":100,\"id\":11,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Spire\"}\n{\"batteryLevel\":100,\"id\":4,\"location\":{\"address\":null,\"latitude\":null,\"longitude\":null},\"type\":\"Staircase\"}\n").
......@@ -40,8 +48,11 @@ func Test_ScaffoldingAPITEST(t *testing.T) {
//Gets all Scaffolding parts by Flooring
t.Run("Get Scaffolding by type", func(t *testing.T) {
r.HandleFunc("/stillastracking/v1/api/unit", endpoints.ScaffoldingRequest).Queries()
ts := httptest.NewServer(r)
defer ts.Close()
apitest.New().
HandlerFunc(handler).
HandlerFunc(endpoints.ScaffoldingRequest).
Get("/stillastracking/v1/api/unit").
Query("type", "Flooring").
Expect(t).
......@@ -50,7 +61,7 @@ func Test_ScaffoldingAPITEST(t *testing.T) {
End()
apitest.New().
HandlerFunc(handler).
HandlerFunc(endpoints.ScaffoldingRequest).
Get("/stillastracking/v1/api/unit").
Query("type", "Beam1").
Expect(t).
......@@ -59,7 +70,7 @@ func Test_ScaffoldingAPITEST(t *testing.T) {
End()
apitest.New().
HandlerFunc(handler).
HandlerFunc(endpoints.ScaffoldingRequest).
Get("/stillastracking/v1/api/unit").
Query("type", "Staircase").
Expect(t).
......@@ -71,7 +82,7 @@ func Test_ScaffoldingAPITEST(t *testing.T) {
//Gets a specific scaffolding part
t.Run("Get Individual Scaffolding part", func(t *testing.T) {
apitest.New().
HandlerFunc(handler).
HandlerFunc(endpoints.ScaffoldingRequest).
Get("/stillastracking/v1/api/unit").
Query("type", "Flooring").
Query("id", "9").
......@@ -83,7 +94,7 @@ func Test_ScaffoldingAPITEST(t *testing.T) {
t.Run("Delete all scaffolding parts", func(t *testing.T) {
apitest.New().
HandlerFunc(handler).
HandlerFunc(endpoints.ScaffoldingRequest).
Delete("/stillastracking/v1/api/unit/").
Body("[ { \"id\": 7, \"type\": \"Beam1\" }, { \"id\": 8, \"type\": \"Beam2\" }, { \"id\": 5, \"type\": \"Bottom-Screw\" }, { \"id\": 6, \"type\": \"Diagonals\" }, { \"id\": 10, \"type\": \"Flooring\" }, { \"id\": 2, \"type\": \"Flooring\" }, { \"id\": 9, \"type\": \"Flooring\" }, { \"id\": 12, \"type\": \"Railing\" }, { \"id\": 3, \"type\": \"Short-Flooring\" }, { \"id\": 1, \"type\": \"Spire\" }, { \"id\": 11, \"type\": \"Spire\" }, { \"id\": 4, \"type\": \"Staircase\" } ]").
Expect(t).
......
......@@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/src/Config/firebaseConfig.js
......@@ -5,6 +5,7 @@
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
<excludeFolder url="file://$MODULE_DIR$/.idea/inspectionProfiles" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
......
webstillas/src/Assets/Images/profile-png-icon-2.png

34.8 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment