Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Merge dev branch into staging branch. #963

Merged
merged 48 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
22377a5
Combine schema for like and dislike, and query dislike after creation
Aug 3, 2024
506233d
Update /test_dislike_blog_post.py file
Aug 3, 2024
8b4d1fa
Add client_helpers.py file AND use it to set ip_address for dislike
Aug 3, 2024
b3bb5c0
Change request method for routes.blog.dislike_blog_post from PUT to POST
Aug 5, 2024
df5124a
Merge branch 'dev' into test-fix-refactor/improve-dislike-blog-post-t…
chimeziriobioha Aug 7, 2024
4ecc1c0
Merge branch 'dev' into test-fix-refactor/improve-dislike-blog-post-t…
Aug 8, 2024
509ab52
Add objects_count to data returned from blog like/dislike requests
Aug 8, 2024
2cd66a3
Fix conflict and merge dev into branch: corrections in blog likes and…
Aug 22, 2024
20cdb65
Change dislike blog endpoint method from PUT to POST. Add objects_cou…
Aug 22, 2024
7c34446
Merge branch 'dev' into fix/corrections-in-blog-like-and-dislike-impl…
chimeziriobioha Aug 23, 2024
6c002fc
Update billing plan endpoints schemas to show sample return data in docs
Aug 23, 2024
c91bce4
Correct billing_plans to plans
Aug 23, 2024
05dd240
feat: updated email notification for waitlist signu
MikeSoft007 Aug 23, 2024
7d90f9b
Merge remote-tracking branch 'origin/dev' into bugfix/waitlist_email
MikeSoft007 Aug 23, 2024
9023e94
feat: updated email notification for waitlist signu
MikeSoft007 Aug 23, 2024
9071502
Merge pull request #950 from MikeSoft007/bugfix/waitlist_email
johnson-oragui Aug 23, 2024
c1cd498
Merge branch 'dev' into fix/corrections-in-blog-like-and-dislike-impl…
chimeziriobioha Aug 23, 2024
fa125e4
Merge branch 'dev' into fix/update-response-data-docs-for-billing-pla…
chimeziriobioha Aug 23, 2024
d5a6316
Merge pull request #936 from traderstechie/fix/corrections-in-blog-li…
johnson-oragui Aug 23, 2024
b16420b
Merge branch 'dev' into fix/update-response-data-docs-for-billing-pla…
chimeziriobioha Aug 23, 2024
6fd2c2d
feat: implement status page endpoints
JoshuaOloton Aug 23, 2024
fe695c4
boilerplate status page
utibenoah Aug 23, 2024
2544647
Merge pull request #951 from utibenoah/qa_tests/boilerplate-status-page
joboy-dev Aug 23, 2024
75f4ea0
feat: implement status page endpoints
JoshuaOloton Aug 24, 2024
8f2bcf5
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
JoshuaOloton Aug 24, 2024
012dc0e
fix: updated api base url
JoshuaOloton Aug 24, 2024
529a16a
fix: updated api base url
JoshuaOloton Aug 24, 2024
afc319e
feat added get all payments with user_id
marveldo Aug 24, 2024
4f33047
bugfix: updated google auth
MikeSoft007 Aug 24, 2024
72a9aeb
Merge remote-tracking branch 'origin/dev' into bugfix/waitlist_email
MikeSoft007 Aug 24, 2024
6aaef3f
bugfix: updated google auth
MikeSoft007 Aug 24, 2024
f49c00e
bugfix: updated google auth
MikeSoft007 Aug 24, 2024
3863607
bugfix: updated google auth
MikeSoft007 Aug 24, 2024
be6a80b
bugfix: updated google auth
MikeSoft007 Aug 24, 2024
7750011
Merge pull request #959 from MikeSoft007/bugfix/google_auth
johnson-oragui Aug 24, 2024
27fb752
Merge branch 'dev' into fix/update-response-data-docs-for-billing-pla…
johnson-oragui Aug 24, 2024
43d9e5a
Merge pull request #944 from traderstechie/fix/update-response-data-d…
johnson-oragui Aug 24, 2024
79e53b6
Added search queries functionality
theijhay Aug 24, 2024
b276d5b
Merge branch 'dev' into feat/implement-status-page
joboy-dev Aug 24, 2024
7cdaa4d
Merge pull request #961 from theijhay/fix/Get-fags
johnson-oragui Aug 24, 2024
54fc4b8
Merge branch 'dev' into feat/implement-status-page
Goketech Aug 24, 2024
4804cb7
Merge branch 'hngprojects:dev' into feat/transaction-history
marveldo Aug 24, 2024
1fda8cf
Merge pull request #953 from JoshuaOloton/feat/implement-status-page
johnson-oragui Aug 24, 2024
d2e1ac2
Merge branch 'dev' into feat/transaction-history
marveldo Aug 24, 2024
39ad0a6
Merge pull request #962 from marveldo/feat/transaction-history
johnson-oragui Aug 24, 2024
c1fe3b9
feat: implement returning faqs by category
Nifilat Aug 24, 2024
b03099f
chore: added query params
Nifilat Aug 24, 2024
c58deb8
Merge pull request #964 from Nifilat/feat/faq-categories
joboy-dev Aug 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from api.v1.models.activity_logs import ActivityLog
from api.v1.models.api_status import APIStatus
from api.v1.models.billing_plan import BillingPlan
from api.v1.models.comment import Comment, CommentLike, CommentDislike
from api.v1.models.contact_us import ContactUs
Expand Down
11 changes: 11 additions & 0 deletions api/v1/models/api_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from sqlalchemy import Column, DateTime, String, Text, Numeric, func
from api.v1.models.base_model import BaseTableModel

