List lists all tools
(c *gin.Context)
| 93 | |
| 94 | // List lists all tools |
| 95 | func (h *ToolHandler) List(c *gin.Context) { |
| 96 | ctx := c.Request.Context() |
| 97 | status := c.Query("status") |
| 98 | toolType := c.Query("type") |
| 99 | |
| 100 | records, err := (*h.store).List(ctx, "tools") |
| 101 | if err != nil { |
| 102 | c.JSON(http.StatusInternalServerError, gin.H{ |
| 103 | "success": false, |
| 104 | "error": gin.H{ |
| 105 | "code": "internal_error", |
| 106 | "message": err.Error(), |
| 107 | }, |
| 108 | }) |
| 109 | return |
| 110 | } |
| 111 | |
| 112 | tools := make([]*ToolRecord, 0) |
| 113 | for _, record := range records { |
| 114 | var tool ToolRecord |
| 115 | if err := store.DecodeValue(record, &tool); err != nil { |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | // Filter |
| 120 | if status != "" && tool.Status != status { |
| 121 | continue |
| 122 | } |
| 123 | if toolType != "" && tool.Type != toolType { |
| 124 | continue |
| 125 | } |
| 126 | |
| 127 | tools = append(tools, &tool) |
| 128 | } |
| 129 | |
| 130 | c.JSON(http.StatusOK, gin.H{ |
| 131 | "success": true, |
| 132 | "data": tools, |
| 133 | }) |
| 134 | } |
| 135 | |
| 136 | // Get retrieves a single tool |
| 137 | func (h *ToolHandler) Get(c *gin.Context) { |