Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
stillasTracker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aleksander Aaboen
stillasTracker
Commits
4a3d559c
Commit
4a3d559c
authored
3 years ago
by
Martin Iversen
Browse files
Options
Downloads
Patches
Plain Diff
FInished query specification for project and storage endpoint
parent
f55615df
No related branches found
No related tags found
1 merge request
!51
Martin
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/endpoints/APIHandler.go
+6
-8
6 additions, 8 deletions
api/endpoints/APIHandler.go
api/endpoints/projects.go
+15
-13
15 additions, 13 deletions
api/endpoints/projects.go
api/endpoints/scaffolding.go
+0
-3
0 additions, 3 deletions
api/endpoints/scaffolding.go
with
21 additions
and
24 deletions
api/endpoints/APIHandler.go
+
6
−
8
View file @
4a3d559c
...
...
@@ -30,17 +30,15 @@ func Handle() {
router
.
Path
(
baseURL
+
"/unit"
)
.
HandlerFunc
(
ScaffoldingRequest
)
//GET POST PUT DELETE
//Project endpoint
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
.
Queries
(
)
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
.
Queries
(
)
.
Queries
()
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
.
Queries
(
"id"
,
"{id}"
)
.
Queries
(
"scaffolding"
,
"{scaffolding}"
)
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
.
Queries
(
"name"
,
"{name}"
)
.
Queries
(
"scaffolding"
,
"{scaffolding}"
)
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
.
Queries
(
"id"
,
"{id}"
)
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
.
Queries
(
"name"
,
"{name}"
)
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/{scaffolding}"
,
ProjectRequest
)
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/{scaffolding}"
,
ProjectRequest
)
.
Queries
()
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/{scaffolding}"
,
ProjectRequest
)
.
Queries
()
.
Queries
()
//DELETE, POST, GET
router
.
HandleFunc
(
baseURL
+
"/project/"
,
ProjectRequest
)
//DELETE, POST, GET
//Storage endpoint
router
.
HandleFunc
(
baseURL
+
"/storage/"
,
storageRequest
)
router
.
HandleFunc
(
baseURL
+
"/storage/"
,
storageRequest
)
.
Queries
()
//Profile endpoint
router
.
HandleFunc
(
baseURL
+
"/user/"
,
ProfileRequest
)
...
...
This diff is collapsed.
Click to expand it.
api/endpoints/projects.go
+
15
−
13
View file @
4a3d559c
...
...
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/gorilla/mux"
"google.golang.org/api/iterator"
"io"
"io/ioutil"
...
...
@@ -117,18 +118,19 @@ If the user made an invalid request, the user will be redirected to invalidReque
func
getProject
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
"*"
)
queries
:=
mux
.
Vars
(
r
)
query
,
err
:=
tool
.
GetQueryProject
(
r
)
/*
query, err := tool.GetQueryProject(r)
if !err {
tool.HandleError(tool.INVALIDREQUEST, w)
return
}
}
*/
switch
true
{
case
!
quer
y
.
Has
(
constants
.
P_idURL
)
&&
!
quer
y
.
Has
(
constants
.
P_nameURL
)
&&
!
quer
y
.
Has
(
constants
.
P_State
)
:
case
quer
ies
[
constants
.
P_idURL
]
==
""
&&
quer
ies
[
constants
.
P_nameURL
]
==
""
&&
quer
ies
[
constants
.
P_State
]
==
""
:
getProjectCollection
(
w
,
r
)
//If the query has keywords specific to the state of the project it ends up here
break
case
quer
y
.
Has
(
constants
.
P_idURL
)
||
quer
y
.
Has
(
constants
.
P_nameURL
)
||
quer
y
.
Has
(
constants
.
P_State
)
:
case
quer
ies
[
constants
.
P_idURL
]
!=
""
||
quer
ies
[
constants
.
P_nameURL
]
!=
""
||
quer
ies
[
constants
.
P_State
]
!=
""
:
getProjectWithID
(
w
,
r
)
//If the query has keywords specific to the state of the project it ends up here
break
default
:
...
...
@@ -148,7 +150,7 @@ func getProjectCollection(w http.ResponseWriter, r *http.Request) {
//Defines the necessary variables
var
projects
[]
_struct
.
GetProject
//Defines a list containing multiple GetProject structs
collectionIterator
:=
ProjectCollection
.
Collections
(
database
.
Ctx
)
queryMap
:=
r
.
URL
.
Query
(
)
queryMap
:=
mux
.
Vars
(
r
)
for
{
//For loop iterates through all the documents in the project collection and appends them
collRef
,
err
:=
collectionIterator
.
Next
()
...
...
@@ -183,7 +185,7 @@ func getProjectCollection(w http.ResponseWriter, r *http.Request) {
var
project
_struct
.
GetProject
//Defines one instance of the GetProject struct, we have the project details but need scaffolding parts
project
.
NewProject
=
projectNew
//Defines the project section of the GetProject struct
if
queryMap
.
Has
(
constants
.
P_scaffolding
)
&&
queryMap
.
Get
(
constants
.
P_scaffolding
)
==
"true"
{
if
queryMap
[
constants
.
P_scaffolding
]
==
"true"
{
scaffold
,
err
:=
getScaffoldingStruct
(
documentRef
.
Ref
)
//If the request asks for scaffolding parts we get the scaffolding struct
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
COULDNOTFINDDATA
,
w
)
...
...
@@ -215,9 +217,9 @@ func getProjectWithID(w http.ResponseWriter, r *http.Request) {
var
projects
[]
_struct
.
GetProject
var
err
error
queryMap
,
_
:=
tool
.
GetQueryProject
(
r
)
if
queryMap
.
Has
(
constants
.
P_idURL
)
{
//If the query contains a project ID we convert it to int and store it for later use
intID
,
err
:=
strconv
.
Atoi
(
queryMap
.
Get
(
constants
.
P_idURL
)
)
queryMap
:=
mux
.
Vars
(
r
)
if
queryMap
[
constants
.
P_idURL
]
!=
""
{
//If the query contains a project ID we convert it to int and store it for later use
intID
,
err
:=
strconv
.
Atoi
(
queryMap
[
constants
.
P_idURL
]
)
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
INVALIDBODY
,
w
)
return
...
...
@@ -225,11 +227,11 @@ func getProjectWithID(w http.ResponseWriter, r *http.Request) {
documentReference
,
err
=
IterateProjects
(
intID
,
""
,
""
)
//Finds the project with the defined ID
}
else
if
queryMap
.
Has
(
constants
.
P_nameURL
)
{
//If the url contains a project name we will use that instead
documentReference
,
err
=
IterateProjects
(
0
,
queryMap
.
Get
(
constants
.
P_nameURL
)
,
""
)
}
else
if
queryMap
[
constants
.
P_nameURL
]
!=
""
{
//If the url contains a project name we will use that instead
documentReference
,
err
=
IterateProjects
(
0
,
queryMap
[
constants
.
P_nameURL
]
,
""
)
}
else
{
//If the url contains a state we will use that instead
//Function strings.Title is deprecated however formatting makes usages of cases.Title impossible
documentReference
,
err
=
IterateProjects
(
0
,
""
,
strings
.
Title
(
queryMap
.
Get
(
constants
.
P_State
)
))
documentReference
,
err
=
IterateProjects
(
0
,
""
,
strings
.
Title
(
queryMap
[
constants
.
P_State
]
))
}
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
NODOCUMENTWITHID
,
w
)
...
...
@@ -263,7 +265,7 @@ func getProjectWithID(w http.ResponseWriter, r *http.Request) {
var
project
_struct
.
GetProject
project
.
NewProject
=
projectNew
if
queryMap
.
Has
(
constants
.
P_scaffolding
)
&&
queryMap
.
Get
(
constants
.
P_scaffolding
)
==
"true"
{
if
queryMap
[
constants
.
P_scaffolding
]
==
"true"
{
scaffold
,
err
:=
getScaffoldingStruct
(
ref
)
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
COULDNOTFINDDATA
,
w
)
...
...
This diff is collapsed.
Click to expand it.
api/endpoints/scaffolding.go
+
0
−
3
View file @
4a3d559c
...
...
@@ -50,9 +50,6 @@ func getPart(w http.ResponseWriter, r *http.Request) {
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
"*"
)
queries
:=
mux
.
Vars
(
r
)
print
(
queries
[
"type"
])
print
(
queries
[
"id"
])
switch
true
{
case
queries
[
"type"
]
!=
""
&&
queries
[
"id"
]
!=
""
:
//URL is on the following format: /stillastracking/v1/api/unit?type=""&id=""
getIndividualScaffoldingPart
(
w
,
queries
[
"type"
],
queries
[
"id"
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment