diff --git a/project/app/database.sqlite b/project/app/database.sqlite new file mode 100644 index 0000000..676b9f8 Binary files /dev/null and b/project/app/database.sqlite differ diff --git a/project/app/migrations/0001_initial.py b/project/app/migrations/0001_initial.py new file mode 100644 index 0000000..a8016c8 --- /dev/null +++ b/project/app/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 5.2.11 on 2026-05-17 21:25 + +import banjo.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Movie', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', banjo.models.StringField(default='')), + ('year', banjo.models.IntegerField(blank=True, default=0, null=True)), + ('genre', banjo.models.StringField(blank=True, default='')), + ('status', banjo.models.StringField(default='')), + ('rating', banjo.models.IntegerField(blank=True, default=0, null=True)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/project/app/migrations/0002_alter_movie_genre.py b/project/app/migrations/0002_alter_movie_genre.py new file mode 100644 index 0000000..f9557bd --- /dev/null +++ b/project/app/migrations/0002_alter_movie_genre.py @@ -0,0 +1,19 @@ +# Generated by Django 5.2.11 on 2026-05-17 21:35 + +import banjo.models +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='movie', + name='genre', + field=banjo.models.StringField(blank=True, default='', null=True), + ), + ] diff --git a/project/app/migrations/0003_remove_movie_year.py b/project/app/migrations/0003_remove_movie_year.py new file mode 100644 index 0000000..86555d0 --- /dev/null +++ b/project/app/migrations/0003_remove_movie_year.py @@ -0,0 +1,17 @@ +# Generated by Django 5.2.11 on 2026-05-17 22:11 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0002_alter_movie_genre'), + ] + + operations = [ + migrations.RemoveField( + model_name='movie', + name='year', + ), + ] diff --git a/project/app/migrations/__init__.py b/project/app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/app/models.py b/project/app/models.py new file mode 100644 index 0000000..15f1bcc --- /dev/null +++ b/project/app/models.py @@ -0,0 +1,24 @@ +from banjo.models import ( + Model, + StringField, + IntegerField, + FloatField, + ForeignKey, +) +from django.db.models import DateTimeField + +class Movie(Model): + title = StringField() + genre = StringField(blank = True, null = True) + status = StringField(default = "Want to Watch") + rating = IntegerField(blank = True, null = True) + + + def to_dict(self): + return { + "id": self.id, + "title": self.title, + "genre": self.genre, + "status": self.status, + "rating": self.rating, + } \ No newline at end of file diff --git a/project/app/views.py b/project/app/views.py new file mode 100644 index 0000000..ed5db17 --- /dev/null +++ b/project/app/views.py @@ -0,0 +1,70 @@ +from banjo.urls import route_get, route_post +from banjo.http import BadRequest +from app.models import Movie + +@route_get('movies/all') +def all_movies(params): + movies = Movie.objects.all() + return {'movies': [movie.to_dict() for movie in movies]} + +@route_get('movies/search', args={'query': str}) +def search_movie(params): + query = params['query'] + movies = Movie.objects.filter(title__icontains=query) + return {'movies': [movie.to_dict() for movie in movies]} + +@route_get('movies/want-to-watch') +def want_to_watch(params): + movies = Movie.objects.filter(status="Want to Watch") + return {'movies': [movie.to_dict() for movie in movies]} + +@route_get('movies/watched') +def watched_movies(params): + movies = Movie.objects.filter(status="Watched") + return {'movies': [movie.to_dict() for movie in movies]} + +@route_post('movies/add', args={'title': str}) +def add_movie(params): + movie = Movie( + title=params['title'], + genre=params.get('genre'), + status=params.get('status', 'Want to Watch'), + rating=params.get('rating') + ) + movie.save() + return movie.to_dict() + +@route_post('movies/update-status', args={'id': int, 'status': str}) +def update_status(params): + try: + movie = Movie.objects.get(id=params['id']) + movie.status = params['status'] + movie.save() + return movie.to_dict() + except Movie.DoesNotExist: + raise NotFound("Movie not found") + + +@route_post('movies/update-rating', args={'id': int, 'rating': int}) +def update_rating(params): + try: + movie = Movie.objects.get(id=params['id']) + rating = params['rating'] + if rating < 1 or rating > 10: + raise BadRequest("Rating must be between 1 and 10") + movie.rating = rating + movie.save() + return movie.to_dict() + except Movie.DoesNotExist: + raise NotFound("Movie not found") + +@route_post('movies/update-genre', args={'id': int, 'genre': str}) +def update_genre(params): + """Update the genre of an existing movie""" + try: + movie = Movie.objects.get(id=params['id']) + movie.genre = params['genre'] + movie.save() + return movie.to_dict() + except Movie.DoesNotExist: + raise NotFound("Movie not found") \ No newline at end of file