pocolifo / noter-backend

0 stars 0 forks source link

API v1 #1

Closed YoungerMax closed 11 months ago

YoungerMax commented 1 year ago

Objects

Date

All dates are UTC ISO 8601 dates

Example: 2023-06-19T01:17:05.565Z

IDs

All IDs are UUID 4

Example: 90da6511-685e-4538-a2cf-19c112616c8f

User

Example:

{
    "id": "90da6511-685e-4538-a2cf-19c112616c8f",
    "email": "example@example.com",
    "lastSignedIn": "2023-06-19T01:17:05.565Z",
    "joinedOn": "2023-06-19T01:17:05.565Z",
    "history": [
        {
            "type": "studentTypeSurveyResponse",
            "timestamp": "2023-06-19T01:17:05.565Z",
            "data": {
                "responded": "college"
            }
        }
    ]
}

history explanation

Note

{
    "id": "4f91ef86-70ae-42ef-b156-81566bd4230b",
    "type": "note",
    "metadata": {
        "name": "3.5.2 Example name",
        "path": ["3. Computers", "3.5 folder inside a folder"],
        "lastEdited": "2023-06-19T01:17:05.565Z",
        "createdOn": "2023-06-19T01:17:05.565Z",
        "owner": {
            "id": "90da6511-685e-4538-a2cf-19c112616c8f",
            "email": "example@example.com",
            "lastSignedIn": "2023-06-19T01:17:05.565Z",
            "joinedOn": "2023-06-19T01:17:05.565Z",
            "history": [
                {
                    "type": "studentTypeSurveyResponse",
                    "timestamp": "2023-06-19T01:17:05.565Z",
                    "data": {
                        "responded": "college"
                    }
                }
            ]
        }
    },
    "blocks": [
        {
            "type": "text",
            "data": {
                "content": "<serialized data>"
            }
        },
        {
            "type": "image",
            "data": {
                "url": "<serialized URL data>"
            }
        }
    ]
}

Folder

{
    "id": "4f91ef86-70ae-42ef-b156-81566bd4230b",
    "type": "folder",
    "metadata": {
        "name": "3. Computers",
        "path": [],
        "lastEdited": "2023-06-19T01:17:05.565Z",
        "createdOn": "2023-06-19T01:17:05.565Z",
        "owner": {
            "id": "90da6511-685e-4538-a2cf-19c112616c8f",
            "email": "example@example.com",
            "lastSignedIn": "2023-06-19T01:17:05.565Z",
            "joinedOn": "2023-06-19T01:17:05.565Z",
            "history": [
                {
                    "type": "studentTypeSurveyResponse",
                    "timestamp": "2023-06-19T01:17:05.565Z",
                    "data": {
                        "responded": "college"
                    }
                }
            ]
        }
    }
}

Authentication

Endpoints

GET /

Authentication accepted, but not required No request body accepted at all. Return 400 Bad Request if a body is given.

Description

Get server status, server information, user information

Return

POST /items/list

Must be authenticated.

Description

Because the notes/folders are being implemented by a file system, this endpoint lists notes in a path

Request Body

Return

DELETE /items/delete

Must be authenticated. Deny request bodies with 400 Bad Request.

Description

Delete resources (notes or folders) by ID

Query Params

Return

POST /items/create/note

Must be authenticated.

Description

This endpoint creates a note and returns the created note

Request Body

Return

POST /items/create/studyguide

Must be authenticated.

Description

This endpoint creates a study guide and returns it. Important: study guides are notes, just auto-generated on the server.

Request Body

Return

POST /items/create/folder

Must be authenticated.

Description

This endpoint creates a folder and returns the created folder

Request Body

Return

POST /items/update/metadata

Must be authenticated.

Description

Update a resource's (folder/note) metadata (path/name) by ID

Query Params

Request Body

Return

PUT /items/update/blocks

Must be authenticated.

Description

Update the contents (blocks) in a note by its ID

Query Params

Request Body

Return

YoungerMax commented 1 year ago

In v2, make note saving incremental

aodhfionn commented 1 year ago

We should use a shorter hash instead of a full-length UUID 4. We could truncate the length of the UUID 4 to about 6-8 characters.

The possibility of hash collision can be avoided by implementing a fail-safe that checks if the newly truncated id matches an id that already exists, and then just re-generate it.