-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.go
92 lines (85 loc) · 2.91 KB
/
schemas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
var UsersCollectionSchema = bson.M{
"required": []string{"username", "email", "password", "salt", "todos", "lastEdited"},
"properties": bson.M{
"username": bson.M{
"bsonType": "string",
"minLength": 4,
"maxLength": 16,
"pattern": "^[a-zA-Z0-9_]{4,16}$",
},
"password": bson.M{
"bsonType": "string",
"minLength": 16,
},
"salt": bson.M{
"bsonType": "string",
"minLength": 16,
},
"email": bson.M{
"bsonType": "string",
"minLength": 4,
"maxLength": 254,
"pattern": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$",
},
"verified": bson.M{
"bsonType": "string",
"minLength": 16,
},
"lastEdited": bson.M{"bsonType": "date"},
"todos": bson.M{
"bsonType": "array",
"items": bson.M{
"bsonType": "object",
"required": []string{"id", "name", "description", "done", "repeating", "createdAt", "updatedAt"},
"properties": bson.M{
"id": bson.M{"bsonType": "objectId"},
"name": bson.M{"bsonType": "string", "minLength": 1},
"description": bson.M{"bsonType": "string"},
"done": bson.M{"bsonType": "boolean"},
"createdAt": bson.M{"bsonType": "date"},
"updatedAt": bson.M{"bsonType": "date"},
"repeating": bson.M{"bsonType": "string", "enum": []string{"", "daily", "weekly", "monthly", "yearly"}},
"dueDate": bson.M{"bsonType": "date"},
},
},
},
},
}
type UserDocument struct {
Username string `json:"username" bson:"username"`
Password string `json:"password" bson:"password"`
Salt string `json:"salt" bson:"salt"`
Email string `json:"email" bson:"email"`
Verified string `json:"verified" bson:"verified"`
LastEdited time.Time `json:"lastEdited" bson:"lastEdited"`
Todos []TodoDocument `json:"todos" bson:"todos"`
}
type TodoDocument struct {
ID primitive.ObjectID `json:"id" bson:"id"`
Name string `json:"name" bson:"name"`
Description string `json:"description" bson:"description"`
Done bool `json:"done" bson:"done"`
Repeating string `json:"repeating" bson:"repeating"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
DueDate time.Time `json:"dueDate" bson:"dueDate"`
}
var TokensCollectionSchema = bson.M{
"required": []string{"username", "token", "issuedOn"},
"properties": bson.M{
"token": bson.M{"bsonType": "string", "minLength": 42},
"username": bson.M{"bsonType": "string", "minLength": 4},
"issuedOn": bson.M{"bsonType": "date"},
},
}
type TokenDocument struct {
Username string `json:"username" bson:"username"`
IssuedOn time.Time `json:"issuedOn" bson:"issuedOn"`
Token string `json:"token" bson:"token"`
}