class APIStatus(BaseTableModel):
__tablename__ = "api_status"

api_group = Column(String, nullable=False)
status = Column(String, nullable=False)
last_checked = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
response_time = Column(Numeric, nullable=True)
details = Column(Text, nullable=True)
2 changes: 2 additions & 0 deletions api/v1/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from api.v1.routes.privacy import privacies
from api.v1.routes.team import team
from fastapi import APIRouter
from api.v1.routes.api_status import api_status
from api.v1.routes.auth import auth
from api.v1.routes.faq_inquiries import faq_inquiries
from api.v1.routes.newsletter import newsletter, news_sub
Expand Down Expand Up @@ -48,6 +49,7 @@

api_version_one = APIRouter(prefix="/api/v1")

api_version_one.include_router(api_status)
api_version_one.include_router(auth)
api_version_one.include_router(faq_inquiries)
api_version_one.include_router(google_auth)
Expand Down
34 changes: 34 additions & 0 deletions api/v1/routes/api_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import Annotated
from api.db.database import get_db
from api.v1.schemas.api_status import APIStatusPost
from api.v1.services.api_status import APIStatusService
from api.utils.success_response import success_response
from fastapi import APIRouter, Depends, status
from sqlalchemy.orm import Session

api_status = APIRouter(prefix='/api-status', tags=['API Status'])


@api_status.get('', response_model=success_response, status_code=200)
async def get_api_status(db: Annotated[Session, Depends(get_db)]):
all_status = APIStatusService.fetch_all(db)

return success_response(
message='All API Status fetched successfully',
data=all_status,
status_code=status.HTTP_200_OK
)


@api_status.post('', response_model=success_response, status_code=201)
async def post_api_status(
schema: APIStatusPost,
db: Annotated[Session, Depends(get_db)]
):
new_status = APIStatusService.upsert(db, schema)

return success_response(
message='API Status created successfully',
data=new_status,
status_code=status.HTTP_201_CREATED
)
25 changes: 14 additions & 11 deletions api/v1/routes/billing_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
from api.v1.services.billing_plan import billing_plan_service
from api.db.database import get_db
from api.v1.services.user import user_service
from api.v1.schemas.plans import CreateSubscriptionPlan
from api.v1.schemas.plans import (
CreateBillingPlanSchema, CreateBillingPlanResponse, GetBillingPlanListResponse
)


