diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c69e394 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "src/main.go" + } + ] +} \ No newline at end of file diff --git a/src/app/controller/webhook_controller.go b/src/app/controller/webhook_controller.go new file mode 100644 index 0000000..8617d2a --- /dev/null +++ b/src/app/controller/webhook_controller.go @@ -0,0 +1,15 @@ +package controller + +import ( + "github.com/gofiber/fiber/v2" + "ulmer-furs.de/pretix-proxy/v2/entities" +) + +func PostPretix(c *fiber.Ctx) error { + data := new(entities.Pretix_Webhook) + if err := c.BodyParser(data); err != nil { + return c.Status(fiber.ErrBadRequest.Code).SendString(err.Error()) + } + //TODO: Update attendies from pretix + return c.SendStatus(fiber.StatusOK) +} diff --git a/src/app/routes/public_routes.go b/src/app/routes/public_routes.go index 157df84..13b237f 100644 --- a/src/app/routes/public_routes.go +++ b/src/app/routes/public_routes.go @@ -8,6 +8,8 @@ import ( func PublicRoutes(app *fiber.App) { apiv1 := app.Group("/api/v1/public") attendies := apiv1.Group("/attendies") + webhooks := apiv1.Group("/webhooks") + webhooks.Post("/pretix", controller.PostPretix) apiv1.Post("/login", controller.LoginUser) apiv1.Get("/event", controller.ReturnAllEventsPublic) apiv1.Get("/ping", controller.Ping) diff --git a/src/config/database.go b/src/config/database.go index 1096da1..6611c74 100644 --- a/src/config/database.go +++ b/src/config/database.go @@ -16,7 +16,7 @@ func Connect() error { panic(err) } - Database.AutoMigrate(&entities.Db_Event{}, &entities.User{}) + Database.AutoMigrate(&entities.Db_Event{}, &entities.Db_Attendies{}, &entities.User{}) return nil } diff --git a/src/entities/db_attendies.go b/src/entities/db_attendies.go new file mode 100644 index 0000000..71bb9d8 --- /dev/null +++ b/src/entities/db_attendies.go @@ -0,0 +1,15 @@ +package entities + +import "gorm.io/gorm" + +type Db_Attendies struct { + gorm.Model + Nickname string `gorm:"column:nickname;not null"` + Event Db_Event `gorm:"column:event_id;not null"` + IsSuiter bool `grom:"column:is_suiter;not null"` + IsGuest bool `gorm:"column:is_guest;not null"` + IsSpotter bool `gorm:"column:is_spotter;not null"` + IsPhotograph bool `gorm:"column:is_photograph;not null"` + IsSpecialAnimal bool `gorm:"column:is_special_animal;not null"` + IsPublic bool `gorm:"column:is_public;not null"` +} diff --git a/src/entities/webhooks.go b/src/entities/webhooks.go new file mode 100644 index 0000000..a0960e0 --- /dev/null +++ b/src/entities/webhooks.go @@ -0,0 +1,9 @@ +package entities + +type Pretix_Webhook struct { + NotificationId int `json:"notification_id"` + Organizer string `json:"organizer"` + Event string `json:"event"` + Code string `json:"code"` + Action string `json:"action"` +} diff --git a/src/go.mod b/src/go.mod index c6ac959..9a0fb32 100644 --- a/src/go.mod +++ b/src/go.mod @@ -4,8 +4,12 @@ go 1.19 require ( github.com/go-playground/validator/v10 v10.15.4 + github.com/gofiber/contrib/jwt v1.0.7 github.com/gofiber/fiber/v2 v2.51.0 + github.com/golang-jwt/jwt/v5 v5.1.0 + github.com/jinzhu/copier v0.4.0 github.com/joho/godotenv v1.5.1 + golang.org/x/crypto v0.15.0 gorm.io/driver/sqlite v1.5.3 gorm.io/gorm v1.25.4 ) @@ -15,11 +19,7 @@ require ( github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/gofiber/contrib/jwt v1.0.7 // indirect - github.com/golang-jwt/jwt/v5 v5.1.0 // indirect - github.com/jinzhu/copier v0.4.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect - golang.org/x/crypto v0.15.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/text v0.14.0 // indirect )