feat: send proper status when integration not found
This commit is contained in:
parent
a13a21a67d
commit
0ade58d2f2
@ -122,6 +122,15 @@ func (db *DeviceDatabase) CreateIntegration(name, token string) (string, error)
|
|||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DeviceDatabase) IntegrationIdExists(id string) (bool, error) {
|
||||||
|
var exists bool
|
||||||
|
err := db.Connection.QueryRow("SELECT EXISTS(SELECT 1 FROM integrations WHERE id = ?)", id).Scan(&exists)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return exists, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (db *DeviceDatabase) GetIntegration(id string) (*Integration, error) {
|
func (db *DeviceDatabase) GetIntegration(id string) (*Integration, error) {
|
||||||
var integration Integration
|
var integration Integration
|
||||||
err := db.Connection.QueryRow("SELECT id, name FROM integrations WHERE id = ?", id).Scan(&integration.ID, &integration.Name)
|
err := db.Connection.QueryRow("SELECT id, name FROM integrations WHERE id = ?", id).Scan(&integration.ID, &integration.Name)
|
||||||
|
|||||||
@ -146,6 +146,14 @@ func (dm *DeviceManager) DeleteIntegration(id string) error {
|
|||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dm *DeviceManager) IntegrationIdExists(id string) (bool, error) {
|
||||||
|
exists, error := dm.deviceDatabase.IntegrationIdExists(id)
|
||||||
|
if error != nil {
|
||||||
|
return false, error
|
||||||
|
}
|
||||||
|
return exists, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (dm *DeviceManager) checkCode(code string) bool {
|
func (dm *DeviceManager) checkCode(code string) bool {
|
||||||
for _, c := range dm.registrationCodes {
|
for _, c := range dm.registrationCodes {
|
||||||
if c == code {
|
if c == code {
|
||||||
|
|||||||
@ -83,11 +83,21 @@ func (r *DeviceApiHandler) handleCreateIntegration(context echo.Context) error {
|
|||||||
func (r *DeviceApiHandler) handleGetIntegration(context echo.Context) error {
|
func (r *DeviceApiHandler) handleGetIntegration(context echo.Context) error {
|
||||||
id := context.Param("id")
|
id := context.Param("id")
|
||||||
|
|
||||||
integration, error := r.deviceManager.GetIntegration(id)
|
exists, err := r.deviceManager.IntegrationIdExists(id)
|
||||||
|
if err != nil {
|
||||||
|
SendError(500, context, fmt.Sprintf("Failed to get integration: %s", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
SendError(404, context, fmt.Sprintf("integration with id %s does not exist", id))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if error != nil {
|
integration, err := r.deviceManager.GetIntegration(id)
|
||||||
SendError(500, context, fmt.Sprintf("Failed to get integration: %s", error))
|
|
||||||
return error
|
if err != nil {
|
||||||
|
SendError(500, context, fmt.Sprintf("Failed to get integration: %s", err))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
integrationData := struct {
|
integrationData := struct {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user