You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
// StoryCategory represents the category of a story.
|
|
type StoryCategory string
|
|
|
|
const (
|
|
// StoryCategoryInfo is a story category, see GraphQL documentation.
|
|
StoryCategoryInfo StoryCategory = "Info"
|
|
// StoryCategoryNews is a story category, see GraphQL documentation.
|
|
StoryCategoryNews StoryCategory = "News"
|
|
// StoryCategoryDocument is a story category, see GraphQL documentation.
|
|
StoryCategoryDocument StoryCategory = "Document"
|
|
// StoryCategoryBackground is a story category, see GraphQL documentation.
|
|
StoryCategoryBackground StoryCategory = "Background"
|
|
// StoryCategoryStory is a story category, see GraphQL documentation.
|
|
StoryCategoryStory StoryCategory = "Story"
|
|
)
|
|
|
|
// IsValid returns whether the category is one of the valid values.
|
|
func (e *StoryCategory) IsValid() bool {
|
|
switch *e {
|
|
case StoryCategoryInfo, StoryCategoryNews, StoryCategoryDocument, StoryCategoryBackground, StoryCategoryStory:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// UnmarshalGQL unmarshals
|
|
func (e *StoryCategory) UnmarshalGQL(v interface{}) error {
|
|
str, ok := v.(string)
|
|
if !ok {
|
|
return fmt.Errorf("enums must be strings")
|
|
}
|
|
|
|
if !e.IsValid() {
|
|
return fmt.Errorf("%s is not a valid StoryCategory", str)
|
|
}
|
|
|
|
*e = StoryCategory(str)
|
|
|
|
return nil
|
|
}
|
|
|
|
// MarshalGQL turns it into a JSON string
|
|
func (e StoryCategory) MarshalGQL(w io.Writer) {
|
|
fmt.Fprint(w, "\""+string(e)+"\"")
|
|
}
|