ELTE-Clean / Clean-Administration-Platform

2 stars 1 forks source link

File Upload and Create Task Endpoint #62

Closed Mohido closed 2 years ago

Mohido commented 2 years ago

Refactored the endpoints, implemented debugging feature for the backend (Disabling auth from the env file), and implemented the file uploading and saving it to the database.

Regarding the file saving in the backend, I have decided to save the file data as VARCHAR(5000) in the database. The maximum size that can be sent at the moment is 5KB. I chose this way of saving the file after reading some articles discussing some implementations. We have a relatively small files in general, thus, we don't need to handle them in a very complicated manner. For small files, we can either go with storing the file as "BYTEA", which resembles a buffer of data in the database, or store it in a textual representation. I chose the latter one since the given file is textual. For "avatars" and images, we can store them as a sequence of bytes.

Regarding the refactoring, I almost refactored all the endpoints and I will re-document them in the Main-Endpoints issue #52.

To test the current file uploading: 1) Change the DISABLE_AUTH* in the backend/env to true. This disables the need to authenticate. Some endpoints that rely on an authorized user (Logged in user) data to run, will result in an error. 2) Run the project 3) Through using curl: curl -v -X POST -H "Content-Type: multipart/form-data" -F max=100 -F taskid=task_test_4 -F sectionid=Homework -F groupid=Group_1 -F description=@platform_build_deploy.sh -F solution=@backend/routes/groups.js http://localhost:5000/tasks/create In this test, I am pushing two files referred to as description and solution, and extra variables that are required for the creation of the task. 4) You can see the logs or open the cpgadmin portal to check the new row and its content. Note that you can also use the usual content-types, just make sure to put the solution and description files' contents as text in these variables inside the request body.

the4t4 commented 2 years ago

Resolved merge conflicts