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

Backend: Merge Dev to Main #692

Closed
wants to merge 161 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
92a97bb
be able to fetch meanings
Oct 26, 2024
15a1f5d
Searching for diferent labels but not done yet
Oct 26, 2024
648a3c7
be able to get word information
Oct 27, 2024
7b5a80b
be able to fetch the categorical words as narrower and broader meanin…
Oct 28, 2024
00562fa
added cefr level csv files
Oct 30, 2024
cbfbab3
added csv and csv processing and add sleeps for lexvo fetching
Oct 30, 2024
3cea5a1
written codes which fetches lexvo and writes to the csv files for mig…
Oct 31, 2024
98ddfa4
populate tables written code
Nov 1, 2024
4ef6d2f
added a custom commands folder for populating the database
Nov 1, 2024
6a8ae46
writen the command automation functions for migrating and lexvo but n…
Nov 1, 2024
1ca1419
we are partially able to write to csv
Nov 1, 2024
6c3ef3a
deleted the datas
Nov 1, 2024
d523007
Merge pull request #472 from bounswe/Backend-Like-Unlike-Post
oktayozel Nov 5, 2024
004b2e3
populated the database and the csvs
Nov 16, 2024
9411637
written endpoints for fetching data
Nov 16, 2024
d11bc27
Revert "activity_streams_model"
oktayozel Nov 19, 2024
9147a8a
Merge pull request #511 from bounswe/revert-510-activity_streams_oktay
oktayozel Nov 19, 2024
4843239
Update models.py
oktayozel Nov 19, 2024
8ae98d4
Update postviews.py
oktayozel Nov 19, 2024
980ef75
Update follow_unfollow.py
oktayozel Nov 19, 2024
856f7c6
Update comments.py
oktayozel Nov 19, 2024
fe21eb5
Create backend-dev.yml
arastasci Nov 19, 2024
b79d84b
added command to dockerfile
Nov 19, 2024
21a8964
Merge branch 'BACKEND-DEV' into BACKEND-458
kaanyolcu22 Nov 19, 2024
5df1191
Merge pull request #514 from bounswe/BACKEND-458
kaanyolcu22 Nov 19, 2024
2b21e7c
activity streams and post endpoints are rewritten
oktayozel Nov 19, 2024
c178957
post endpoints
oktayozel Nov 19, 2024
a25e2ab
urls of activity streams and posts
oktayozel Nov 19, 2024
66ff0c5
user feed
oktayozel Nov 19, 2024
8463d82
refactoring get feed view
oktayozel Nov 19, 2024
4ceb898
mock profile removal
oktayozel Nov 19, 2024
8fee8bd
Merge branches 'main' and 'lab-5' of https://github.com/bounswe/bouns…
arastasci Nov 20, 2024
96f14a0
Add foreign key to quiz model
arastasci Nov 20, 2024
ba64430
create comment model
arastasci Nov 20, 2024
f70925c
Merge branch 'BACKEND-DEV' of https://github.com/bounswe/bounswe2024g…
arastasci Nov 20, 2024
fb681b3
Merge branch 'BACKEND-524' into BACKEND-DEV
arastasci Nov 20, 2024
afb1b15
Merge branch 'BACKEND-DEV' into BACKEND-519
arastasci Nov 20, 2024
02fdfbb
Merge branch 'BACKEND-DEV' into get_activity_streams
oktayozel Nov 20, 2024
f4113b1
Merge pull request #516 from bounswe/get_activity_streams
oktayozel Nov 20, 2024
2060d11
remove mockdata creation code
arastasci Nov 20, 2024
17fa439
implement initial endpoints
arastasci Nov 20, 2024
92743fb
reference db volume in docker-compose.yml
arastasci Nov 21, 2024
2fb88b8
bookmark model added
oktayozel Nov 21, 2024
3e8f1db
create new docker-compose for BACKEND-DEV
arastasci Nov 21, 2024
734527f
deleted unecessary files
oktayozel Nov 21, 2024
8a74729
Merge pull request #533 from bounswe/BACKEND-530
kaanyolcu22 Nov 21, 2024
dcff712
bookmark endpoints
oktayozel Nov 21, 2024
e7b684a
bookmark urls
oktayozel Nov 21, 2024
3240621
Merge pull request #534 from bounswe/bookmarks
oktayozel Nov 21, 2024
d318006
Merge branch 'BACKEND-DEV' into BACKEND-519
arastasci Nov 21, 2024
7cd507a
refresh token feature
oktayozel Nov 21, 2024
532eec4
Update urls.py
oktayozel Nov 21, 2024
ae9ec06
authentication tests
oktayozel Nov 21, 2024
1e95f97
tests and susbtantial updates for posts and profile views
oktayozel Nov 21, 2024
50c9f19
Merge pull request #538 from bounswe/BACKEND-TESTS
oktayozel Nov 21, 2024
54d0d9e
perform health check
arastasci Nov 21, 2024
f83654a
delete profile being referenced in user
arastasci Nov 22, 2024
2ac8fee
Merge pull request #543 from bounswe/BACKEND-DEV-MODEL-FIX
arastasci Nov 22, 2024
83af939
fix serializer - signal discrepancy
arastasci Nov 22, 2024
4fbb7c4
Merge pull request #544 from bounswe/BACKEND-DEV-MODEL-FIX
alitariksahin Nov 22, 2024
0fc7287
fix feed tag list referencing issue
arastasci Nov 22, 2024
d5daed9
Merge pull request #545 from bounswe/BACKEND-DEV-MODEL-FIX
alitariksahin Nov 22, 2024
b3a4733
Merge branch 'BACKEND-DEV' into BACKEND-519
arastasci Nov 22, 2024
f5170cb
implement quiz creation endpoint with graceful discrepancy handling
arastasci Nov 22, 2024
810026d
implement to_representation for quizserializer to refine the tags
arastasci Nov 22, 2024
f43d750
create start quiz endpoint
arastasci Nov 22, 2024
4419b03
implement solve quiz endpoint
arastasci Nov 22, 2024
050bcc8
implement submit quiz endpoint
arastasci Nov 22, 2024
374303d
health check and backend_dev shell script for AWS instance
arastasci Nov 22, 2024
ce9ff2c
post + comment baglantisi
oktayozel Nov 22, 2024
454adb7
Merge pull request #552 from bounswe/commentpostintegration
oktayozel Nov 22, 2024
03e6972
aaahsdujnv
oktayozel Nov 22, 2024
df216ae
recursive comments
oktayozel Nov 22, 2024
6234902
like_unlike problem solution
skywllker Nov 22, 2024
a8884cb
Merge pull request #553 from bounswe/BACKEND-550
skywllker Nov 22, 2024
626a368
username in profile added
oktayozel Nov 22, 2024
2bd15e5
fix
oktayozel Nov 22, 2024
0c5f5a1
is liked and is bookmarked
oktayozel Nov 22, 2024
0288c4d
view other profiles
skywllker Nov 22, 2024
f2da378
Merge pull request #557 from bounswe/BACKEND-554
skywllker Nov 22, 2024
16d303f
delete duplicate code
skywllker Nov 22, 2024
aa1b430
Merge pull request #558 from bounswe/BACKEND-554
skywllker Nov 22, 2024
4ac53bc
imp: make meaningful urls
arastasci Nov 23, 2024
64b8035
feat: proper quiz submission and retrieve all questions in start quiz
arastasci Nov 23, 2024
0e260f6
feat: drive from quiz progress and proper quiz results representations
arastasci Nov 23, 2024
2387413
Merge branch 'BACKEND-DEV' into BACKEND-519
arastasci Nov 23, 2024
18be31f
Merge pull request #573 from bounswe/BACKEND-519
arastasci Nov 23, 2024
8eef93b
giving environment variables
Nov 23, 2024
85eaa29
added like count and modified is liked and is bookmarked
Nov 23, 2024
4a97bfe
tested
Nov 23, 2024
0b7da0d
Merge pull request #581 from bounswe/BACKEND-478
kaanyolcu22 Nov 23, 2024
899f2a0
about field to profile added
oktayozel Nov 23, 2024
db8d215
feat: remove time limit
arastasci Nov 23, 2024
3f206e0
feat: quiz like, bookmark
arastasci Nov 23, 2024
adde841
Update serializers.py
oktayozel Nov 23, 2024
609ee9a
feat: provide the result url after quiz submission
arastasci Nov 23, 2024
f75a82b
feat: return quiz question count and quiz title in start quiz endpoint
arastasci Nov 23, 2024
5975dbf
fixed various things I do not know
Nov 23, 2024
b6eb758
feat: add average score to representation; fix: save times_taken and …
arastasci Nov 23, 2024
7c52466
Merge branch 'BACKEND-DEV' into BACKEND-583-updated
arastasci Nov 23, 2024
6d5143d
Merge pull request #594 from bounswe/BACKEND-583-updated
kaanyolcu22 Nov 23, 2024
e6292c4
Merge branch 'BACKEND-DEV' into BACKEND-585
arastasci Nov 23, 2024
976f62d
Merge pull request #596 from bounswe/BACKEND-585
arastasci Nov 23, 2024
5823e05
added the seperate endpoints for translations and meanings
Nov 23, 2024
c434204
activity streams fix
oktayozel Nov 24, 2024
847468d
fix follow with username
oktayozel Nov 24, 2024
5fcd950
get_post_details conversion from GET to POST
oktayozel Nov 24, 2024
a9dd484
another fix related to author in post
oktayozel Nov 24, 2024
cc4fdea
fix: execute on build script on /bin/bash
arastasci Nov 24, 2024
21b2a6d
Update postviews.py
oktayozel Nov 24, 2024
e3b47e8
feed hot fix for username
oktayozel Nov 24, 2024
19e4d54
feat: add liked quizzes and bookmarked quizzes endpoints
arastasci Nov 24, 2024
04709c9
feat: add solved quizzes and created quizzes view endpoints
arastasci Nov 24, 2024
805ae07
fix: liked quizzes api view and url - view
arastasci Nov 24, 2024
5175c74
improve: see every user's created quizzes and solved quizzes given th…
arastasci Nov 24, 2024
39c3c13
Merge pull request #611 from bounswe/BACKEND-610
YavizGuldalf Nov 24, 2024
00effa9
feat: add following, followers endpoints for profile, also update pro…
arastasci Nov 24, 2024
aeec240
Merge pull request #616 from bounswe/BACKEND-613
YavizGuldalf Nov 24, 2024
99a222c
search algorithm for user, quiz, post, comment
skywllker Nov 24, 2024
1ac9286
Merge pull request #621 from bounswe/BACKEND-617
skywllker Nov 24, 2024
036e9ba
access token expire time update to 1 day
oktayozel Nov 24, 2024
54d677b
feat: add quiz review endpoint
arastasci Nov 24, 2024
653485d
feat: add level to quiz results response
arastasci Nov 24, 2024
58d08de
fix: create result url after quiz views with quiz progress id
arastasci Nov 24, 2024
dd67d2f
fix: query with quiz progress id
arastasci Nov 24, 2024
d22a807
fix: add quiz progress field to quizresults model
arastasci Nov 24, 2024
f1c6eda
feat: add quiz_result_id and is_solved fields to quiz/<int:quiz_id> e…
arastasci Nov 24, 2024
c6f6d12
impr: add author to post details
arastasci Nov 24, 2024
372b973
Merge pull request #628 from bounswe/BACKEND-627
aoengin Nov 24, 2024
681138c
Merge pull request #633 from bounswe/BACKEND-632
arastasci Nov 24, 2024
614989c
returning follower count as well
oktayozel Nov 24, 2024
19146bb
bookmark error fix
oktayozel Nov 24, 2024
1fcee11
follower count hot fix
oktayozel Nov 24, 2024
d2cc48a
bookmark isi
oktayozel Nov 24, 2024
c81d7cc
bookmark fix try2
oktayozel Nov 24, 2024
0dde5a8
bookmark fix 3
oktayozel Nov 24, 2024
553b147
get bookmarked post
oktayozel Nov 24, 2024
1b1f991
fix: profile update pass request in context + check get posts
arastasci Nov 24, 2024
789c099
impr: do posts filtering after request check
arastasci Nov 24, 2024
79ebf06
update profile fix
oktayozel Nov 24, 2024
4e4bf8c
Merge branch 'BACKEND-DEV' into BACKEND-649
arastasci Nov 24, 2024
39e0f7a
Merge pull request #650 from bounswe/BACKEND-649
arastasci Nov 24, 2024
f04a304
hotfix: syntax error 🙏
arastasci Nov 24, 2024
8016533
comment serializer
oktayozel Nov 24, 2024
8acf1d8
comment isliked field
oktayozel Nov 24, 2024
ceaab39
revert back
oktayozel Nov 24, 2024
801f310
feat: quiz recommendation
arastasci Nov 24, 2024
daf8a44
Merge pull request #659 from bounswe/BACKEND-657
aoengin Nov 24, 2024
1d0c1e5
fetching true result
Nov 24, 2024
f9b274d
Merge branch 'BACKEND-DEV' into BACKEND-600
kaanyolcu22 Nov 24, 2024
37aaa99
Merge pull request #608 from bounswe/BACKEND-600
kaanyolcu22 Nov 24, 2024
e906cd3
impr: optimize database word population
arastasci Nov 24, 2024
4988fa7
Merge pull request #665 from bounswe/BACKEND-664
arastasci Nov 25, 2024
21137ef
feat: implement review latest quiz attempt for a given quiz endpoint
arastasci Nov 25, 2024
e53f153
tests: some quiz endpoints.
arastasci Nov 25, 2024
5de77d7
Merge pull request #671 from bounswe/BACKEND-666
arastasci Nov 25, 2024
569d893
Merge pull request #673 from bounswe/BACKEND-672
arastasci Nov 25, 2024
68fe833
fix: return unique quiz instances in solved quizzes endpoint
arastasci Nov 25, 2024
4345bf8
Merge pull request #679 from bounswe/BACKEND-678
kaanyolcu22 Nov 25, 2024
dad94a8
Added lexvo endpoints
Nov 25, 2024
0a46de6
Merge pull request #689 from bounswe/BACKEND-688
arastasci Nov 25, 2024
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
26 changes: 26 additions & 0 deletions .github/workflows/backend-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy Backend Dev

