This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
routes_database.go
51 lines (47 loc) · 1.62 KB
/
routes_database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package v2
import (
"net/http"
"github.com/RTradeLtd/Temporal/eh"
"github.com/gin-gonic/gin"
)
// GetUploadsForUser is used to retrieve all uploads for the authenticated user
func (api *API) getUploadsForUser(c *gin.Context) {
username, err := GetAuthenticatedUserFromContext(c)
if err != nil {
api.LogError(c, err, eh.NoAPITokenError)(http.StatusBadRequest)
return
}
// fetch all uploads by the specified user
uploads, err := api.upm.GetUploadsForUser(username)
if err != nil {
api.LogError(c, err, eh.UploadSearchError)(http.StatusInternalServerError)
return
}
// log and return
api.l.Info("specific uploads from database requested")
Respond(c, http.StatusOK, gin.H{"response": uploads})
}
// getUploadsByNetworkName is used to get uploads for a network by its name
func (api *API) getUploadsByNetworkName(c *gin.Context) {
username, err := GetAuthenticatedUserFromContext(c)
if err != nil {
api.LogError(c, err, eh.NoAPITokenError)(http.StatusBadRequest)
return
}
// get network name to retrieve uploads from
networkName := c.Param("networkName")
// validate the user can access the network
if err := CheckAccessForPrivateNetwork(username, networkName, api.dbm.DB); err != nil {
api.LogError(c, err, eh.PrivateNetworkAccessError)(http.StatusBadRequest)
return
}
// find uploads for the network
uploads, err := api.upm.FindUploadsByNetwork(networkName)
if err != nil {
api.LogError(c, err, eh.UploadSearchError)(http.StatusInternalServerError)
return
}
// log and return
api.l.Infow("uploads forprivate ifps network requested", "user", username)
Respond(c, http.StatusOK, gin.H{"response": uploads})
}