feat: add get integrations endpoint
This commit is contained in:
parent
e526bb8122
commit
cfe4ac9eb2
@ -122,6 +122,15 @@ func (db *DeviceDatabase) CreateIntegration(name, token string) (string, error)
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (db *DeviceDatabase) GetIntegration(id string) (*Integration, error) {
|
||||
var integration Integration
|
||||
err := db.Connection.QueryRow("SELECT id, name FROM integrations WHERE id = ?", id).Scan(&integration.ID, &integration.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &integration, nil
|
||||
}
|
||||
|
||||
func (db *DeviceDatabase) GetIntegrations() ([]Integration, error) {
|
||||
var integrations []Integration
|
||||
|
||||
|
||||
@ -125,6 +125,14 @@ func (um *DeviceManager) CreateIntegration(name, code string) (d.Integration, er
|
||||
return integration, nil
|
||||
}
|
||||
|
||||
func (um *DeviceManager) GetIntegration(id string) (*d.Integration, error) {
|
||||
integration, err := um.deviceDatabase.GetIntegration(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return integration, nil
|
||||
}
|
||||
|
||||
func (um *DeviceManager) GetIntegrations() ([]d.Integration, error) {
|
||||
integrations, err := um.deviceDatabase.GetIntegrations()
|
||||
if err != nil {
|
||||
|
||||
@ -27,6 +27,7 @@ func (r *DeviceApiHandler) Initialize(authenticator *Authenticator) {
|
||||
integrationsApi.GET("/register", r.handleIntegrationRegistration)
|
||||
integrationsApi.POST("", r.handleCreateIntegration)
|
||||
integrationsApi.GET("", r.handleGetIntegrations)
|
||||
integrationsApi.GET("/:id", r.handleGetIntegration)
|
||||
}
|
||||
|
||||
func (r *DeviceApiHandler) handleIntegrationRegistration(context echo.Context) error {
|
||||
@ -65,7 +66,38 @@ func (r *DeviceApiHandler) handleCreateIntegration(context echo.Context) error {
|
||||
return error
|
||||
}
|
||||
|
||||
return context.JSON(200, integration)
|
||||
integrationData := struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Token string `json:"token"`
|
||||
}{
|
||||
ID: integration.ID,
|
||||
Name: integration.Name,
|
||||
Token: integration.Token,
|
||||
}
|
||||
|
||||
return context.JSON(200, integrationData)
|
||||
}
|
||||
|
||||
func (r *DeviceApiHandler) handleGetIntegration(context echo.Context) error {
|
||||
id := context.Param("id")
|
||||
|
||||
integration, error := r.deviceManager.GetIntegration(id)
|
||||
|
||||
if error != nil {
|
||||
SendError(500, context, fmt.Sprintf("Failed to get integration: %s", error))
|
||||
return error
|
||||
}
|
||||
|
||||
integrationData := struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}{
|
||||
ID: integration.ID,
|
||||
Name: integration.Name,
|
||||
}
|
||||
|
||||
return context.JSON(200, integrationData)
|
||||
}
|
||||
|
||||
func (r *DeviceApiHandler) handleGetIntegrations(context echo.Context) error {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user