2022-08-19 12:26:42 -06:00
|
|
|
package gql
|
2022-08-07 11:55:49 -06:00
|
|
|
|
2022-08-09 16:23:33 -06:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
|
2023-02-26 22:33:01 -07:00
|
|
|
"go.sour.is/ev/pkg/es/event"
|
2022-08-09 16:23:33 -06:00
|
|
|
)
|
2022-08-07 11:55:49 -06:00
|
|
|
|
|
|
|
type Edge interface {
|
|
|
|
IsEdge()
|
|
|
|
}
|
|
|
|
|
|
|
|
type Connection struct {
|
|
|
|
Paging *PageInfo `json:"paging"`
|
|
|
|
Edges []Edge `json:"edges"`
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:23:33 -06:00
|
|
|
type PostEvent struct {
|
2022-08-07 11:55:49 -06:00
|
|
|
ID string `json:"id"`
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Meta *event.Meta `json:"meta"`
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:23:33 -06:00
|
|
|
func (PostEvent) IsEdge() {}
|
|
|
|
|
|
|
|
func (e *PostEvent) PayloadJSON(ctx context.Context) (m map[string]interface{}, err error) {
|
|
|
|
err = json.Unmarshal([]byte(e.Payload), &m)
|
|
|
|
return
|
|
|
|
}
|
2022-08-07 11:55:49 -06:00
|
|
|
|
|
|
|
type PageInfo struct {
|
|
|
|
Next bool `json:"next"`
|
|
|
|
Prev bool `json:"prev"`
|
|
|
|
Begin uint64 `json:"begin"`
|
|
|
|
End uint64 `json:"end"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PageInput struct {
|
2022-10-25 20:15:57 -06:00
|
|
|
After *int64 `json:"after"`
|
|
|
|
Before *int64 `json:"before"`
|
|
|
|
Count *int64 `json:"count"`
|
2022-08-07 11:55:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PageInput) GetIdx(v int64) int64 {
|
2022-10-25 20:15:57 -06:00
|
|
|
if p == nil {
|
|
|
|
// pass
|
|
|
|
} else if p.Before != nil {
|
|
|
|
return (*p.Before)
|
|
|
|
} else if p.After != nil {
|
|
|
|
return *p.After
|
2022-08-07 11:55:49 -06:00
|
|
|
}
|
2022-10-25 20:15:57 -06:00
|
|
|
|
|
|
|
return v
|
2022-08-07 11:55:49 -06:00
|
|
|
}
|
|
|
|
func (p *PageInput) GetCount(v int64) int64 {
|
|
|
|
if p == nil || p.Count == nil {
|
|
|
|
return v
|
2022-10-25 20:15:57 -06:00
|
|
|
} else if p.Before != nil {
|
|
|
|
return -(*p.Count)
|
|
|
|
} else if p.After != nil {
|
|
|
|
return *p.Count
|
2022-08-07 11:55:49 -06:00
|
|
|
}
|
2022-10-25 20:15:57 -06:00
|
|
|
|
2022-08-07 11:55:49 -06:00
|
|
|
return *p.Count
|
|
|
|
}
|