This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontOrganizationsHandler.go
81 lines (67 loc) · 1.88 KB
/
frontOrganizationsHandler.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package routes
import (
"fmt"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/oswee/os/models"
"github.com/oswee/os/utils"
)
func frontOrganizationsHandler(r *mux.Router) {
r.HandleFunc("/organizations", organizationsMainHandler).Methods("GET")
r.HandleFunc("/organizations/{id:[0-9]+}", getOrganization).Methods("GET")
}
// Handlers
func organizationsMainHandler(w http.ResponseWriter, r *http.Request) {
visibility := 1
applications, err := models.ListApplications(visibility)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Error: 001, Internal Server Error"))
return
}
organizations, err := models.ListOrganizations()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Error: 001, Internal Server Error"))
return
}
utils.ExecuteTemplate(w, "mod-organizations.html", struct {
Title string
Apps []models.Application
Orgs []models.Organization
}{
Title: "Oswee.com: Organizations",
Apps: applications,
Orgs: organizations,
})
}
func getOrganization(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
orgID := vars["id"]
t := time.Now()
ts := t.Format("2006-01-02 15:04:05")
fmt.Println("Org. ID:", orgID, "IP:", r.Header.Get("X-Forwarded-For"), "Time:", ts)
visibility := 1
applications, err := models.ListApplications(visibility)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Error: 001, Internal Server Error"))
return
}
organizations, err := models.GetOrganization(orgID)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Error: 001, Internal Server Error"))
return
}
utils.ExecuteTemplate(w, "mod-organization-profile.html", struct {
Title string
Apps []models.Application
Orgs []models.Organization
}{
Title: "Oswee.com: Organization",
Apps: applications,
Orgs: organizations,
})
}