Resources
LoginApi
Bases: Resource
This class is a subclass of the Resource class from the Flask-RESTful library. It handles requests against the
Snippet model to api/auth/login
Source code in resources/auth.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
post()
staticmethod
Authenticate a User object against the User model.
Yields:
Type | Description |
---|---|
Check the email. |
|
Check the password. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Reference the class itself |
required |
Flags
Errors and returns status code with error message, 200, otherwise.
Returns:
Type | Description |
---|---|
{dict}: JSON Flask Response with an access token and a username. sets a refresh-cookie in headers. |
Source code in resources/auth.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
LogoutApi
Bases: Resource
Requests against the Snippet model to api/auth/logout
Source code in resources/auth.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
post()
Create a new TokenBlockList document following a User's logout request.
Yields:
Type | Description |
---|---|
Save an exiting User's access token to the TokenBlockList database. |
|
This prevents the access token from being used between the logout event |
|
and its expiration. |
Flags
Errors and returns status code with error message, 200, otherwise.
Returns:
Type | Description |
---|---|
{dict}: JSON Flask Response confirmation that the token has been revoked. |
Source code in resources/auth.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
SignupApi
Bases: Resource
Requests against the Snippet model to api/auth/signup
Source code in resources/auth.py
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 |
|
post()
The post function creates a new User object following the User model.
Yields:
Type | Description |
---|---|
Save a new User with the required username, email, password fields. |
|
Hash the password. |
|
Create three Snippets for the user to have some UI to play with |
|
upon authentication. |
Flags
Errors and returns status code with error message, 200 otherwise. Returns: {dict}: JSON Flask Response with an access token and a username sets a refresh cookie in headers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Reference the class in the method definition |
required |
Returns:
Type | Description |
---|---|
A tuple, the first item is a dictionary with an access token and username |
Note
The computation to update, save, reload a Snippet is required to
ensure Objects have fully landed before they are referenced. It is extra
complicated for this endpoint as we are awaiting reloads for three models:
User, Collection and Snippet, all of which vary in having to exist
before
the other.
Source code in resources/auth.py
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 |
|
BadTokenError
Bases: Exception
It creates a new class called BadTokenError that inherits from the Exception class.
Source code in resources/errors.py
81 82 83 84 |
|
EmailAlreadyExistsError
Bases: Exception
This class is used to raise an error when a user tries to register with an email that already exists in the database
Source code in resources/errors.py
63 64 65 66 |
|
EmailDoesNotExistError
Bases: Exception
This class is used to raise an error when the email address provided does not exist in the database.
Source code in resources/errors.py
75 76 77 78 |
|
ExpiredTokenError
Bases: Exception
This class is used to raise an exception when a token has expired
Source code in resources/errors.py
87 88 89 90 |
|
InternalServerError
Bases: Exception
It creates a class called InternalServerError that inherits from the Exception class.
Source code in resources/errors.py
16 17 18 19 |
|
SchemaValidationError
Bases: Exception
It's a custom exception class that will be raised when the schema validation fails
Source code in resources/errors.py
22 23 24 25 |
|
SnippetAlreadyExistsError
Bases: Exception
It's a custom exception that is raised when a snippet already exists
Source code in resources/errors.py
28 29 30 31 |
|
SnippetNotExistsError
Bases: Exception
It's a custom exception that is raised when a snippet is not found in the database
Source code in resources/errors.py
45 46 47 48 |
|
UnauthorizedError
Bases: Exception
It's a custom exception class that inherits from the built-in Exception class
Source code in resources/errors.py
69 70 71 72 |
|
UpdatingSnippetError
Bases: Exception
It's an exception that's raised when a snippet can't be updated
Source code in resources/errors.py
34 35 36 37 |
|
UserNotExistsError
Bases: Exception
This class is used to raise an error when a user does not exist
Source code in resources/errors.py
51 52 53 54 |
|
UsernameAlreadyExistsError
Bases: Exception
This class is used to raise an error when a username already exists in the database
Source code in resources/errors.py
57 58 59 60 |
|
Status
Bases: Resource
Home endpoint to loosely convey the backend is running /
Source code in resources/status.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
get()
The get function returns a string that says "Api running"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Access variables that belongs to the class |
required |
Returns:
Type | Description |
---|---|
A dictionary with a key of data and value of "api running" |
Source code in resources/status.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
initialize_routes(api)
The initialize_routes function creates the routes for our API.
It is called in app.py when you run flask run
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api |
Register the resources |
required |
Returns:
Type | Description |
---|---|
The status of the api |
Source code in resources/routes.py
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 |
|
LikeSnippetApi
Bases: Resource
Requests against the Snippet model to api/likesnippet/<id>
Source code in resources/snippet.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
post(id)
Add/Remove a Snippet reference to the snippets_liked
list field of a User
document with matching id; vice-versa to the liked_by
list field of matching
Snippet document.
Yields:
Type | Description |
---|---|
Identify a user object against a User model via token. |
|
Identify a Snippet document based on the |
|
If the User is already in the Snippet's |
|
Otherwise, we're |
|
Update and reload both references to each other. |
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 with message |
Note
This response is a computation as there is no Fave
collection.
Source code in resources/snippet.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
SnippetApi
Bases: Resource
Requests against the Snippet model to api/snippets/<id>
(singular)
Source code in resources/snippet.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
delete(id)
Delete one Snippet object with a matching id.
Yields:
Type | Description |
---|---|
Identify a user object against a User model via token. |
|
Identify a Snippet document created by the user object. |
|
Delete the Snippet document. |
Flags
If it doesn't exist and we've gotten this far, It means it's made by someone else. If required fields are missing.
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 else: Notifies the frontend with status code and message. |
Source code in resources/snippet.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
get(id)
Retrieve one Snippet object with a matching id.
Yields:
Type | Description |
---|---|
Identify a Snippet object against a Snippet model |
Flags
If it doesn't exist.
[{dict}]
Type | Description |
---|---|
mappable JSON Flask Response, 200 |
|
an array, even with one value to keep the frontend handlers consistent. else: Notifies the frontend with status message. |
Source code in resources/snippet.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
put(id)
Update one Snippet object with a matching id.
Yields:
Type | Description |
---|---|
Identify a user object against a User model via token. |
|
Identify a Snippet document created by the user object. |
|
Accept all updates to the Snippet document. |
Flags
If it doesn't exist. If required fields are missing.
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 else: Notifies the frontend with status code and message. |
Source code in resources/snippet.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
SnippetsApi
Bases: Resource
Requests against the Snippet model to api/snippets
(plural)
Source code in resources/snippet.py
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 |
|
get()
Retrieve a list of public snippets.
Yields:
Type | Description |
---|---|
Parse web args from the request. |
|
Get all existing tags from the databse. |
|
Query snippets that include tags from the request. |
|
If the tag field is empty, return all snippets with all tags. |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response |
|
A paginated list of Snippet objects |
Source code in resources/snippet.py
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 |
|
post()
Save a Snippet document created by an authorized User.
Yields:
Type | Description |
---|---|
Identify a user object against a User model |
|
Set a Snippet document based on the Snippet model. |
|
Add the Snippet to the User's |
Flags
File and validation errors
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 else: Notifies the frontend with status message. |
Source code in resources/snippet.py
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 |
|
CollectionApi
Bases: Resource
Requests against the Collection model to api/collections/<id>
(singular)
Source code in resources/collection.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
delete(id)
Delete one Collection object with a matching id.
Yields:
Type | Description |
---|---|
Identify a user object against a User model via token. |
|
Identify a Collection document created by the user object. |
|
Delete the Collection document. |
Flags
If it doesn't exist and we've gotten this far, It means it's made by someone else. If required fields are missing.
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 else: Notifies the frontend with status code and message. |
Source code in resources/collection.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
get(id)
Retrieve one Collection object with a matching id.
Yields:
Type | Description |
---|---|
Identify a Collection object against a Collection model |
Flags
If it doesn't exist.
[{dict}]
Type | Description |
---|---|
mappable JSON Flask Response, 200, |
|
with dereferenced nested fields full of data, |
|
as an array even for one document to keep the frontend handlers consistent. else: Notifies the frontend with status message. |
Source code in resources/collection.py
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 |
|
put(id)
Update one Collection object with a matching id.
Yields:
Type | Description |
---|---|
Identify a user object against a User model via token. |
|
Identify a Collection document created by the user object. |
|
Iterate through the |
|
Set this array as a the new |
Flags
If it doesn't exist. If required fields are missing.
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 else: Notifies the frontend with status code and message. |
Note
Looping and setting a new array seems like an expensive computation
every time someone updates a collection, and the snippets within it.
Why can't we just keep it if it's already there, add it if it isn't?
Because the Snippet has to first exist in the database in order to
find
and add it to a Collection, the result will always be an
all or not all
flip. An alternative might be to create separate endpoints
for adding and removing values from a nested document, which may or may
not require the same amount of computation.
Source code in resources/collection.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
CollectionsApi
Bases: Resource
Requests against the Collection model to api/collections
(plural)
Source code in resources/collection.py
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 |
|
get()
Retrieve loose list of all Collections.
Yields:
Type | Description |
---|---|
jsonify a Query object of the Collection model |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response |
|
A loose reference list of Collection objects |
Note
This endpoint is not the primary endpoint for fetching field details,
Source code in resources/collection.py
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 |
|
post()
Save a Collection document created by an authorized User.
Yields:
Type | Description |
---|---|
Identify a user object against a User model |
|
Set a Collection document based on the Collection model. |
|
Add the Collection to the User's |
Flags
File and validation errors
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 else: Notifies the frontend with status message. |
Source code in resources/collection.py
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 |
|
MyCollectionApi
Bases: Resource
Requests against the Snippet model to api/users/<user_id>/collections/<id>
Source code in resources/profile.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
get(user_id, id)
Retrieve one Collection created by a user.
Yields:
Type | Description |
---|---|
Identify a User object against a User model via username (user_id). |
|
jsonify a Query object to the Collections database of a |
|
Collection object with field |
|
model via unique username |
|
equal to the query |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response |
|
A healthy Collection object with unnested, dereferenced Snippets |
Note
This endpoint returns a response identical to api/collections/<id>
;
the only difference being the user_id
argument.
This is to accommodate Collections flagged as private
to the User, a
field that is currently false for all Collections by default.
Source code in resources/profile.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
MyCollectionsApi
Bases: Resource
Requests against the Snippet model to api/users/<id>/collections
Source code in resources/profile.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
get(user_id)
Retrieve a complete list of all Collections created by a user.
Yields:
Type | Description |
---|---|
Identify a User object against a User model via username (id). |
|
jsonify a Query object to the Collections database of all |
|
Collection objects with field |
|
model via unique username and/or id. |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response |
|
A complete list of Snippet objects, with all nested fields |
|
dereferenced. |
Note
This endpoint is the primary endpoint for fetching User's Snippets profile.
Source code in resources/profile.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
MyCollectionsOptionsApi
Bases: Resource
Requests against the Collection model to api/users/<user_id>/collections/options
Source code in resources/profile.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
get(user_id)
Retrieve an array of all Collections available to the user.
Yields:
Type | Description |
---|---|
Identify a User object against a User model via username (user_id). |
|
jsonify a Query object to the Collections database of all |
|
Collection objects with field |
|
model via unique username |
|
an HTML |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response
array of Collections with |
Note
This key endpoint is what allows the frontend to quickly present documents as creatable and/or multi-select options immediately following updates to a user's Collections profile.
Source code in resources/profile.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
MyFaveSnippetsApi
Bases: Resource
Requests against the Snippet model to api/users/<id>/snippets/faves
Source code in resources/profile.py
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 |
|
get(id)
Retrieve a complete list of all Snippets liked
by a user.
Yields:
Type | Description |
---|---|
Identify a User object against a User model via username. |
|
jsonify a Query object to the Snippets database of all |
|
Snippet objects with a |
|
User. |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response |
|
A complete list of Snippet objects, with all nested fields |
|
dereferenced. |
Note
This API response is modeled to be received as a Collection object,
even though it is a pure computation of values in nested document
fields. This is done to simplofy frontend handlers as the Faves
endpoint's UI is rendered as a unique collection
.
Source code in resources/profile.py
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 |
|
MySnippetsApi
Bases: Resource
Requests against the Snippet model to api/users/<id>/snippets
Source code in resources/profile.py
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 |
|
get(id)
Retrieve a complete list of all Snippets created by a user.
Yields:
Type | Description |
---|---|
Identify a User object against a User model via username (id). |
|
jsonify a Query object to the Snippets database of all |
|
Snippet objects with field |
|
model's unique username. |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response |
|
A complete list of Snippet objects, with all nested fields |
|
dereferenced. |
Note
This endpoint is the primary endpoint for fetching User's Snippets profile.
Source code in resources/profile.py
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 |
|
MySnippetsOptionsApi
Bases: Resource
Requests against the Snippet model to api/users/<user_id>/snippets/options
Source code in resources/profile.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
get(user_id)
Retrieve an array of all Snippets available to the user.
Yields:
Type | Description |
---|---|
Identify a User object against a User model via username (user_id). |
|
jsonify a Query object to the Snippet database of all |
|
Snippet objects with field |
|
model via unique username |
|
an HTML |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response
array of Snippets with |
Note
This key endpoint is what allows the frontend to present documents as creatable and/or multi-select options in an instant following live and/or recurrent updates and additions to a user's saved Snippets.
Source code in resources/profile.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
UserApi
Bases: Resource
Requests against the User model to api/users/<id>
Source code in resources/user.py
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 |
|
delete(id)
Delete one User object with a matching id.
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 with status message. |
Source code in resources/user.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
get(id)
Returns a user object with username matching id.
Source code in resources/user.py
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 |
|
put()
Update one User object with a matching id.
{dict}
Type | Description |
---|---|
JSON Flask Response, 200 else: Notifies the frontend with status code and message. |
Source code in resources/user.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
UsersApi
Bases: Resource
Requests against the User model to api/users
Source code in resources/user.py
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 |
|
get()
Returns an array of all User objects.
Source code in resources/user.py
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 |
|
ForgotPassword
Bases: Resource
This class is a subclass of the Resource class, and it's used to handle the forgot password functionality.
Source code in resources/reset_password.py
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 |
|
post()
staticmethod
The post function is used to send an email with a link that will allow the user to reset their password. The function takes in an email and checks if it exists in the database. If it does, then a token is generated and sent to the user's email address along with instructions on how to reset their password.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Reference the current instance of the class |
required |
Returns:
Type | Description |
---|---|
A response with a message that the email was sent |
Source code in resources/reset_password.py
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 |
|
ResetPassword
Bases: Resource
This class is a subclass of the Resource class from the Flask-RESTful library. It has a post method that takes in a JSON object with a username and password. It then checks if the username is in the database and if it is, it updates the password.
Source code in resources/reset_password.py
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 |
|
post()
The post function is used to reset a user's password. It takes in the reset_token and password from the request body, and then checks if they are valid. If they are valid, it will update the user's password in MongoDB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Reference the current instance of the class |
required |
Returns:
Type | Description |
---|---|
A message that password reset was successful |
Source code in resources/reset_password.py
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 |
|
TagsApi
Bases: Resource
Prepares all selectable tags: api/tags.
Source code in resources/tags.py
17 18 19 20 21 22 23 24 |
|
get()
Retrieve a all current tags.
Source code in resources/tags.py
20 21 22 23 24 |
|
SearchApi
Bases: Resource
Handles query, language and tag params in URL search endpoint: api/search.
Source code in resources/search.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
get()
Retrieve a paginated list of public snippets.
Yields:
Type | Description |
---|---|
|
|
The base url. |
|
The URL string should follow this order: |
|
|
|
Search query is required. |
|
The following params [language, tags, page] are optional, and are there to narrow the search. |
|
|
|
Language query hones search query down to a language. |
|
Frontend can call {language=a} |
|
If empty, params for search query will prevail, and all languages will return. |
|
|
|
Tags query appends to a list. |
|
Frontend can append {tags=a&tags=b&tags=c} multiple times, and the parser will parse: |
|
[a, b, c] |
|
|
|
Page param will be available authomatically. |
Raises:
Type | Description |
---|---|
SnippetNotExistsError
|
The Snippet does not exist. |
InternalServerError
|
Server error. |
Returns:
Type | Description |
---|---|
[{dict}]: JSON Flask Response array of Snippets that match a query |
Source code in resources/search.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|