From c877e4610702e03c71f23c649cc039be307286fa Mon Sep 17 00:00:00 2001 From: Topvennie Date: Tue, 10 Dec 2024 15:28:11 +0100 Subject: [PATCH] feat(message): trigger buzzer --- internal/api/api.go | 5 +++-- internal/api/message/message.go | 7 ++++++- internal/cmd/api.go | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 2097678..ab2b292 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -5,12 +5,13 @@ import ( "github.com/gofiber/fiber/v2" "github.com/zeusWPI/scc/internal/api/message" apiSong "github.com/zeusWPI/scc/internal/api/song" + "github.com/zeusWPI/scc/internal/pkg/buzzer" "github.com/zeusWPI/scc/internal/pkg/db" "github.com/zeusWPI/scc/internal/pkg/song" ) // New creates a new API instance -func New(router fiber.Router, db *db.DB, song *song.Song) { - message.New(router, db) +func New(router fiber.Router, db *db.DB, buzz *buzzer.Buzzer, song *song.Song) { + message.New(router, db, buzz) apiSong.New(router, db, song) } diff --git a/internal/api/message/message.go b/internal/api/message/message.go index 9861569..fc663c2 100644 --- a/internal/api/message/message.go +++ b/internal/api/message/message.go @@ -3,6 +3,7 @@ package message import ( "github.com/gofiber/fiber/v2" + "github.com/zeusWPI/scc/internal/pkg/buzzer" "github.com/zeusWPI/scc/internal/pkg/db" "github.com/zeusWPI/scc/internal/pkg/db/dto" "github.com/zeusWPI/scc/pkg/util" @@ -13,13 +14,15 @@ import ( type Router struct { router fiber.Router db *db.DB + buzz *buzzer.Buzzer } // New creates a new message API instance -func New(router fiber.Router, db *db.DB) *Router { +func New(router fiber.Router, db *db.DB, buzz *buzzer.Buzzer) *Router { api := &Router{ router: router.Group("/messages"), db: db, + buzz: buzz, } api.createRoutes() @@ -60,5 +63,7 @@ func (r *Router) create(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusInternalServerError) } + r.buzz.Play() + return c.Status(fiber.StatusCreated).JSON(dto.MessageDTO(messageDB)) } diff --git a/internal/cmd/api.go b/internal/cmd/api.go index 1c70276..52f2803 100644 --- a/internal/cmd/api.go +++ b/internal/cmd/api.go @@ -7,6 +7,7 @@ import ( "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" "github.com/zeusWPI/scc/internal/api" + "github.com/zeusWPI/scc/internal/pkg/buzzer" "github.com/zeusWPI/scc/internal/pkg/db" "github.com/zeusWPI/scc/internal/pkg/song" "github.com/zeusWPI/scc/pkg/config" @@ -28,8 +29,10 @@ func API(db *db.DB, song *song.Song) { }), ) + buzz := buzzer.New() + apiGroup := app.Group("/api") - api.New(apiGroup, db, song) + api.New(apiGroup, db, buzz, song) host := config.GetDefaultString("server.host", "localhost") port := config.GetDefaultInt("server.port", 3000)