This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// TagKind represents the kind of tags.
|
||||
type TagKind string
|
||||
|
||||
const (
|
||||
// TagKindOrganization is a tag kind, see GraphQL documentation.
|
||||
TagKindOrganization TagKind = "Organization"
|
||||
|
||||
// TagKindCharacter is a tag kind, see GraphQL documentation.
|
||||
TagKindCharacter TagKind = "Character"
|
||||
|
||||
// TagKindLocation is a tag kind, see GraphQL documentation.
|
||||
TagKindLocation TagKind = "Location"
|
||||
|
||||
// TagKindEvent is a tag kind, see GraphQL documentation.
|
||||
TagKindEvent TagKind = "Event"
|
||||
|
||||
// TagKindSeries is a tag kind, see GraphQL documentation.
|
||||
TagKindSeries TagKind = "Series"
|
||||
)
|
||||
|
||||
// UnmarshalGQL unmarshals
|
||||
func (e *TagKind) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = TagKind(str)
|
||||
switch *e {
|
||||
case TagKindOrganization, TagKindCharacter, TagKindLocation, TagKindEvent, TagKindSeries:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("%s is not a valid TagKind", str)
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalGQL turns it into a JSON string
|
||||
func (e TagKind) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, "\""+string(e), "\"")
|
||||
}
|
||||
+52
-1
@@ -1,5 +1,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// A Tag associates a story with other content, like other stories, logs and more.
|
||||
type Tag struct {
|
||||
Kind TagKind `bson:"kind"`
|
||||
@@ -15,4 +20,50 @@ func (tag *Tag) Equal(other Tag) bool {
|
||||
// ChangeObject in GQL.
|
||||
func (*Tag) IsChangeObject() {
|
||||
panic("this method is a dummy, and so is its caller")
|
||||
}
|
||||
}
|
||||
|
||||
// TagKind represents the kind of tags.
|
||||
type TagKind string
|
||||
|
||||
const (
|
||||
// TagKindOrganization is a tag kind, see GraphQL documentation.
|
||||
TagKindOrganization TagKind = "Organization"
|
||||
|
||||
// TagKindCharacter is a tag kind, see GraphQL documentation.
|
||||
TagKindCharacter TagKind = "Character"
|
||||
|
||||
// TagKindLocation is a tag kind, see GraphQL documentation.
|
||||
TagKindLocation TagKind = "Location"
|
||||
|
||||
// TagKindEvent is a tag kind, see GraphQL documentation.
|
||||
TagKindEvent TagKind = "Event"
|
||||
|
||||
// TagKindSeries is a tag kind, see GraphQL documentation.
|
||||
TagKindSeries TagKind = "Series"
|
||||
)
|
||||
|
||||
// UnmarshalGQL unmarshals
|
||||
func (e *TagKind) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = TagKind(str)
|
||||
switch *e {
|
||||
case TagKindOrganization, TagKindCharacter, TagKindLocation, TagKindEvent, TagKindSeries:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("%s is not a valid TagKind", str)
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalGQL turns it into a JSON string
|
||||
func (e TagKind) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, "\""+string(e), "\"")
|
||||
}
|
||||
|
||||
// TagFilter is a filter of tags.
|
||||
type TagFilter struct {
|
||||
Kind *TagKind `bson:"kind,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user