on:
push:
branches:
- BACKEND-DEV

jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set Up Docker Environment
run: |
docker version
docker-compose version

- name: Build and Start Docker Containers
run: |
docker-compose down # Stop any running containers
docker-compose up -d # Start containers in detached mode

- name: Verify Running Containers
run: docker ps
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

__pycache__/
venv/
.venv/
*.pyc
staticfiles
static
Expand Down
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ ENV PYTHONUNBUFFERED 1
EXPOSE 8000

# Run the Django development server
CMD python manage.py makemigrations && python manage.py makemigrations app && python manage.py migrate && python manage.py runserver 0.0.0.0:8000
CMD python manage.py makemigrations && python manage.py makemigrations app && python manage.py migrate && python manage.py populate_db_file data/db_files/words.csv data/db_files/translations.csv data/db_files/relationships.csv && python manage.py runserver 0.0.0.0:8000
10 changes: 0 additions & 10 deletions backend/app/apps.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
from django.apps import AppConfig
import requests
from django.db.models.signals import post_migrate, post_init

import json


def create_mockdata(**kwargs):
from .mock_data_manager import create_quiz_mockdata
create_quiz_mockdata()


class AppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app'

def ready(self):
post_migrate.connect(create_mockdata, sender=self)
import app.signals # Import the signals to ensure they are registered





