Skip to content

Commit

Permalink
feat(message): trigger buzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Dec 10, 2024
1 parent d178e49 commit f5e7f43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 6 additions & 1 deletion internal/api/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand Down Expand Up @@ -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))
}
5 changes: 4 additions & 1 deletion internal/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down

0 comments on commit f5e7f43

Please sign in to comment.