Skip to content
Draft
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
2 changes: 2 additions & 0 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
os.path.join(BASE_DIR.parent, "frontend/static"), # React frontend statics
)

AUTH_USER_MODEL = "tree_api.User"

# Settings for django webpack loader
WEBPACK_LOADER = {
"DEFAULT": {
Expand Down
6 changes: 3 additions & 3 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"""

from django.contrib import admin
from django.shortcuts import redirect
from django.urls import path, include
from django.shortcuts import redirect

urlpatterns = [
path("admin/", admin.site.urls),
path("bt_studio/", include("backend.tree_api.urls")),
path("frontend/", include("frontend.urls")),
path("", lambda request: redirect("frontend/", permanent=True)),
path("projects/", include("frontend.urls")),
path("", lambda request: redirect("/projects", permanent=True)),
]
50 changes: 50 additions & 0 deletions backend/database/db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 17.4 (Debian 17.4-1.pgdg120+2)
-- Dumped by pg_dump version 17.4 (Debian 17.4-1.pgdg120+2)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: projects; Type: TABLE; Schema: public; Owner: user-dev
--

CREATE TABLE public.projects (
id character varying(100) NOT NULL,
name character varying(100) NOT NULL,
creator integer NOT NULL,
last_modified timestamp with time zone NOT NULL,
size bigint NOT NULL
);


ALTER TABLE public.projects OWNER TO "user-dev";

--
-- Name: projects projects_pkey; Type: CONSTRAINT; Schema: public; Owner: user-dev
--

ALTER TABLE ONLY public.projects
ADD CONSTRAINT projects_pkey PRIMARY KEY (id);


--
-- PostgreSQL database dump complete
--

2 changes: 0 additions & 2 deletions backend/tree_api/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.contrib import admin

# Register your models here.
13 changes: 11 additions & 2 deletions backend/tree_api/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework.response import Response
from rest_framework.decorators import api_view
from backend.tree_api.models import User, Project
import binascii
from functools import wraps
import json
Expand All @@ -18,13 +19,21 @@
)


def error_wrapper(type: str, param: list[str | tuple] = []):
def error_wrapper(fal, type: str, param: list[str | tuple] = []):
def decorated(func):
@wraps(func)
@api_view([type])
def wrapper(request):
try:
check_parameters(request.data if type == "POST" else request.GET, param)
fal.set_user(User.objects.get(username="user"))

# Set this to bypass user
projects = Project.objects.all()
if len(projects) > 0:
fal.user.projects = 0
for project in projects:
fal.user.projects += 1
return func(request)
except CUSTOM_EXCEPTIONS as e:
print(str(e))
Expand Down Expand Up @@ -53,5 +62,5 @@ def check_parameters(request, param: list[str | tuple]):
if p not in request:
raise ParameterInvalid(p)
data = request.get(p)
if data == None or len(data) <= min_len:
if data is None or len(data) <= min_len:
raise ParameterInvalid(p)
Loading
Loading