🔧 fix(handlers_web.go): fix typo in handleAttribute function name

 feat(handlers_web.go): add new route handlers for /point/:id and /attr/:id endpoints to handle attribute requests
This commit is contained in:
pluja 2023-10-31 00:03:57 +01:00
parent 0f745c1a25
commit ae8534a693
2 changed files with 18 additions and 0 deletions

View File

@ -114,6 +114,22 @@ func (s *Server) handleService(c *fiber.Ctx) error {
}, "base")
}
func (s *Server) handleAttribute(c *fiber.Ctx) error {
attributeId := strings.ToLower(c.Params("id"))
// Get service from database by name
attribute := database.ServiceAttributes.GetAttribute(attributeId)
// Get all services that have this attribute
services := database.Client.Service.Query().Where(service.AttributesContains(attributeId)).Where(service.Pending(false), service.Listed(true)).AllX(context.Background())
return c.Render("attribute", fiber.Map{
"Title": fmt.Sprintf("%v | Attribute", attribute.ID),
"Attribute": attribute,
"Services": services,
}, "base")
}
func (s *Server) handleRequestServiceForm(c *fiber.Ctx) error {
challenge, id, difficulty, err := s.PowChallenger.PowGenerateChallenge(16)
if err != nil {

View File

@ -83,6 +83,8 @@ func (s *Server) RegisterRoutes() {
// Register HTTP route for getting initial state.
s.Router.Get("/", s.handleIndex)
s.Router.Get("/service/:name", s.handleService)
s.Router.Get("/point/:id", s.handleAttribute)
s.Router.Get("/attr/:id", s.handleAttribute)
s.Router.Get("/request/service", s.handleRequestServiceForm)
s.Router.Post("/request/service", s.handleRequestServicePostForm)