-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d3ef46
commit 7188715
Showing
27 changed files
with
365 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/server/.venv | ||
/**/**/__pycache__ | ||
/client/node_modules | ||
/client/.cache |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.contrib import admin | ||
from .models import Tag, ArticleTags, Article, Author, Category, Comment | ||
|
||
# Register your models here. | ||
|
||
admin.site.register(Tag) | ||
admin.site.register(ArticleTags) | ||
admin.site.register(Article) | ||
admin.site.register(Author) | ||
admin.site.register(Category) | ||
admin.site.register(Comment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BlogConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'blog' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Generated by Django 4.2.7 on 2023-11-03 09:12 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Article', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=200)), | ||
('content', models.TextField()), | ||
('publication_date', models.DateField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Author', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
('email', models.EmailField(max_length=254)), | ||
('bio', models.TextField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Category', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Tag', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('author_name', models.CharField(max_length=100)), | ||
('email', models.EmailField(max_length=254)), | ||
('comment_text', models.TextField()), | ||
('comment_date', models.DateField()), | ||
('article_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.article')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='ArticleTags', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('article_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.article')), | ||
('tag_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.tag')), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='author_id', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.author'), | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='category_id', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.category'), | ||
), | ||
] |
58 changes: 58 additions & 0 deletions
58
server/blog/migrations/0002_rename_author_id_article_author_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Generated by Django 4.2.7 on 2023-11-03 09:27 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='article', | ||
old_name='author_id', | ||
new_name='author', | ||
), | ||
migrations.RenameField( | ||
model_name='article', | ||
old_name='category_id', | ||
new_name='category', | ||
), | ||
migrations.RenameField( | ||
model_name='article', | ||
old_name='publication_date', | ||
new_name='created_at', | ||
), | ||
migrations.RenameField( | ||
model_name='articletags', | ||
old_name='article_id', | ||
new_name='article', | ||
), | ||
migrations.RenameField( | ||
model_name='articletags', | ||
old_name='tag_id', | ||
new_name='tag', | ||
), | ||
migrations.RenameField( | ||
model_name='comment', | ||
old_name='article_id', | ||
new_name='article', | ||
), | ||
migrations.RenameField( | ||
model_name='comment', | ||
old_name='author_name', | ||
new_name='author', | ||
), | ||
migrations.RenameField( | ||
model_name='comment', | ||
old_name='comment_date', | ||
new_name='created_at', | ||
), | ||
migrations.RenameField( | ||
model_name='comment', | ||
old_name='comment_text', | ||
new_name='text', | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
class Author(models.Model): | ||
name = models.CharField(max_length=100) | ||
email = models.EmailField() | ||
bio = models.TextField() | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Category(models.Model): | ||
name = models.CharField(max_length=100) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Article(models.Model): | ||
title = models.CharField(max_length=200) | ||
content = models.TextField() | ||
created_at = models.DateField() | ||
author = models.ForeignKey(Author, on_delete=models.CASCADE) | ||
category = models.ForeignKey(Category, on_delete=models.CASCADE) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
class Comment(models.Model): | ||
article = models.ForeignKey(Article, on_delete=models.CASCADE) | ||
author = models.CharField(max_length=100) # Who made the comment | ||
email = models.EmailField() | ||
text = models.TextField() | ||
created_at = models.DateField() | ||
|
||
def __str__(self): | ||
return self.comment_date | ||
|
||
|
||
class Tag(models.Model): | ||
name = models.CharField(max_length=255) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
# ArticleTags Table (a junction table to implement many-to-many relationship between Articles and Tags): | ||
class ArticleTags(models.Model): | ||
article = models.ForeignKey(Article, on_delete=models.CASCADE) | ||
tag = models.ForeignKey(Tag, on_delete=models.CASCADE) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import graphene | ||
from graphene_django import DjangoObjectType | ||
from ..models import Category, Article | ||
from .queryTypes import CategoryType, ArticleType | ||
|
||
|
||
class CategoryMutation(graphene.Mutation): | ||
class Arguments: | ||
name = graphene.String(required=True) | ||
id = graphene.ID() | ||
|
||
category = graphene.Field(CategoryType) | ||
|
||
@classmethod | ||
def mutate(cls, root, info, name, id=None): | ||
if id: | ||
category = Category.objects.get(pk=id) | ||
category.name = name | ||
category.save() | ||
else: | ||
category = Category.objects.create(name=name) | ||
return CategoryMutation(category=category) | ||
|
||
|
||
class ArticleMutation(graphene.Mutation): | ||
class Arguments: | ||
title = graphene.String(required=True) | ||
content = graphene.String(required=True) | ||
created_at = graphene.Date() | ||
author_id = graphene.ID() | ||
category_id = graphene.ID() | ||
id = graphene.ID() | ||
|
||
article = graphene.Field(ArticleType) | ||
|
||
@classmethod | ||
def mutate(cls, root, info, title, content, created_at, author_id, category_id, id=None): | ||
if id: | ||
article = Article.objects.get(pk=id) | ||
article.title = title | ||
article.content = content | ||
if created_at: | ||
article.created_at = created_at | ||
if author_id: | ||
article.author_id = author_id | ||
if category_id: | ||
article.category_id = category_id | ||
article.save() | ||
else: | ||
article = Article.objects.create(title=title, content=content, created_at=created_at, author_id=author_id, | ||
category_id=category_id) | ||
return ArticleMutation(article=article) | ||
|
||
|
||
class Mutation(graphene.ObjectType): | ||
create_or_update_category = CategoryMutation.Field() | ||
create_or_update_article = ArticleMutation.Field() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import graphene | ||
from .queryTypes import AuthorType, CategoryType, ArticleType, CommentType, TagType | ||
from ..models import Author, Category, Article, Comment, Tag | ||
|
||
class Query(graphene.ObjectType): | ||
|
||
all_authors = graphene.List(AuthorType) | ||
all_categories = graphene.List(CategoryType) | ||
all_articles = graphene.List(ArticleType, start=graphene.Int(), limit=graphene.Int()) | ||
all_comments = graphene.List(CommentType) | ||
all_tags = graphene.List(TagType) | ||
|
||
author_by_id = graphene.Field(AuthorType, id=graphene.Int()) | ||
category_by_id = graphene.Field(CategoryType, id=graphene.Int()) | ||
article_by_id = graphene.Field(ArticleType, id=graphene.Int()) | ||
# comment_by_id = graphene.Field(CommentType, id=graphene.Int()) | ||
# tag_by_id = graphene.Field(TagType, id=graphene.Int()) | ||
|
||
def resolve_all_authors(self, info): | ||
return Author.objects.all() | ||
|
||
def resolve_all_categories(self, info): | ||
return Category.objects.all() | ||
|
||
def resolve_all_articles(self, info, start: int=0, limit: int=20): | ||
return Article.objects.all()[start:start+limit] | ||
|
||
def resolve_all_comments(self, info): | ||
return Comment.objects.all() | ||
|
||
def resolve_all_tags(self, info): | ||
return Tag.objects.all() | ||
|
||
def resolve_author_by_id(self, info, id): | ||
return Author.objects.get(pk=id) | ||
|
||
def resolve_category_by_id(self, info, id): | ||
return Category.objects.get(pk=id) | ||
|
||
def resolve_article_by_id(self, info, id): | ||
return Article.objects.get(pk=id) | ||
|
||
# def resolve_comment_by_id(self, info, id): | ||
# return Comment.objects.get(pk=id) | ||
|
||
# def resolve_tag_by_id(self, info, id): | ||
# return Tag.objects.get(pk=id) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from graphene_django.types import DjangoObjectType | ||
from ..models import Author, Category, Article, Comment, Tag | ||
|
||
class AuthorType(DjangoObjectType): | ||
class Meta: | ||
model = Author | ||
|
||
class CategoryType(DjangoObjectType): | ||
class Meta: | ||
model = Category | ||
|
||
class ArticleType(DjangoObjectType): | ||
class Meta: | ||
model = Article | ||
|
||
class CommentType(DjangoObjectType): | ||
class Meta: | ||
model = Comment | ||
|
||
class TagType(DjangoObjectType): | ||
class Meta: | ||
model = Tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import graphene | ||
from .resolvers.queries import Query | ||
from .resolvers.mutations import Mutation | ||
|
||
schema = graphene.Schema(query=Query, mutation=Mutation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
from graphene_django.views import GraphQLView | ||
|
||
urlpatterns = [ | ||
# ... | ||
path("graphql", GraphQLView.as_view(graphiql=True)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.