18 changes: 18 additions & 0 deletions backend/app/management/commands/clear_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.core.management.base import BaseCommand
from ...models import Word, Translation, Relationship

class Command(BaseCommand):
help = 'Clear all data from the Word, Translation, and Relationship tables'

def handle(self, *args, **kwargs):
self.stdout.write("Clearing all data from the database...")

try:
# Delete all records from the models
Translation.objects.all().delete()
Relationship.objects.all().delete()
Word.objects.all().delete()

self.stdout.write(self.style.SUCCESS("All data cleared successfully!"))
except Exception as e:
self.stderr.write(self.style.ERROR(f"Error: {e}"))
77 changes: 77 additions & 0 deletions backend/app/management/commands/fetch_and_save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
import csv
from django.core.management.base import BaseCommand
from app.word_service.csv_service import fetch_and_save_data

class Command(BaseCommand):
help = 'Fetch the first k words from the CSV file and save to new CSV files'

def handle(self, *args, **options):
ab_filename = 'vocabulary_level_ab'
c_filename = 'vocabulary_level_c'
input_csv_path_ab = f'/app/data/cefr_files/{ab_filename}.csv'
input_csv_path_c = f'/app/data/cefr_files/{c_filename}.csv'
output_path = f'/app/data/db_files'
progress_file_ab = f'/app/data/progress_ab.txt'
progress_file_c = f'/app/data/progress_c.txt'

