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.
		
		
		
		
		
			
		
			
				
					
					
						
							69 lines
						
					
					
						
							1.7 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							69 lines
						
					
					
						
							1.7 KiB
						
					
					
				
								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"`
							 | 
						|
									Name string  `bson:"name"`
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								// Equal returns true if the tags match one another.
							 | 
						|
								func (tag *Tag) Equal(other Tag) bool {
							 | 
						|
									return tag.Kind == other.Kind && tag.Name == other.Name
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								// IsChangeObject is an interface implementation to identify it as a valid
							 | 
						|
								// 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 for tag listing.
							 | 
						|
								type TagFilter struct {
							 | 
						|
									Kind *TagKind `bson:"kind,omitempty"`
							 | 
						|
								}
							 |