-
Notifications
You must be signed in to change notification settings - Fork 0
created Todo CRUD and also apply middleware #7
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
base: dev
Are you sure you want to change the base?
Conversation
…tegration with alembic
| op.add_column('todos', sa.Column('user_id', sa.Integer(), nullable=True)) | ||
| op.create_foreign_key(None, 'todos', 'user', ['user_id'], ['id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you named todos for user relation here
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_constraint(None, 'todos', type_='foreignkey') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having constraint name none have some name
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column('company', sa.Column('company_type', sa.String(), nullable=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why company type is null
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table('todos', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change the table todos name
app/auth.py
Outdated
|
|
||
| SECRET_KEY = "af3287c8391bb9f4f7a72feb3b85f72e1d5bd07cbf4fa4ad9497c78412923312" | ||
| ALGORITHM = "HS256" | ||
| ACCESS_TOKEN_EXPIRE_MINUTES = 7 * 24 * 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct the format as i have defined you before not multiplications just value
app/services/company_service.py
Outdated
| company.location = location | ||
|
|
||
| self.repo.update(company) | ||
| return {"message": "Company updated successfully"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above dont need hard coded reponse
app/services/company_service.py
Outdated
| if not company: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Company not found") | ||
|
|
||
| self.repo.delete(company) | ||
| return {"message": "Company deleted successfully"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
app/services/product_service.py
Outdated
| def create_product(self, company_id: int, name: str, price: float, description: str): | ||
| existing_product = self.repo.get_by_name_and_company(company_id, name) | ||
| if existing_product: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_400_BAD_REQUEST, | ||
| detail="This product already exists for the company" | ||
| ) | ||
|
|
||
| product = Product(company_id=company_id, name=name, price=price, description=description) | ||
| created_product = self.repo.create(product) | ||
| return created_product | ||
|
|
||
| def list_products(self, skip: int, limit: int): | ||
| products = self.repo.get_all(skip, limit) | ||
| if not products: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="No products found") | ||
| return products | ||
|
|
||
| def get_product(self, product_id: int): | ||
| product = self.repo.get_by_id(product_id) | ||
| if not product: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Product not found") | ||
| return product | ||
|
|
||
| def update_product(self, product_id: int, name: str, price: float, description: str): | ||
| product = self.repo.get_by_id(product_id) | ||
| if not product: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Product not found") | ||
|
|
||
| product.name = name | ||
| product.price = price | ||
| product.description = description | ||
|
|
||
| updated = self.repo.update(product) | ||
| return {"message": "Product updated successfully", "data": updated} | ||
|
|
||
| def delete_product(self, product_id: int): | ||
| product = self.repo.get_by_id(product_id) | ||
| if not product: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Product not found") | ||
|
|
||
| self.repo.delete(product) | ||
| return {"message": "Product deleted successfully"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct these aswell
app/services/todo_service.py
Outdated
| def get_all_todo(self,user_id:int,skip: int, limit: int): | ||
| todos = self.repo.list_todo(user_id,skip, limit) | ||
| if not todos: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="No todos found") | ||
|
|
||
| return todos | ||
|
|
||
| def create_todo(self, title: str, description: str, published: bool, user_id: int): | ||
| existing = self.repo.get_todo_by_title(title) | ||
| if existing: | ||
| raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Todo already exists") | ||
|
|
||
| todo = Todo(title=title, description=description, published=published, user_id=user_id) | ||
| create_todo = self.repo.create(todo) | ||
| return create_todo | ||
|
|
||
| def update_todo(self, todo_id: int, title: str, description: str, published: bool): | ||
| todo = self.repo.get_todo_by_id(todo_id) | ||
| if not todo: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Todo not found") | ||
|
|
||
| todo.title = title | ||
| todo.description = description | ||
| todo.published = published | ||
|
|
||
| updated = self.repo.update(todo) | ||
| return {"message": "Todo updated successfully", "data": updated} | ||
|
|
||
| def delete_todo(self, todo_id: int): | ||
| todo = self.repo.get_todo_by_id(todo_id) | ||
| if not todo: | ||
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Todo not found") | ||
|
|
||
| self.repo.delete(todo) | ||
| return {"message": "Todo deleted successfully"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct these aswell accordingly
app/services/user_service.py
Outdated
| class UserService: | ||
| def __init__(self, db: Session): | ||
| self.repo = UserRepository(db) | ||
|
|
||
| def create_user(self, username: str, hashed_pw: str): | ||
| existing_user = self.repo.get_by_username(username) | ||
| if existing_user: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_400_BAD_REQUEST, | ||
| detail="Username already exists" | ||
| ) | ||
|
|
||
| self.repo.create(username, hashed_pw) | ||
| return {"message": "User created successfully"} | ||
|
|
||
| def get_user(self, user_id: int): | ||
| user = self.repo.get_by_id(user_id) | ||
| if not user: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_404_NOT_FOUND, | ||
| detail="User not found" | ||
| ) | ||
| return user | ||
|
|
||
| def delete_user(self, user_id: int): | ||
| user = self.repo.get_by_id(user_id) | ||
| if not user: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_404_NOT_FOUND, | ||
| detail="User not found" | ||
| ) | ||
|
|
||
| self.repo.delete(user) | ||
| return {"message": "User deleted successfully"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
implement CRUD on todo list and also add middleware and authentuication