# Read progress from files
start_row_ab = self.get_progress(progress_file_ab)
start_row_c = self.get_progress(progress_file_c)

# Process first file
words_ab = self.read_csv(input_csv_path_ab)
self.process_words(
words_ab, start_row_ab, progress_file_ab, output_path
)

# Process second file
words_c = self.read_csv(input_csv_path_c)
self.process_words(
words_c, start_row_c, progress_file_c, output_path
)

def get_progress(self, progress_file):
if os.path.exists(progress_file):
with open(progress_file, 'r') as file:
return int(file.read().strip())
return 0

def save_progress(self, progress_file, row_number):
with open(progress_file, 'w') as file:
file.write(str(row_number))

def read_csv(self, csv_path):
words = []
try:
with open(csv_path, 'r', encoding='utf-8') as file:
reader = csv.DictReader(file)
for row in reader:
words.append(row)
except FileNotFoundError:
self.stdout.write(self.style.ERROR(f"Input file '{csv_path}' not found."))
return words

def process_words(self, words, start_row, progress_file, output_path):
if not words:
self.stdout.write(self.style.ERROR("No words to process. Exiting process_words."))
return

self.stdout.write(self.style.NOTICE(f"Starting from row {start_row}. Total rows: {len(words)}"))

for i in range(start_row, len(words)):
try:
self.stdout.write(self.style.NOTICE(f"Processing row {i}..."))
fetch_and_save_data(
words,
output_path,
i,
i + 1,
update_checkpoint=lambda row: self.save_progress(progress_file, row)
)
except Exception as e:
self.stdout.write(self.style.ERROR(f"Error processing row {i}: {e}"))
break



