2fas-server/internal/api/browser_extension/app/query/browser_extension_query.go

33 lines
756 B
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package query
import (
"gorm.io/gorm"
)
type BrowserExtensionPresenter struct {
Id string `json:"id"`
Name string `json:"name"`
BrowserName string `json:"browser_name"`
BrowserVersion string `json:"browser_version"`
}
type BrowserExtensionQuery struct {
Id string `uri:"extension_id" validate:"required,uuid4"`
}
type BrowserExtensionQueryHandler struct {
Database *gorm.DB
}
func (h *BrowserExtensionQueryHandler) Handle(query *BrowserExtensionQuery) (*BrowserExtensionPresenter, error) {
var presenter *BrowserExtensionPresenter
result := h.Database.Raw("SELECT * FROM browser_extensions WHERE id = ?", query.Id).First(&presenter)
if result.Error != nil {
return nil, result.Error
}
return presenter, nil
}