|
@ -179,6 +179,47 @@ func New(name, author, category string, listed, open bool, tags []Tag, createdDa |
|
|
return story, nil |
|
|
return story, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FindID finds a story by ID
|
|
|
|
|
|
func FindID(id string) (Story, error) { |
|
|
|
|
|
story := Story{} |
|
|
|
|
|
err := storyCollection.FindId(id).One(&story) |
|
|
|
|
|
|
|
|
|
|
|
return story, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// List lists stories by any non-zero criteria passed with it.
|
|
|
|
|
|
func List(author string, tags []Tag, earliest, latest time.Time, limit int) ([]Story, error) { |
|
|
|
|
|
query := bson.M{} |
|
|
|
|
|
|
|
|
|
|
|
if author != "" { |
|
|
|
|
|
query["author"] = author |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(tags) > 0 { |
|
|
|
|
|
query["tags"] = bson.M{"$in": tags} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !earliest.IsZero() && !latest.IsZero() { |
|
|
|
|
|
query["fictionalDate"] = bson.M{ |
|
|
|
|
|
"$gte": earliest, |
|
|
|
|
|
"$lt": latest, |
|
|
|
|
|
} |
|
|
|
|
|
} else if !latest.IsZero() { |
|
|
|
|
|
query["fictionalDate"] = bson.M{ |
|
|
|
|
|
"$lt": latest, |
|
|
|
|
|
} |
|
|
|
|
|
} else if !earliest.IsZero() { |
|
|
|
|
|
query["fictionalDate"] = bson.M{ |
|
|
|
|
|
"$gte": earliest, |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stories := make([]Story, 0, 128) |
|
|
|
|
|
err := storyCollection.Find(query).Limit(limit).One(&stories) |
|
|
|
|
|
|
|
|
|
|
|
return stories, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// makeStoryID makes a random story ID that's 16 characters long
|
|
|
// makeStoryID makes a random story ID that's 16 characters long
|
|
|
func makeStoryID() string { |
|
|
func makeStoryID() string { |
|
|
result := "S" |
|
|
result := "S" |
|
|