api: Update graphql schema

This commit is contained in:
Kevin Kandlbinder 2022-03-24 16:35:45 +01:00
parent 39f721101e
commit 4f587820d1
9 changed files with 578 additions and 200 deletions

View file

@ -10,6 +10,7 @@ import (
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"regexp"
"time"
)
@ -235,7 +236,12 @@ func GetUserByID(id primitive.ObjectID) (*model.DBUser, error) {
func GetUserByUsername(username string) (*model.DBUser, error) {
db := DbClient.Database(viper.GetString("bot.mongo.database"))
res := db.Collection(viper.GetString("bot.mongo.collection.users")).FindOne(context.TODO(), bson.D{{"username", username}})
regexPattern := "^" + regexp.QuoteMeta(username) + "$"
res := db.Collection(viper.GetString("bot.mongo.collection.users")).FindOne(context.TODO(), bson.D{{"username", primitive.Regex{
Pattern: regexPattern,
Options: "i",
}}})
if res.Err() != nil {
return nil, res.Err()
}

View file

@ -15,3 +15,24 @@ type DBEntry struct {
AddedBy *primitive.ObjectID `bson:"added_by" json:"added_by"` // AddedBy is a reference to the user who added this
Comments []*DBComment `bson:"comments" json:"comments"` // Comments regarding this entry
}
func (entry *DBEntry) AddTo(id *primitive.ObjectID) {
for _, addedTo := range entry.PartOf {
if addedTo.Hex() == id.Hex() {
return
}
}
entry.PartOf = append(entry.PartOf, id)
}
func (entry *DBEntry) RemoveFrom(id *primitive.ObjectID) {
for i, addedTo := range entry.PartOf {
if addedTo.Hex() == id.Hex() {
entry.PartOf = append(entry.PartOf[:i], entry.PartOf[i+1:]...)
return
}
}
return
}

View file

@ -7,5 +7,6 @@ type DBHashList struct {
Name string `bson:"name" json:"name"`
Tags []string `bson:"tags" json:"tags"` // Tags of this list for discovery, and sorting
Comments []*DBComment `bson:"comments" json:"comments"` // Comments regarding this list
Creator primitive.ObjectID `bson:"creator" json:"creator"` // Creator of the list
Maintainers []*primitive.ObjectID `bson:"maintainers" json:"maintainers"` // Maintainers contains references to the users who may edit this list
}