Files
browser/platform/dto/plugin_data.go
T

56 lines
1.9 KiB
Go

package dto
import (
"time"
"browser.local/platform/domain"
)
type PluginDataPutRequest struct {
Key string `json:"key"`
Value map[string]any `json:"value"`
}
type PluginDataMutationBody struct {
Operation string `json:"operation"`
Key string `json:"key"`
Value map[string]any `json:"value,omitempty"`
}
type PluginDataTransactionRequest struct {
Mutations []PluginDataMutationBody `json:"mutations"`
}
func (request PluginDataTransactionRequest) ToDomain(pluginID, serverInstanceID, collection string) domain.PluginDataTransaction {
mutations := make([]domain.PluginDataMutation, len(request.Mutations))
for index, mutation := range request.Mutations {
mutations[index] = domain.PluginDataMutation{Operation: domain.PluginDataMutationOperation(mutation.Operation), Key: mutation.Key, Value: mutation.Value}
}
return domain.PluginDataTransaction{PluginID: pluginID, ServerInstanceID: serverInstanceID, Collection: collection, Mutations: mutations}
}
type PluginDataRecordResponse struct {
Key string `json:"key"`
Value map[string]any `json:"value"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type PluginDataListResponse struct {
Items []PluginDataRecordResponse `json:"items"`
Count int `json:"count"`
}
func PluginDataRecordFromDomain(value domain.PluginDataRecord) PluginDataRecordResponse {
value = domain.CopyPluginDataRecord(value)
return PluginDataRecordResponse{Key: value.Key, Value: value.Value, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt}
}
func PluginDataRecordsFromDomain(values []domain.PluginDataRecord) PluginDataListResponse {
items := make([]PluginDataRecordResponse, len(values))
for index, value := range values {
items[index] = PluginDataRecordFromDomain(value)
}
return PluginDataListResponse{Items: items, Count: len(items)}
}