File uploads, mostly. Also added extra behavior to addCharacter.
the build was successful

This commit is contained in:
2019-08-31 22:46:55 +02:00
parent 8a313b3bb2
commit c8ced52e1a
17 changed files with 175 additions and 25 deletions
+1
View File
@@ -24,6 +24,7 @@ type Database interface {
Comments() repositories.CommentRepository
Keys() repositories.KeyRepository
Users() repositories.UserRepository
Files() repositories.FileRepository
Close(ctx context.Context) error
}
+31
View File
@@ -77,6 +77,37 @@ func (r *characterRepository) FindNick(ctx context.Context, nick string) (*model
return character, nil
}
func (r *characterRepository) FindName(ctx context.Context, name string) (*models.Character, error) {
query := bson.M{
"$or": []bson.M{
{"shortName": name},
{"name": name},
},
}
// Look for all characters matching query
characters := make([]*models.Character, 0, 8)
err := r.characters.Find(query).All(&characters)
if err != nil {
if err == mgo.ErrNotFound {
return nil, repositories.ErrNotFound
}
return nil, err
} else if len(characters) == 0 {
return nil, repositories.ErrNotFound
}
// Prioritize exact match
for _, character := range characters {
if character.Name == name {
return character, nil
}
}
return characters[0], nil
}
func (r *characterRepository) List(ctx context.Context, filter models.CharacterFilter) ([]*models.Character, error) {
query := bson.M{}
if filter.Author != nil {