Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDD83 Project
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pontus Atuma Löfgren
TDDD83 Project
Merge requests
!71
Added GET for a single user
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Added GET for a single user
feature/SingleUserGET
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Johan Lovén
requested to merge
feature/SingleUserGET
into
main
9 months ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
88f17468
1 commit,
9 months ago
1 file
+
28
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
server/routes/user.py
0 → 100644
+
28
−
0
Options
from
bson
import
ObjectId
from
flask
import
jsonify
from
flask
import
Blueprint
from
main
import
db
#import relevant classes
from
classes
import
user
bp
=
Blueprint
(
'
user
'
,
__name__
)
@bp.route
(
'
/user/<string:id>
'
)
def
specific_user
(
id
):
#Should only be allowed for GET
user_collection
=
db
[
"
user
"
]
try
:
# Convert the string ID to an ObjectId
oid
=
ObjectId
(
id
)
except
:
return
jsonify
({
"
error
"
:
"
Invalid ID format
"
}),
400
# Use the ObjectId to query the database
cursor
=
user_collection
.
find_one
({
"
_id
"
:
oid
})
if
cursor
is
None
:
return
jsonify
({
'
error
'
:
"
No object with the given ID exists.
"
}),
404
query
=
dict
(
cursor
)
us
=
user
.
User
(
query
)
return
jsonify
(
us
.
serialise_client
()),
200
\ No newline at end of file
Loading