diff --git a/cmd/server/main.go b/cmd/server/main.go index 4cd34c8..d983996 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -38,6 +38,7 @@ func main() { routes.CountriesRouter(app) routes.CampRouter(app) routes.KuromasuRouter(app) + routes.MemoryRouter(app) log.Fatal(app.Listen(":" + port)) } diff --git a/internal/handlers/memory.go b/internal/handlers/memory.go new file mode 100644 index 0000000..5f46c69 --- /dev/null +++ b/internal/handlers/memory.go @@ -0,0 +1,28 @@ +package handlers + +import ( + "github.com/cheatsnake/shadify/internal/helpers" + "github.com/cheatsnake/shadify/pkg/memory" + "github.com/gofiber/fiber/v2" +) + +const ( + memoryHeight int = 4 + memoryWidth int = 6 + memoryPairSize int = 3 + memoryShowPositions bool = true +) + +func MemoryGenerator(c *fiber.Ctx) error { + width := helpers.GetQueryInt(c, "width", memoryWidth) + height := helpers.GetQueryInt(c, "height", memoryHeight) + pairSize := helpers.GetQueryInt(c, "pair-size", memoryPairSize) + showPositions := helpers.GetQueryBool(c, "show-positions", memoryShowPositions) + + result, err := memory.Generate(width, height, pairSize, showPositions) + if err != nil { + return helpers.ThrowError(c, fiber.StatusBadRequest, err.Error()) + } + + return c.JSON(result) +} diff --git a/internal/routes/memory.go b/internal/routes/memory.go new file mode 100644 index 0000000..8a85099 --- /dev/null +++ b/internal/routes/memory.go @@ -0,0 +1,12 @@ +package routes + +import ( + "github.com/cheatsnake/shadify/internal/handlers" + "github.com/gofiber/fiber/v2" +) + +func MemoryRouter(app fiber.Router) { + prefix := "/api/memory" + + app.Get(prefix+"/generator", handlers.MemoryGenerator) +}