130 changes: 130 additions & 0 deletions backend/app/management/commands/populate_db_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import csv
from django.core.management.base import BaseCommand
from ...models import Word, Translation, Relationship
import re
from collections import defaultdict

class Command(BaseCommand):
help = 'Populate the database with Words, Translations, and Relationships from CSV files'

def add_arguments(self, parser):
parser.add_argument('words_csv', type=str, help="Path to the Words CSV file")
parser.add_argument('translations_csv', type=str, help="Path to the Translations CSV file")
parser.add_argument('relationships_csv', type=str, help="Path to the Relationships CSV file")

def handle(self, *args, **kwargs):
words_csv = kwargs['words_csv']
translations_csv = kwargs['translations_csv']
relationships_csv = kwargs['relationships_csv']

self.stdout.write("Starting to populate the database...")

try:
self.populate_words(words_csv)
self.populate_translations(translations_csv)
self.populate_relationships(relationships_csv)
except Exception as e:
self.stderr.write(self.style.ERROR(f"Error: {e}"))

def populate_words(self, file_path):
with open(file_path, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)

word_dict = defaultdict(list)

for row in reader:
info_dict = {
'language': row.get('language', 'eng'),
'level': row.get('level'),
'part_of_speech': row.get('part_of_speech'),
'meaning': row.get('explanation', 'Meaning not available'),
'sentence': row.get('sentence', 'Sentence not available'),
}
word_dict[row['word']].append(info_dict)

existing_words = set(Word.objects.values_list('word', flat=True))
words_to_create = []

for word, infos in word_dict.items():
if word not in existing_words:
defaults = {
'language': ', '.join(set(info['language'] for info in infos)),
'level': ', '.join(set(info['level'] for info in infos if info['level'])),
'part_of_speech': ', '.join(set(info['part_of_speech'] for info in infos if info['part_of_speech'])),
'meaning': ', '.join(set(info['meaning'] for info in infos if info['meaning'])),
'sentence': ', '.join(set(info['sentence'] for info in infos if info['sentence'])),
}
words_to_create.append(Word(word=word, **defaults))

# Bulk create new words
if words_to_create:
Word.objects.bulk_create(words_to_create)
self.stdout.write(f"Created {len(words_to_create)} new words.")

def populate_translations(self, file_path):
with open(file_path, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)

existing_translations = set(Translation.objects.values_list('word__word', 'translation'))
words = {w.word: w for w in Word.objects.all()}
translations_to_create = []

for row in reader:
word = row['word']
translation = row['turkish_translation']

if (word, translation) not in existing_translations:
if word not in words:
words[word] = Word.objects.create(
word=word,
language='eng',
level='unknown',
part_of_speech='unknown',
meaning='Auto-created for missing translation',
sentence='No example provided',
)
translations_to_create.append(
Translation(word=words[word], translation=translation)
)

# Bulk create translations
if translations_to_create:
Translation.objects.bulk_create(translations_to_create)
self.stdout.write(f"Created {len(translations_to_create)} new translations.")

def populate_relationships(self, file_path):
with open(file_path, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)

words = {w.word: w for w in Word.objects.all()}
relationships_to_create = []

for row in reader:
word = row['word']
related_word = row['related_word']
relation_type = row['relation_type']

if not re.match(r"^[a-zA-Z-']+$", related_word):
self.stderr.write(f"Skipping invalid related word '{related_word}'.")
continue

if word not in words:
self.stderr.write(f"Word '{word}' not found. Skipping relationship.")
continue

if related_word not in words:
words[related_word] = Word.objects.create(
word=related_word,
language='eng',
level=words[word].level,
part_of_speech=words[word].part_of_speech,
)

relationships_to_create.append(
Relationship(word=words[word], related_word=words[related_word], relation_type=relation_type)
)

# Bulk create relationships
if relationships_to_create:
Relationship.objects.bulk_create(relationships_to_create)
self.stdout.write(f"Created {len(relationships_to_create)} new relationships.")
Loading
Loading