2023-09-21 16:43:11 +01:00
|
|
|
package utils
|
2023-09-19 13:39:59 +01:00
|
|
|
|
2023-09-21 15:38:02 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2024-04-14 14:51:16 +01:00
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
|
2023-09-21 15:38:02 +01:00
|
|
|
)
|
2023-09-19 13:39:59 +01:00
|
|
|
|
2024-03-09 10:52:08 +00:00
|
|
|
func GetIdFromUrl(c *Context, target string) (string, error) {
|
|
|
|
if !c.R.URL.Query().Has(target) {
|
2024-02-08 18:20:58 +00:00
|
|
|
return "", errors.New("Query does not have " + target)
|
2023-09-21 15:38:02 +01:00
|
|
|
}
|
|
|
|
|
2024-03-09 10:52:08 +00:00
|
|
|
id := c.R.URL.Query().Get("id")
|
2023-09-21 15:38:02 +01:00
|
|
|
if len(id) == 0 {
|
2024-02-08 18:20:58 +00:00
|
|
|
return "", errors.New("Query is empty for " + target)
|
2023-09-21 15:38:02 +01:00
|
|
|
}
|
|
|
|
|
2023-09-21 16:43:11 +01:00
|
|
|
if !IsValidUUID(id) {
|
2024-02-08 18:20:58 +00:00
|
|
|
return "", errors.New("Value of query is not a valid uuid for " + target)
|
2023-09-21 15:38:02 +01:00
|
|
|
}
|
|
|
|
|
2024-02-08 18:20:58 +00:00
|
|
|
return id, nil
|
2023-09-21 15:38:02 +01:00
|
|
|
}
|