Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(message): trigger buzzer #35

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading