Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
ADD: setup app to create tables for movies and actors;
Browse files Browse the repository at this point in the history
  • Loading branch information
denistsoi committed May 6, 2020
1 parent 1a90d60 commit be85fb4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 15 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,28 @@

Udacity Fullstack capstone project

## criteria

### General Specifications

- [ ] Models will include at least…
- [ ] Two classes with primary keys at at least two attributes each
- [ ] [Optional but encouraged] One-to-many or many-to-many relationships between classes

- [ ] Endpoints will include at least…
- [ ] Two GET requests
- [ ] One POST request
- [ ] One PATCH request
- [ ] One DELETE request

- [ ] Roles will include at least…
- [ ] Two roles with different permissions
- [ ] Permissions specified for all endpoints

- [ ] Tests will include at least….
- [ ] One test for success behavior of each endpoint
- [ ] One test for error behavior of each endpoint
- [ ] At least two tests of RBAC for each role

## author
Denis Tsoi <denistsoi@gmail.com>
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS

from models import setup_db


def create_app(test_config=None):
# create and configure the app
app = Flask(__name__)
CORS(app)
setup_db(app)

@app.route("/")
def home():
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@


if __name__ == '__main__':
manager.run()
manager.run()
56 changes: 42 additions & 14 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,53 @@ def setup_db(app, database_path=database_path):
db.create_all()


'''
Person
Have title and release year
'''
class Movie(db.Model):
__tablename__ = "Movie"
id = Column(Integer, primary_key=True)
title = Column(String)
release_date = Column(db.DateTime, nullable=False)

def insert(self):
db.session.add(self)
db.session.commit()

def update(self):
db.session.commit()

def delete(self):
db.session.delete(self)
db.session.commit()

def format(self):
return {
"id": self.id,
"title": self.title,
"release_date": self.release_date
}

class Person(db.Model):
__tablename__ = 'People'

class Actor(db.Model):
__tablename__ = "Actor"
id = Column(Integer, primary_key=True)
name = Column(String)
catchphrase = Column(String)
name = Column(String, nullable=False)
age = Column(Integer, nullable=False)
gender = Column(String, nullable=False)

def insert(self):
db.session.add(self)
db.session.commit()

def update(self):
db.session.commit()

def __init__(self, name, catchphrase=""):
self.name = name
self.catchphrase = catchphrase
def delete(self):
db.session.delete(self)
db.session.commit()

def format(self):
return {
'id': self.id,
'name': self.name,
'catchphrase': self.catchphrase}
"id": self.id,
"name": self.name,
"age": self.age,
"gender": self.gender
}

0 comments on commit be85fb4

Please sign in to comment.