phoenix/main.go

62 lines
1.2 KiB
Go
Raw Normal View History

2023-04-06 10:36:11 +05:00
package main
import (
"github.com/gin-gonic/gin"
"github.com/ordinary-dev/phoenix/backend"
"github.com/ordinary-dev/phoenix/views"
"log"
)
func main() {
db, err := backend.GetDatabaseConnection()
if err != nil {
log.Fatal(err)
}
r := gin.Default()
r.LoadHTMLGlob("templates/*")
r.Static("/assets", "./assets")
2023-04-06 10:37:48 +05:00
// Main page
2023-04-06 10:36:11 +05:00
r.GET("/", func(c *gin.Context) {
2023-04-09 11:22:48 +05:00
views.ShowMainPage(c, db)
2023-04-06 10:37:48 +05:00
})
r.GET("/settings", func(c *gin.Context) {
2023-04-09 11:22:48 +05:00
views.ShowSettings(c, db)
2023-04-06 10:36:11 +05:00
})
2023-04-06 10:37:48 +05:00
// Create new user
2023-04-06 10:36:11 +05:00
r.POST("/users", func(c *gin.Context) {
2023-04-09 11:22:48 +05:00
views.CreateUser(c, db)
})
2023-04-06 10:36:11 +05:00
2023-04-09 11:22:48 +05:00
r.POST("/signin", func(c *gin.Context) {
views.AuthorizeUser(c, db)
2023-04-06 10:36:11 +05:00
})
2023-04-06 10:37:48 +05:00
// Create new group
2023-04-06 10:36:11 +05:00
r.POST("/groups", func(c *gin.Context) {
2023-04-09 11:22:48 +05:00
views.CreateGroup(c, db)
2023-04-06 10:36:11 +05:00
})
2023-04-06 10:37:48 +05:00
// Create new link
2023-04-06 10:36:11 +05:00
r.POST("/links", func(c *gin.Context) {
2023-04-09 11:22:48 +05:00
views.CreateLink(c, db)
2023-04-06 10:36:11 +05:00
})
2023-04-09 11:22:48 +05:00
// Update link.
// HTML forms cannot be submitted using PUT or PATCH methods without javascript.
2023-04-06 10:37:48 +05:00
r.POST("/links/:id/put", func(c *gin.Context) {
2023-04-09 11:22:48 +05:00
views.UpdateLink(c, db)
2023-04-06 10:36:11 +05:00
})
2023-04-06 10:37:48 +05:00
// Delete link
2023-04-09 11:22:48 +05:00
// HTML forms cannot be submitted using the DELETE method without javascript.
2023-04-06 10:37:48 +05:00
r.POST("/links/:id/delete", func(c *gin.Context) {
2023-04-09 11:22:48 +05:00
views.DeleteLink(c, db)
2023-04-06 10:36:11 +05:00
})
r.Run()
}