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

Code documented using Techdocs CLI Tool #49

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 19 additions & 16 deletions TechdocsAPI/backend/core/ConfigEnv.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
"""Config class for handling env variables.
"""
from functools import lru_cache

from pydantic import BaseSettings


class Settings(BaseSettings):
HOSTNAME: str
DATABASE: str
UID: str
PASSWORD: str
ALGORITHM:str
JWT_SECRET_KEY:str
JWT_REFRESH_SECRET_KEY:str
JWT_VERIFICATION_SECRET_KEY:str
# OPENAI_KEY:str
APP_ID:str
USER_ID:str
MODEL_ID:str
CLARIFAI_PAT:str
MODEL_VERSION_ID:str
ALGORITHM: str
JWT_SECRET_KEY: str
JWT_REFRESH_SECRET_KEY: str
JWT_VERIFICATION_SECRET_KEY: str
APP_ID: str
USER_ID: str
MODEL_ID: str
CLARIFAI_PAT: str
MODEL_VERSION_ID: str

MAIL_SERVER_URL:str

Expand All @@ -28,12 +25,18 @@ class Settings(BaseSettings):
MAIL_FROM:str

class Config:
env_file = ".env"

env_file = '.env'

@lru_cache()
def get_settings():
return Settings()
"""
Returns the settings object.

This function returns a settings object of the type Settings. This object contains various configuration
settings used throughout the application.

config = get_settings()
Returns:
Settings: The settings object.
"""
return Settings()
config = get_settings()
148 changes: 140 additions & 8 deletions TechdocsAPI/backend/core/Exceptions.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,191 @@
import json

from backend.models import GeneralResponse, TokenSchema


class InvalidCredentialsException(Exception):

def __init__(self, token_result: GeneralResponse):
"""
Initializes an instance of InvalidCredentialsException.

Arguments:
token_result -- GeneralResponse: The result of a token request.

Raises:
InvalidCredentialsException: If the token request was unsuccessful.

"""
self.token_result = token_result
self.set_statuses()
super(InvalidCredentialsException, self).__init__()

def set_statuses(self):
"""
This method updates the status of the token_result attribute to 'login_failed'.

Arguments:
self -- The object instance.

Raises:
No exceptions are raised by this method.

Returns:
None, this method doesn't return a value.
"""
self.token_result.status = 'login_failed'

def __repr__(self):
return "exception.InvalidCredentialsException()"
"""
Returns a string representation of the object.

This method is used to return a string that represents the object. This string can be used to reconstruct the object.

Returns:
str: A string representation of the object.
"""
return 'exception.InvalidCredentialsException()'

class ExistingUserException(Exception):

def __init__(self, response_result: GeneralResponse):
"""
Initializes an instance of ExistingUserException.

Args:
response_result: GeneralResponse
The response result object that contains information about the response.

Raises:
None

Returns:
None
"""
self.response_result = response_result
self.set_statuses()
super(ExistingUserException, self).__init__()

def set_statuses(self):
"""
This function sets the status and message of the response_result object.

Args:
self: The object of the class.

Returns:
None

Raises:
None
"""
self.response_result.status = f'failed'
self.response_result.message.append(f'user with this AADHAR Number already has an account')
self.response_result.message.append(f'user already has an account')
self.response_result.message[0] = 'authenticated'

def __repr__(self):
return "exception.ExistingUserException()"

"""
This method returns a representation of the object.

Returns:
exception.ExistingUserException: This exception is raised when a user with the same username already exists.

Raises:
No exceptions are raised by this method.

"""
return 'exception.ExistingUserException()'

class InfoNotFoundException(Exception):

def __init__(self, response_result: GeneralResponse, message: str):
"""
Initializes an instance of InfoNotFoundException.

This is a custom exception class used when information is not found.

Args:
response_result: GeneralResponse
The response result object.
message: str
A human-readable message describing the error.

Raises:
Exception
If the initialization fails.

"""
self.response_result = response_result
self.message = message
self.set_statuses()
super(InfoNotFoundException, self).__init__(message)

def set_statuses(self):
"""
This method updates the status and message in the response_result dictionary.

Args:
self: The object instance.

Attributes:
response_result: A dictionary containing the response result.

Methods:
self.response_result['status'] = 'abort': Updates the status in the response_result dictionary to 'abort'.
self.response_result['message'][0] = 'authenticated': Updates the first message in the message list in the response_result dictionary to 'authenticated'.
self.response_result['message'].append(self.message): Appends the value of self.message to the message list in the response_result dictionary.

Returns:
None: This method does not return any value.

Raises:
None: This method does not raise any exceptions.
"""
self.response_result['status'] = 'abort'
self.response_result['message'][0] = 'authenticated'
self.response_result['message'].append(self.message)

def __repr__(self):
return "exception.InfoNotFoundException()"
"""
Returns a string representation of the object.

Returns:
str: A string representation of the object.
"""
return 'exception.InfoNotFoundException()'

class EmailNotVerifiedException(Exception):

def __init__(self):
"""
Initializes an instance of EmailNotVerifiedException.

This method sets the statuses and initializes the exception with a message.

Parameters:
self: The instance of the class.

Returns:
None: This method doesn't return anything.

Raises:
None: This method doesn't raise any exceptions.
"""
self.set_statuses()
super(EmailNotVerifiedException, self).__init__()

def set_statuses(self):
"""
def set_statuses(self):
"""
self.status = 'EmailNotVerifiedException'

def __repr__(self):
return "exception.EmailNotVerifiedException()"
"""
This method returns a representation of the object.

Returns:
str: A string representation of the object.
"""
return 'exception.EmailNotVerifiedException()'


class EmailNotSentException(Exception):
Expand Down
19 changes: 15 additions & 4 deletions TechdocsAPI/backend/models/generic.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
from pydantic import BaseModel
from typing import List


class Base(BaseModel):

@classmethod
def get_instance(cls, **kwargs):
return cls(**kwargs)
"""
This is a class method that creates an instance of the class.

Args:
**kwargs: Keyword arguments to be passed to the class constructor.

Returns:
An instance of the class.

Raises:
No exceptions are raised by this method.
"""
return cls(**kwargs)

class GeneralResponse(Base):
status:str
status: str
message: List[str]
data:dict
data: dict
Loading
Loading