-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
100 lines (85 loc) · 3.83 KB
/
main.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"os"
"github.com/FrosTiK-SD/auth/constants"
"github.com/FrosTiK-SD/auth/controller"
"github.com/FrosTiK-SD/auth/handler"
"github.com/FrosTiK-SD/auth/util"
"github.com/FrosTiK-SD/mongik"
mongikConstants "github.com/FrosTiK-SD/mongik/constants"
mongikModels "github.com/FrosTiK-SD/mongik/models"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
r := gin.Default()
mongikClient := mongik.NewClient(os.Getenv(constants.CONNECTION_STRING), &mongikModels.Config{
Client: mongikConstants.REDIS,
TTL: constants.CACHING_DURATION,
RedisConfig: &mongikModels.RedisConfig{
URI: os.Getenv(constants.REDIS_URI),
Password: os.Getenv(constants.REDIS_PASSWORD),
Username: os.Getenv(constants.REDIS_USERNAME),
},
FallbackToDefault: true,
})
// Initialie default JWKs
defaultJwkSet, jwkSetRetrieveError := controller.GetJWKs(mongikClient.CacheClient, true)
if jwkSetRetrieveError != nil {
fmt.Println("Error retrieving JWKs")
}
r.Use(cors.New(util.DefaultCors()))
handler := &handler.Handler{
MongikClient: mongikClient,
JwkSet: defaultJwkSet,
Config: handler.Config{
Mode: handler.HANDLER,
},
Session: &handler.Session{},
}
token := r.Group("/api/token")
{
token.GET("/verify", handler.HandlerVerifyRecruiterIdToken)
token.GET("/student/verify", handler.HandlerVerifyStudentIdToken)
token.GET("/invalidate_cache", handler.InvalidateCache)
}
student := r.Group("/api/student")
{
student.GET("", handler.GinVerifyStudent, handler.GetRoleCheckHandlerForStudent(constants.ROLE_ADMIN), handler.GetAllStudents)
student.GET("/id", handler.GinVerifyStudent, handler.GetStudentById)
student.GET("/tpr/all", handler.GinVerifyStudent, handler.GetRoleCheckHandlerForStudent(constants.ROLE_ADMIN), handler.GetAllTprs)
student.GET("/tprLogin", handler.GinVerifyStudent, handler.GetRoleCheckHandlerForStudent(constants.ROLE_TPR), handler.HandlerTprLogin)
student.PUT("/update", handler.GinVerifyStudent, handler.HandlerUpdateStudentDetails)
student.GET("/profile", handler.GinVerifyStudent, handler.HandlerGetStudentProfile)
student.PUT("/profile", handler.GinVerifyStudent, handler.HandlerUpdateStudentProfile)
student.POST("/register", handler.HandlerRegisterStudentDetails)
}
group := r.Group("/api/group", handler.GinVerifyStudent)
{
group.GET("", handler.GetRoleCheckHandlerForStudent(constants.ROLE_GROUP_READ), handler.GetAllGroups)
group.POST("/batch", handler.GetRoleCheckHandlerForStudent(constants.ROLE_GROUP_CREATE), handler.BatchCreateGroup)
group.PUT("/batch/edit", handler.GetRoleCheckHandlerForStudent(constants.ROLE_GROUP_EDIT), handler.BatchEditGroup)
group.DELETE("/batch/delete", handler.GetRoleCheckHandlerForStudent(constants.ROLE_GROUP_DELETE), handler.BatchDeleteGroup)
group.POST("/batch/assign", handler.GetRoleCheckHandlerForStudent(constants.ROLE_GROUP_ASSIGN), handler.BatchAssignGroup)
}
domain := r.Group("/api/domain", handler.GinVerifyStudent)
{
domain.GET("", handler.GetRoleCheckHandlerForStudent(constants.ROLE_DOMAIN_ALL_READ), handler.GetAllDomains)
domain.GET("/id", handler.GetRoleCheckHandlerForStudent(constants.ROLE_DOMAIN_ALL_READ), handler.GetDomainById)
domain.POST("/batch", handler.GetRoleCheckHandlerForStudent(constants.ROLE_DOMAIN_CREATE), handler.BatchCreateDomain)
domain.PUT("/id", handler.GetRoleCheckHandlerForStudent(constants.ROLE_DOMAIN_EDIT), handler.EditDomainById)
domain.DELETE("/id", handler.GetRoleCheckHandlerForStudent(constants.ROLE_DOMAIN_DELETE), handler.DeleteDomainById)
}
companies := r.Group("/api/company", handler.GinVerifyStudent)
{
companies.GET("/all", handler.GetRoleCheckHandlerForStudent(constants.ROLE_COMPANY_ALL_READ), handler.GetAllCompanies)
}
port := "" + os.Getenv("PORT")
if port == "" {
port = "8080"
}
r.Run(":" + port)
}