Skip to content
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

Mobile Development #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,55 @@ Before running the project, ensure that you have the following installed:

3. Inside the project directory, you will find three main folders: `frontend`, `backend`, and `venv`.

## Frontend (ReactNative)

1. Change to the `frontendMobile` directory:

```bash
cd frontendMobile
```

2. Install the required dependencies:

```bash
npm install
npm i -g expo-cli
```

3. Run the development server:

```bash
npm start
```

This will create an Expo server, which you can access through your mobile device by scanning the QR Code.

## Backend (Django)

1. Change to the `backend` directory:

=======

- [Git](https://git-scm.com/)
- [Node.js](https://nodejs.org/)
- [Python](https://www.python.org/)

## Getting Started

1. Clone the repository to your local machine using the following command:

```bash
git clone https://github.com/nov8devs/stoistrom.git
```

2. Navigate to the project directory:

```bash
cd stoistrom
```

3. Inside the project directory, you will find three main folders: `frontend`, `backend`, and `venv`.

## Frontend (React)

1. Change to the `frontend` directory:
Expand All @@ -54,6 +103,7 @@ Before running the project, ensure that you have the following installed:

1. Change to the `backend` directory:


```bash
cd backend
```
Expand All @@ -76,3 +126,4 @@ Before running the project, ensure that you have the following installed:

to contribute fork this respository, make changes create a pull request. a maintainer will check the pull request by the soonest. refer to [code of conduct](https://github.com/nov8devs/stoistrom/blob/main/CODE_OF_CONDUCT.md) for more details

=======
Binary file modified backend/backend/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file modified backend/backend/__pycache__/urls.cpython-310.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
'journaling.apps.JournalingConfig',
]

CORS_ALLOWED_ORIGINS = ['http://localhost:5173']
CORS_ALLOWED_ORIGINS = [
'http://localhost:5173',
'exp://192.168.254.15:8081',]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
Expand Down
Binary file modified backend/db.sqlite3
Binary file not shown.
Binary file modified backend/journaling/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file modified backend/journaling/__pycache__/models.cpython-310.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion backend/journaling/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin
from .models import Journal, JournalPage
from .models import Journal, JournalPage, JournalType

# Register your models here.
admin.site.register(Journal)
admin.site.register(JournalPage)
admin.site.register(JournalType)
Binary file modified backend/journaling/api/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified backend/journaling/api/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified backend/journaling/api/__pycache__/views.cpython-310.pyc
Binary file not shown.
15 changes: 10 additions & 5 deletions backend/journaling/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
from rest_framework import serializers
from ..models import Journal, JournalPage


class JournalSerializer(serializers.ModelSerializer):
class Meta:
model = Journal
fields = ['id', 'user', 'journal_type', 'date_completed']
fields = ['id', 'journal_type', 'date_started', 'date_last_edited']


class JournalPageSerializer(serializers.ModelSerializer):
class Meta:
model = JournalPage
fields = ['id', 'prompt', 'entry', 'image']

fields = ['id', 'journal', 'prompt', 'entry', 'image']

# Handling POST requests from our Frontend
class CreateJournal(serializers.ModelSerializer):
journal_type_id = serializers.IntegerField(write_only=True)
class Meta:
model = Journal
fields = ['journal_type_id']

class CreateJournalPage(serializers.ModelSerializer):
journal_id = serializers.IntegerField(write_only=True)
class Meta:
model = JournalPage
fields = ['prompt', 'entry']
fields = ['journal_id', 'prompt', 'entry']
8 changes: 6 additions & 2 deletions backend/journaling/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import JournalViewSet, JournalPageViewSet, CreateJournalPageView
from .views import JournalViewSet, JournalPageViewSet, CreateJournalPageView, CreateJournalView, ListJournalView


journal_router = DefaultRouter()
journal_router.register(r'journal', JournalViewSet)
journal_router.register(r'journal_page', JournalPageViewSet)


# All the backend endpoints, starting with api/{endpoint}
urlpatterns = [
path('', include(journal_router.urls)),
path('create/', CreateJournalPageView.as_view())
path('create/', CreateJournalPageView.as_view()),
path('create_journal/', CreateJournalView.as_view()),
path('list_journals/', ListJournalView.as_view())
]
74 changes: 67 additions & 7 deletions backend/journaling/api/views.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,90 @@
from rest_framework import viewsets, status
from ..models import Journal, JournalPage
from .serializers import JournalSerializer, JournalPageSerializer, CreateJournalPage
from ..models import Journal, JournalPage, JournalType
from .serializers import JournalSerializer, JournalPageSerializer, CreateJournalPage, CreateJournal
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.generics import ListAPIView


# Backend Viewsets
class JournalViewSet(viewsets.ModelViewSet):
queryset = Journal.objects.all()
serializer_class = JournalSerializer

def create(self, request, *args, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer.data)
return Response(serializer.data)

def update(self, request, *args, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
return Response(serializer.data)

def destroy(self, request, *args, **kwargs):
instance = self.get_object()
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)


class JournalPageViewSet(viewsets.ModelViewSet):
queryset = JournalPage.objects.all()
serializer_class = JournalPageSerializer

def create(self, request, *args, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer.data)
return Response(serializer.data)

#Handling POST requests from frontend.
def update(self, request, *args, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
return Response(serializer.data)

def destroy(self, request, *args, **kwargs):
instance = self.get_object()
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)

# Handling POST requests from frontend.
# These will NOT be used in the future.
class CreateJournalPageView(APIView):
serializer_class = CreateJournalPage

def post(self, request):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
prompt = serializer.data.get("prompt")
entry = serializer.data.get("entry")
journal_page = JournalPage.objects.create(prompt=prompt, entry=entry)
journal_id = serializer.validated_data.get("journal_id")
prompt = serializer.validated_data.get("prompt")
entry = serializer.validated_data.get("entry")
journal = Journal.objects.get(id=int(journal_id))
journal_page = JournalPage.objects.create(journal=journal, prompt=prompt, entry=entry)
journal_page.save()
return Response(JournalPageSerializer(journal_page).data, status=status.HTTP_201_CREATED)
return Response({'Bad Request': 'Invalid data...'}, status=status.HTTP_400_BAD_REQUEST)

class CreateJournalView(APIView):
serializer_class = CreateJournal

def post(self, request):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
_type = serializer.validated_data.get("journal_type_id")
journal_type = JournalType.objects.get(id=int(_type))
journal = Journal.objects.create(journal_type=journal_type)
journal.save()
return Response(JournalSerializer(journal).data, status=status.HTTP_201_CREATED)
return Response({'Bad Request': 'Invalid data...'}, status=status.HTTP_400_BAD_REQUEST)


# Sending responses to Frontend
class ListJournalView(ListAPIView):
queryset = Journal.objects.all()
serializer_class = JournalSerializer
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2023-11-28 03:13

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('journaling', '0003_remove_journalpage_journal'),
]

operations = [
migrations.RemoveField(
model_name='journal',
name='user',
),
migrations.AddField(
model_name='journalpage',
name='journal',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='journaling.journal'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2023-11-28 03:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('journaling', '0004_remove_journal_user_journalpage_journal'),
]

operations = [
migrations.RenameField(
model_name='journal',
old_name='date_completed',
new_name='date_started',
),
migrations.AddField(
model_name='journal',
name='date_last_edited',
field=models.DateTimeField(auto_now=True),
),
]
18 changes: 18 additions & 0 deletions backend/journaling/migrations/0006_alter_journal_journal_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2023-11-28 16:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('journaling', '0005_rename_date_completed_journal_date_started_and_more'),
]

operations = [
migrations.AlterField(
model_name='journal',
name='journal_type',
field=models.CharField(choices=[('0', 'Empty Page'), ('1', 'Random Prompt')], max_length=2, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.7 on 2023-11-30 13:12

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('journaling', '0006_alter_journal_journal_type'),
]

operations = [
migrations.CreateModel(
name='JournalTypes',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=25)),
],
),
migrations.AlterField(
model_name='journal',
name='journal_type',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='journaling.journaltypes'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.7 on 2023-11-30 13:27

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('journaling', '0007_journaltypes_alter_journal_journal_type'),
]

operations = [
migrations.CreateModel(
name='JournalType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(default='Empty Page', max_length=25)),
('description', models.TextField()),
],
),
migrations.AddField(
model_name='journal',
name='name',
field=models.CharField(default='Journal', max_length=50),
),
migrations.AlterField(
model_name='journal',
name='journal_type',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='journaling.journaltype'),
),
migrations.DeleteModel(
name='JournalTypes',
),
]
21 changes: 10 additions & 11 deletions backend/journaling/models.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from django.contrib.auth.models import User
from django.db import models

# Create your models here.
class JournalType(models.Model):
name = models.CharField(max_length=25, default='Empty Page')
description = models.TextField(null=False)

class Journal(models.Model):
TYPES = [
('0', 'Empty Page'),
('1', "Random Prompt"),
]

user = models.ForeignKey(User, on_delete=models.CASCADE)
journal_type = models.CharField(max_length=2, choices=TYPES)
date_completed = models.DateTimeField(auto_now_add=True)

class Journal(models.Model):
name = models.CharField(max_length=50, default='Journal')
journal_type = models.ForeignKey(JournalType, on_delete=models.CASCADE, null=True)
date_started = models.DateTimeField(auto_now_add=True)
date_last_edited = models.DateTimeField(auto_now=True)

class JournalPage(models.Model):
prompt = models.CharField(max_length=120)
journal = models.ForeignKey(Journal, on_delete=models.CASCADE, null=True)
prompt = models.CharField(max_length=120, blank=False)
entry = models.TextField(null=True)
image = models.ImageField(null=True)
Loading