Skip to content

Commit

Permalink
Merge pull request #4 from ntvviktor/viktor/feature/CRUD-favourite-list
Browse files Browse the repository at this point in the history
complete CRUD favourite functionality endpoint
  • Loading branch information
ntvviktor authored Apr 30, 2024
2 parents 6e8f25e + 1f79e03 commit b18e7a6
Show file tree
Hide file tree
Showing 28 changed files with 666 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""first create db
"""first update
Revision ID: b1e09f172156
Revision ID: 0126d9492ccb
Revises:
Create Date: 2024-04-28 18:01:35.434190
Create Date: 2024-04-29 16:38:06.972199
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = 'b1e09f172156'
revision = '0126d9492ccb'
down_revision = None
branch_labels = None
depends_on = None
Expand Down Expand Up @@ -45,6 +45,14 @@ def upgrade():
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('favourite_list',
sa.Column('id', sa.String(length=30), nullable=False),
sa.Column('user_id', sa.String(length=250), nullable=True),
sa.Column('book_isbn', sa.String(length=30), nullable=True),
sa.ForeignKeyConstraint(['book_isbn'], ['books.isbn'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('opentrolley_books',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('isbn', sa.String(length=255), nullable=False),
Expand All @@ -61,6 +69,7 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('opentrolley_books')
op.drop_table('favourite_list')
op.drop_table('users')
op.drop_table('books')
# ### end Alembic commands ###
34 changes: 34 additions & 0 deletions migrations/versions/1078920783b3_second_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""second update
Revision ID: 1078920783b3
Revises: 0126d9492ccb
Create Date: 2024-04-29 21:13:51.079162
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1078920783b3'
down_revision = '0126d9492ccb'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('favourite_list',
sa.Column('user_id', sa.String(length=250), nullable=False),
sa.Column('book_isbn', sa.String(length=30), nullable=False),
sa.ForeignKeyConstraint(['book_isbn'], ['books.isbn'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('user_id', 'book_isbn')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('favourite_list')
# ### end Alembic commands ###
11 changes: 10 additions & 1 deletion webapp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Flask
import werkzeug
from flask import Flask, render_template
from dotenv import load_dotenv
from flask_login import LoginManager
from flask_migrate import Migrate
Expand Down Expand Up @@ -46,6 +47,14 @@ def create_app():
app.register_blueprint(admin_bp)
app.register_blueprint(search_bp)

@app.errorhandler(werkzeug.exceptions.HTTPException)
def internal_error(error):
if error.code == 500:
return render_template('errors/500.html'), 500
elif error.code == 404:
return render_template('errors/404.html'), 404
return render_template('errors/500.html'), 401

from .models.user_model import User

@login_manager.user_loader
Expand Down
14 changes: 9 additions & 5 deletions webapp/models/favourite_list.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from sqlalchemy import PrimaryKeyConstraint
from .. import db
import shortuuid


class FavouriteList(db.Model):
__tablename__ = 'favourite_list'

id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
book_isbn = db.Column(db.Integer, db.ForeignKey('books.isbn'))
user_id = db.Column(db.String(250), db.ForeignKey('users.id'))
book_isbn = db.Column(db.String(30), db.ForeignKey('books.isbn'))

__table_args__ = (
PrimaryKeyConstraint(
user_id,
book_isbn),
{})

def __init__(self, user_id, book_isbn):
self.id = shortuuid.uuid()
self.user_id = user_id
self.book_isbn = book_isbn
1 change: 0 additions & 1 deletion webapp/recommender/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from ..recommender.utils import load_data
from ..recommender.CDAE import CDAE
import pandas as pd
import numpy as np
import plotly
import plotly.graph_objs as go
import json
Expand Down
Loading

0 comments on commit b18e7a6

Please sign in to comment.