Skip to content

Commit ac72c5e

Browse files
authored
Merge pull request #8 from Tech-JI/restful/main
fix all the existing issues
2 parents 3ae75a3 + c9602b0 commit ac72c5e

10 files changed

Lines changed: 175 additions & 257 deletions

File tree

.husky/pre-commit

Lines changed: 0 additions & 5 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: format-and-add
5+
name: Format code and stage changes
6+
entry: uv run scripts/pre-commit-format.py
7+
language: system
8+
pass_filenames: false
9+
always_run: true

apps/web/models/vote.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ def vote(self, value, course_id, category, user):
3131
else:
3232
vote.value = value
3333
vote.save()
34-
# add the new value of the vote
35-
if category == Vote.CATEGORIES.QUALITY:
36-
course.quality_score += vote.value
37-
elif category == Vote.CATEGORIES.DIFFICULTY:
38-
course.difficulty_score += vote.value
3934

4035
new_score = self._calculate_average_score(course, category)
4136
if category == Vote.CATEGORIES.QUALITY:

apps/web/views.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
authentication_classes,
2323
permission_classes,
2424
)
25-
from rest_framework.permissions import AllowAny
25+
from rest_framework.permissions import AllowAny, IsAuthenticated
2626
from rest_framework.response import Response
2727

2828

@@ -377,7 +377,7 @@ def course_search_api(request):
377377

378378

379379
@api_view(["GET"])
380-
@permission_classes([AllowAny])
380+
@permission_classes([IsAuthenticated])
381381
def course_review_search_api(request, course_id):
382382
try:
383383
course = Course.objects.get(pk=course_id)
@@ -388,9 +388,7 @@ def course_review_search_api(request, course_id):
388388
reviews = course.search_reviews(query)
389389
review_count = reviews.count()
390390

391-
if not request.user.is_authenticated:
392-
reviews = reviews[: LIMITS["unauthenticated_review_search"]]
393-
391+
# Since we now require authentication, no need to limit reviews
394392
serializer = ReviewSerializer(reviews, many=True, context={"request": request})
395393

396394
return Response(
@@ -399,11 +397,7 @@ def course_review_search_api(request, course_id):
399397
"course_id": course.id,
400398
"course_short_name": course.short_name(),
401399
"reviews_full_count": review_count,
402-
"remaining": (
403-
review_count - LIMITS["unauthenticated_review_search"]
404-
if review_count > LIMITS["unauthenticated_review_search"]
405-
else 0
406-
),
400+
"remaining": 0, # No remaining since user is authenticated
407401
"reviews": serializer.data,
408402
}
409403
)

docs/Setup.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Environment:
1818

1919
4. `uv sync`
2020

21-
5. Make directory for builds of static files: `mkdir staticfiles`
21+
5. `uv run pre-commit install` (for installing git hook in .git)
2222

23-
6. Create .env file for storing secrets. The contents should be like:
23+
6. Make directory for builds of static files: `mkdir staticfiles`
24+
25+
7. Create .env file for storing secrets. The contents should be like:
2426

2527
```ini
2628
# PostgreSQL
@@ -34,9 +36,9 @@ Environment:
3436
OFFERINGS_THRESHOLD_FOR_TERM_UPDATE=100
3537
```
3638

37-
7. Build static files: `make collect`
39+
8. Build static files: `make collect`
3840

39-
8. Configure database
41+
9. Configure database
4042

4143
1. Install Postgres:
4244

@@ -89,11 +91,11 @@ Environment:
8991

9092
10. Auto setup database connection and static file routes in Django: `make migrate`, `make makemigrations`
9193

92-
9. Install cache database redis: `sudo apt install redis-server`, `sudo systemctl start redis`. Run `sudo systemctl enable redis` to auto-start redis service on start-up.
94+
10. Install cache database valkey: `sudo apt install valkey`, `sudo systemctl start valkey`. Run `sudo systemctl enable valkey` to auto-start valkey service on start-up.
9395

94-
10. `make run` and visit <http://127.0.0.1:8000/>
96+
11. `make run` and visit <http://127.0.0.1:8000/>
9597

96-
11. Add local admin:
98+
12. Add local admin:
9799

98100
1. `make createsuperuser`. The email can be blank. Use a strong password in production.
99101

@@ -110,7 +112,7 @@ Environment:
110112
u.save()
111113
```
112114

113-
12. Crawl data from JI official website:
115+
13. Crawl data from JI official website:
114116

115117
1. Edit `COURSE_DETAIL_URL_PREFIX` in `apps/spider/crawlers/orc.py`: Add a number after url param `id` like this: `...?id=23`, so only course id starting from 23 (e.g. 230-239, 2300) will be crawled, so as to save time during development. Remember not to commit this change.
116118

@@ -123,4 +125,4 @@ Environment:
123125
crawl_and_import_data()
124126
```
125127

126-
13. Run frontend (dev mode): `make dev-frontend` and visit http://127.0.0.1:5173/
128+
14. Run frontend (dev mode): `make dev-frontend` and visit http://127.0.0.1:5173/

docs/Structure.md

Lines changed: 0 additions & 218 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ dependencies = [
2626

2727
[tool.uv]
2828
package = false
29+
30+
[dependency-groups]
31+
dev = [
32+
"pre-commit>=4.3.0",
33+
]

scripts/pre-commit-format.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
import sys
5+
6+
7+
def main():
8+
"""Pre-commit formatting script"""
9+
print("Running formatter...")
10+
11+
try:
12+
# Run make format and capture exit code
13+
result = subprocess.run(["make", "format"], check=True)
14+
15+
# Format succeeded, stage the changes
16+
subprocess.run(["git", "add", "--update"], check=True)
17+
print("formatted.")
18+
return 0
19+
20+
except subprocess.CalledProcessError:
21+
# Format failed, stop the commit
22+
print("ERROR: Formatting failed! Commit aborted.")
23+
return 1
24+
25+
26+
if __name__ == "__main__":
27+
sys.exit(main())

0 commit comments

Comments
 (0)