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
18e91127
Commit
18e91127
authored
May 4, 2022
by
Aleksander Aaboen
Browse files
Options
Downloads
Patches
Plain Diff
Changed id for employee to be string
parent
9d06e520
No related branches found
No related tags found
1 merge request
!102
Alex
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/endpoints/profiles.go
+13
-18
13 additions, 18 deletions
api/endpoints/profiles.go
api/struct/ProfileStruct.go
+2
-2
2 additions, 2 deletions
api/struct/ProfileStruct.go
with
15 additions
and
20 deletions
api/endpoints/profiles.go
+
13
−
18
View file @
18e91127
...
...
@@ -13,7 +13,6 @@ import (
"stillasTracker/api/constants"
"stillasTracker/api/database"
_struct
"stillasTracker/api/struct"
"strconv"
"strings"
"time"
)
...
...
@@ -104,7 +103,7 @@ func createProfile(w http.ResponseWriter, r *http.Request) {
return
}
id
:=
strconv
.
Itoa
(
employee
.
EmployeeID
)
//Converts the employee id to string
id
:=
employee
.
EmployeeID
//Converts the employee id to string
_
,
err
=
iterateProfiles
(
employee
.
EmployeeID
,
""
)
//Iterates through the profiles using the id
if
err
==
nil
{
tool
.
HandleError
(
tool
.
CouldNotAddSameID
,
w
)
...
...
@@ -158,9 +157,9 @@ func updateProfile(w http.ResponseWriter, r *http.Request) {
return
}
employee
:=
employeeStruct
[
constants
.
U_employeeID
]
.
(
float64
)
//Defines the employee id
employee
:=
employeeStruct
[
constants
.
U_employeeID
]
.
(
string
)
//Defines the employee id
documentReference
,
err
:=
iterateProfiles
(
int
(
employee
)
,
""
)
//Finds the profile using the id
documentReference
,
err
:=
iterateProfiles
(
employee
,
""
)
//Finds the profile using the id
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
COULDNOTFINDDATA
,
w
)
return
...
...
@@ -215,8 +214,8 @@ func deleteProfile(w http.ResponseWriter, r *http.Request) {
return
}
for
_
,
num
:=
range
deleteID
{
//Iterates through the profiles
document
,
err
:=
iterateProfiles
(
num
.
Id
,
""
)
for
_
,
profile
:=
range
deleteID
{
//Iterates through the profiles
document
,
err
:=
iterateProfiles
(
profile
.
Id
,
""
)
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
CouldNotDelete
,
w
)
return
...
...
@@ -346,7 +345,7 @@ func getUserByName(w http.ResponseWriter, r *http.Request) {
queryMap
:=
r
.
URL
.
Query
()
documentReference
,
err
=
iterateProfiles
(
0
,
queryMap
.
Get
(
constants
.
U_nameURL
))
//Gets the profile with the appropriate name
documentReference
,
err
=
iterateProfiles
(
""
,
queryMap
.
Get
(
constants
.
U_nameURL
))
//Gets the profile with the appropriate name
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
COULDNOTFINDDATA
,
w
)
return
...
...
@@ -392,13 +391,9 @@ func getIndividualUserByID(w http.ResponseWriter, r *http.Request) {
var
err
error
queryMap
:=
mux
.
Vars
(
r
)
intID
,
err
:=
strconv
.
Atoi
(
queryMap
[
constants
.
U_idURL
])
//Converts the query id to int
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
INVALIDREQUEST
,
w
)
return
}
id
:=
queryMap
[
constants
.
U_idURL
]
//Converts the query id to int
documentReference
,
err
=
iterateProfiles
(
i
ntID
,
""
)
//Gets the documents with the id
documentReference
,
err
=
iterateProfiles
(
i
d
,
""
)
//Gets the documents with the id
if
err
!=
nil
{
tool
.
HandleError
(
tool
.
COULDNOTFINDDATA
,
w
)
return
...
...
@@ -418,7 +413,7 @@ func getIndividualUserByID(w http.ResponseWriter, r *http.Request) {
return
}
if
employee
.
EmployeeID
==
0
{
if
employee
.
EmployeeID
==
""
{
tool
.
HandleError
(
tool
.
COULDNOTFINDDATA
,
w
)
return
}
...
...
@@ -430,7 +425,7 @@ func getIndividualUserByID(w http.ResponseWriter, r *http.Request) {
}
//iterateProjects will iterate through every project in active, inactive and upcoming projects.
func
iterateProfiles
(
id
in
t
,
name
string
)
([]
*
firestore
.
DocumentRef
,
error
)
{
func
iterateProfiles
(
id
str
in
g
,
name
string
)
([]
*
firestore
.
DocumentRef
,
error
)
{
var
documentReferences
[]
*
firestore
.
DocumentRef
collection
:=
baseCollection
.
Collections
(
database
.
Ctx
)
...
...
@@ -490,7 +485,7 @@ func checkUpdate(update map[string]interface{}) bool {
}
fields
:=
[]
string
{
constants
.
U_name
,
constants
.
U_email
,
constants
.
U_admin
,
constants
.
U_employeeID
,
constants
.
U_phone
}
constants
.
U_email
,
constants
.
U_admin
,
constants
.
U_Role
,
constants
.
U_employeeID
,
constants
.
U_phone
}
if
employeeID
{
for
_
,
field
:=
range
fields
{
for
f
:=
range
update
{
...
...
@@ -553,7 +548,7 @@ func checkStruct(body []byte) bool {
return
false
}
_
,
idFormat
:=
userMap
[
constants
.
U_employeeID
]
.
(
float64
)
_
,
idFormat
:=
userMap
[
constants
.
U_employeeID
]
.
(
string
)
_
,
phoneFormat
:=
userMap
[
constants
.
U_phone
]
.
(
float64
)
roles
:=
[]
string
{
constants
.
U_Admin
,
constants
.
U_Installer
,
constants
.
U_Storage
}
var
roleFormat
bool
...
...
@@ -621,7 +616,7 @@ func checkDeleteBody(bytes []byte) bool {
}
for
_
,
m
:=
range
deleteID
{
//Checks that it is in the appropriate format
_
,
errDelete
:=
m
[
constants
.
U_idURL
]
.
(
float64
)
_
,
errDelete
:=
m
[
constants
.
U_idURL
]
.
(
string
)
if
!
errDelete
{
return
false
}
...
...
This diff is collapsed.
Click to expand it.
api/struct/ProfileStruct.go
+
2
−
2
View file @
18e91127
package
_struct
type
Employee
struct
{
EmployeeID
in
t
`json:"employeeID"`
EmployeeID
str
in
g
`json:"employeeID"`
Name
struct
{
FirstName
string
`json:"firstName"`
LastName
string
`json:"lastName"`
...
...
@@ -17,5 +17,5 @@ type Employee struct {
}
type
ProfileDelete
[]
struct
{
Id
in
t
`json:"id"`
Id
str
in
g
`json:"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