Skip to content

Commit

Permalink
Add technology route, registering route,...
Browse files Browse the repository at this point in the history
  • Loading branch information
danilojezernik committed Jul 15, 2024
1 parent 94ddb15 commit 840c3d2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/database/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

blog = [
Blog(
naslov='Test Naslov 1',
title='Test Naslov 1',
kategorija='angular',
podnaslov='Test Podnaslov 1',
datum_vnosa=datetime.datetime.now(),
vsebina='Test Vsebina 1',
image='test1.jpg'
).dict(by_alias=True),
Blog(
naslov='Test Naslov 2',
title='Test Naslov 2',
kategorija='angular',
podnaslov='Test Podnaslov 2',
datum_vnosa=datetime.datetime.now(),
vsebina='Test Vsebina 2',
image='test2.jpg'
).dict(by_alias=True),
Blog(
naslov='Test Naslov 3',
title='Test Naslov 3',
kategorija='angular',
podnaslov='Test Podnaslov 3',
datum_vnosa=datetime.datetime.now(),
Expand Down
2 changes: 1 addition & 1 deletion src/domain/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Blog(BaseModel):
id: Optional[str] = Field(alias='_id', default_factory=lambda: str(ObjectId()))
naslov: str
title: str
kategorija: str
podnaslov: str
vsebina: str
Expand Down
2 changes: 1 addition & 1 deletion src/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Use domains in models for frontend:

export interface Blog {
'_id'?: string;
naslov: string;
title: string;
kategorija: string;
podnaslov: string;
vsebina: string;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def add_new_blog(blog: Blog, current_user: str = Depends(get_current_user)
blog_dict['_id'] = str(insert_result.inserted_id)

# Generate the body content for the blog notification email
body = blog_notifications.html(title=blog.naslov)
body = blog_notifications.html(title=blog.title)

# Send notification to users that have blog_notification set to true
if not blog_notification.blog_notification(subject='Nov blog na strani DaniloJezernik.com', body=body):
Expand Down
21 changes: 21 additions & 0 deletions src/routes/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ async def get_all_links_public() -> list[Links]:
return links_list


# Get link by ID
@router.get('/{_id}', operation_id='get_link_by_id')
async def get_link_by_id(_id: str) -> Links:
"""
This route handles the retrieval of one link by its ID from the database
:param _id: The ID of the link to be retrieved
:return: If the link is found, returns the link data; otherwise, returns a 404 error
"""

# Attempt to find a link in the database based on the provided ID
cursor = db.process.links.find_one({'_id': _id})

# If no user is found, return a 404 error with a relevant detail message
if cursor is None:
raise HTTPException(status_code=404, detail=f'Link by ID: ({_id}) does not exist')
else:
# If the link is found, convert the cursor data into a Links object and return it
return Links(**cursor)


"""
THIS ROUTES ARE PRIVATE
"""
Expand Down

0 comments on commit 840c3d2

Please sign in to comment.