bill_plan = APIRouter(prefix="/organisations", tags=["Billing-Plan"])


@bill_plan.get("/{organisation_id}/billing-plans", response_model=success_response)
@bill_plan.get("/{organisation_id}/billing-plans", response_model=GetBillingPlanListResponse)
async def retrieve_all_billing_plans(
organisation_id: str, db: Session = Depends(get_db)
):
Expand All @@ -34,10 +37,10 @@ async def retrieve_all_billing_plans(
)


@bill_plan.post("/billing-plans", response_model=success_response)
@bill_plan.post("/billing-plans", response_model=CreateBillingPlanResponse)
async def create_new_billing_plan(
request: CreateSubscriptionPlan,
current_user: User = Depends(user_service.get_current_super_admin),
request: CreateBillingPlanSchema,
_: User = Depends(user_service.get_current_super_admin),
db: Session = Depends(get_db),
):
"""
Expand All @@ -53,11 +56,11 @@ async def create_new_billing_plan(
)


@bill_plan.patch("/billing-plans/{billing_plan_id}", response_model=success_response)
@bill_plan.patch("/billing-plans/{billing_plan_id}", response_model=CreateBillingPlanResponse)
async def update_a_billing_plan(
billing_plan_id: str,
request: CreateSubscriptionPlan,
current_user: User = Depends(user_service.get_current_super_admin),
request: CreateBillingPlanSchema,
_: User = Depends(user_service.get_current_super_admin),
db: Session = Depends(get_db),
):
"""
Expand All @@ -76,7 +79,7 @@ async def update_a_billing_plan(
@bill_plan.delete("/billing-plans/{billing_plan_id}", response_model=success_response)
async def delete_a_billing_plan(
billing_plan_id: str,
current_user: User = Depends(user_service.get_current_super_admin),
_: User = Depends(user_service.get_current_super_admin),
db: Session = Depends(get_db),
):
"""
Expand All @@ -91,11 +94,11 @@ async def delete_a_billing_plan(
)


@bill_plan.get('/billing-plans/{billing_plan_id}', response_model=success_response)
@bill_plan.get('/billing-plans/{billing_plan_id}', response_model=CreateBillingPlanResponse)
async def retrieve_single_billing_plans(
billing_plan_id: str,
db: Session = Depends(get_db),
current_user: User = Depends(user_service.get_current_user)
_: User = Depends(user_service.get_current_user)
):
"""
Endpoint to get single billing plan by id
Expand Down
94 changes: 47 additions & 47 deletions api/v1/routes/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,80 +117,80 @@ def like_blog_post(
db: Session = Depends(get_db),
current_user: User = Depends(user_service.get_current_user),
):
"""Endpoint to add `like` to a blog post.

args:
blog_id: `str` The ID of the blog post.
request: `default` Request.
db: `default` Session.

return:
In the `data` returned, `"object"` represents details of the
BlogLike obj and the `"objects_count"` represents the number
of BlogLike for the blog post
"""
blog_service = BlogService(db)

# GET blog post
# get blog post
blog_p = blog_service.fetch(blog_id)
if not isinstance(blog_p, Blog):
raise HTTPException(
detail="Post not found", status_code=status.HTTP_404_NOT_FOUND
)

# CONFIRM current user has NOT liked before
existing_like = blog_service.fetch_blog_like(blog_p.id, current_user.id)
if isinstance(existing_like, BlogLike):
raise HTTPException(
detail="You have already liked this blog post",
status_code=status.HTTP_403_FORBIDDEN,
)

# UPDATE likes
blog_service.create_blog_like(

# confirm current user has NOT liked before
blog_service.check_user_already_liked_blog(blog_p, current_user)

# update likes
new_like = blog_service.create_blog_like(
db, blog_p.id, current_user.id, ip_address=get_ip_address(request))

# CONFIRM new like
new_like = blog_service.fetch_blog_like(blog_p.id, current_user.id)
if not isinstance(new_like, BlogLike):
raise HTTPException(
detail="Unable to record like.", status_code=status.HTTP_400_BAD_REQUEST
)

# Return success response
return success_response(
status_code=status.HTTP_200_OK,
message="Like recorded successfully.",
data=new_like.to_dict(),
data={
'object': new_like.to_dict(),
'objects_count': blog_service.num_of_likes(blog_id)
},
)


@blog.put("/{blog_id}/dislike", response_model=BlogLikeDislikeResponse)
@blog.post("/{blog_id}/dislike", response_model=BlogLikeDislikeResponse)
def dislike_blog_post(
blog_id: str,
request: Request,
db: Session = Depends(get_db),
current_user: User = Depends(user_service.get_current_user),
):
"""Endpoint to add `dislike` to a blog post.

args:
blog_id: `str` The ID of the blog post.
request: `default` Request.
db: `default` Session.

return:
In the `data` returned, `"object"` represents details of the
BlogDislike obj and the `"objects_count"` represents the number
of BlogDislike for the blog post
"""
blog_service = BlogService(db)

# GET blog post
# get blog post
blog_p = blog_service.fetch(blog_id)
if not isinstance(blog_p, Blog):
raise HTTPException(
detail="Post not found", status_code=status.HTTP_404_NOT_FOUND
)

# CONFIRM current user has NOT disliked before
existing_dislike = blog_service.fetch_blog_dislike(blog_p.id, current_user.id)
if isinstance(existing_dislike, BlogDislike):
raise HTTPException(
detail="You have already disliked this blog post",
status_code=status.HTTP_403_FORBIDDEN,
)

# UPDATE disikes
new_dislike = blog_service.create_blog_dislike(db, blog_p.id, current_user.id)

if not isinstance(new_dislike, BlogDislike):
raise HTTPException(
detail="Unable to record dislike.", status_code=status.HTTP_400_BAD_REQUEST
)

# confirm current user has NOT disliked before
blog_service.check_user_already_disliked_blog(blog_p, current_user)

# update disikes
new_dislike = blog_service.create_blog_dislike(
db, blog_p.id, current_user.id, ip_address=get_ip_address(request))

# Return success response
return success_response(
status_code=status.HTTP_200_OK,
message="Dislike recorded successfully.",
data=new_dislike.to_dict(),
data={
'object': new_dislike.to_dict(),
'objects_count': blog_service.num_of_dislikes(blog_id)
},
)


Expand Down
20 changes: 15 additions & 5 deletions api/v1/routes/faq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import APIRouter, Depends, status
from fastapi import APIRouter, Depends, status, Query
from fastapi.encoders import jsonable_encoder
from sqlalchemy.orm import Session
from typing import Optional

from api.db.database import get_db
from api.utils.pagination import paginated_response
Expand All @@ -15,15 +16,24 @@


@faq.get("", response_model=success_response, status_code=200)
async def get_all_faqs(db: Session = Depends(get_db),):
"""Endpoint to get all FAQs"""
async def get_all_faqs(
db: Session = Depends(get_db),
keyword: Optional[str] = Query(None, min_length=1)
):
"""Endpoint to get all FAQs or search by keyword in both question and answer"""

query_params = {}
if keyword:
query_params["question"] = keyword
query_params["answer"] = keyword

faqs = faq_service.fetch_all(db=db)
grouped_faqs = faq_service.fetch_all_grouped_by_category(
db=db, **query_params)

return success_response(
status_code=200,
message="FAQs retrieved successfully",
data=jsonable_encoder(faqs),
data=jsonable_encoder(grouped_faqs),
)


Expand Down
Loading
Loading