-
Notifications
You must be signed in to change notification settings - Fork 0
/
instruction.txt
174 lines (155 loc) · 3.94 KB
/
instruction.txt
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
Run the following lines, after replacing the strings
npm install express jsonwebtoken body-parser bcryptjs mongoose dotenv
export DB_URL="mongodb+srv://wigtailw:[email protected]/?retryWrites=true&w=majority"
export SECRET_CODE="SHA256"
export SERVER_PORT="8080"
export SALT_ROUNDS="10"
export TOKEN_EXP_SECS="10000"
npm app.js
API Documentation
User
{
_id: ,
username: {
type: String,
unique: true,
required: true,
lowercase: true,
trim: true
},
password: {
type: String,
required: true
},
documents: []
}
Sign up for new user
POST /user/signup
{
"username": ,
"password":
}
BUG: validation of username and password to be implemented
ON SUCCESS:
{
"success": true,
"token": ...
}
ON FAIL, output error
Login to acquire token
GET /user/login
{
"username": ,
"password":
}
ON SUCCESS: return a token (expires in def. time) and user info without password,
ON FAIL, output error
Delete a user
POST /user/delete
Only success after the user quits all her/their/his documents
Bearer <token>
{
}
ON SUCCESS: return the user deleted
ON FAIL, output error
Document
{
_id: ,
title: {
type: String,
required: true,
trim: true
},
creator: {
type: String,
required: true
},
section: [String],
sectionQueue: [[String]],
collaborators: [],
comments: [{
comment: String,
date: Date,
user: String
}]
}
Create a document, become its creator
POST /document/create
Bearer <token>
{
"title": <title>
}
ON SUCCESS: add the document to list of documents of the creator, return the document
<PLEASE TAKE NOTE OF THE DOCUMENT ID ("_id" field)>
ON Fail: output err
Invite a collaborator to the document
POST /document/invite
Bearer <token>
{
"id": "_id" field of doc,
"collaborator": <user name of the collaborator to invite>
}
FAIL IF: 1> not the owner of the doc, 2> try to join again as collaborator
ON SUCCESS: add the document to list of documents of the collaborator, return the document
ON Fail: output err
Quit a document
POST /document/quit
Bearer <token>
{
"id": "_id" field of doc
}
If the creator wants to quit, when there exist at least 1 collaborator, the (first) collaborator
gets promoted as the new creator. If there is no collaborator, remove the doc to MINIMIZE DATA RETENTION!!
If the collaborator wants to quit, remove him/her/themself(ves) from the list of collaborators.
Remove all comments made by the user
ON SUCCESS: return doc and user with token
ON Fail: output err
View a document
GET /document/view1
Bearer <token>
{
"id": "_id" field of doc
}
FAIL IF: 1> the document does not belong to the user
ON SUCCESS: return the document
ON Fail: output err
View all documents of the user with token
GET /document/viewall
Bearer <token>
{
}
ON SUCCESS: return all the documents of the user
Make a comment to a doc
POST /document/comment
Bearer <token>
{
"id": "_id" field of doc,
"comment": <comment>
}
FAIL IF: 1> the document does not belong to the user
Append a (user, date, comment) tuple at the list of comments
date is calculated at server to avoid timezone issues
ON SUCCESS: return the document
Create a section of a doc
POST /document/createsection
Bearer <token>
{
"id": "_id" field of doc
}
FAIL IF: 1> the document does not belong to the user
POSSIBLE POINT TO IMPROVE:
1> maybe something like a section identifier?, or a section schema?
2> maybe only the creator is allowed to add a section?
Append an empty string to list of sections, and an empty queue to the end of sectionQueue
ON SUCCESS: return the document
Write a section of a doc
POST /document/writesection
Bearer <token>
{
"id": "_id" field of doc,
"sectionid": <section id, a number>,
"sectiontext": <text>
}
FAIL IF: 1> the document does not belong to the user
OVERWRITE the section with "sectiontext".
ON SUCCESS: return the document