feat: Sentinela v0.2.0 — Brazilian Financial Data API in Go
- 20 Go source files, single 16MB binary - SQLite + FTS5 full-text search (pure Go, no CGO) - BCB integration: Selic, CDI, IPCA, USD/BRL, EUR/BRL - CVM integration: 2,524 companies from registry - Fiber v2 REST API with 42 handlers - Auto-seeds on first run (~5s for BCB + CVM) - Token bucket rate limiter, optional API key auth - Periodic sync scheduler (configurable) - Graceful shutdown, structured logging (slog) - All endpoints tested with real data
This commit is contained in:
63
internal/api/handlers/companies.go
Normal file
63
internal/api/handlers/companies.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (h *Handler) ListCompanies(c *fiber.Ctx) error {
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
status := c.Query("status")
|
||||
sector := c.Query("sector")
|
||||
|
||||
companies, total, err := h.db.ListCompanies(limit, offset, status, sector)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"data": companies, "total": total, "limit": limit, "offset": offset})
|
||||
}
|
||||
|
||||
func (h *Handler) GetCompany(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "invalid id"})
|
||||
}
|
||||
company, err := h.db.GetCompany(id)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
if company == nil {
|
||||
return c.Status(404).JSON(fiber.Map{"error": "not found"})
|
||||
}
|
||||
return c.JSON(fiber.Map{"data": company})
|
||||
}
|
||||
|
||||
func (h *Handler) CompanyFilings(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "invalid id"})
|
||||
}
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
|
||||
filings, total, err := h.db.ListFilingsByCompany(id, limit, offset)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"data": filings, "total": total, "limit": limit, "offset": offset})
|
||||
}
|
||||
|
||||
func (h *Handler) SearchCompanies(c *fiber.Ctx) error {
|
||||
q := c.Query("q")
|
||||
if q == "" {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "query parameter 'q' required"})
|
||||
}
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
companies, err := h.db.SearchCompanies(q, limit)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"data": companies, "total": len(companies)})
|
||||
}
|
||||
Reference in New Issue
Block a user