Skip to content

Rewriting the quotefault backend in πŸš€ blazing πŸš€ fast πŸš€ and πŸš€ memory safe πŸš€ rust πŸš€

Notifications You must be signed in to change notification settings

ComputerScienceHouse/quotefault-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Quotefault Backend

API

POST /api/quote

Creates a quote

Post Data

{
    "shards": [
        {
            "body": "Erm... what the spruce?",
            "speaker": "mcdade"
        }
    ]
}

GET /api/quotes

Queries a list of quotes. With no parameters it returns the most recent 10 quotes.

Params

  • q={query} - Searches the quotes for a list of space separates keywords
  • lt={qid} - Filters for all quotes less than a given quote id. Used in pagination.
  • limit={num} - The maximum number of entries to return (default: 10)
  • submitter={username} - Filters for quotes submitted by a certain user
  • speaker={username} - Filters for quotes said by a certain user
  • involved={username} - Filters for submitter OR speaker
  • hidden={bool} - Filters for quotes that are hidden and visible to user (if admin, this means all hidden quotes. If normal user, this means their hidden quotes)
  • favorited={bool} - Filters for favorited quotes (default: false)

Response

[
    {
        "submitter": {
            "cn": "Cole Stowell",
            "uid": "cole"
        },
        "timestamp": "2023-10-24T22:03:08.254364",
        "shards": [
            {
                "body": "Erm... what the spruce?",
                "speaker": {
                    "cn": "Wilson McDade",
                    "uid": "mcdade"
                }
            }
        ],
        "id": 26,
        "vote": "upvote",
        "score": 1,
        "hidden": false,
        "favorited": true
    }
]

GET /api/quote/{qid}

Queries for a specific quote by id.

Response

{
    "submitter": {
        "cn": "Cole Stowell",
        "uid": "cole"
    },
    "timestamp": "2023-10-24T22:03:08.254364",
    "shards": [
        {
            "body": "Erm... what the spruce?",
            "speaker": {
                "cn": "Wilson McDade",
                "uid": "mcdade"
            }
        }
    ],
    "id": 26,
    "vote": "upvote",
    "score": 1,
    "hidden": false,
    "favorited": true
}

DELETE /api/quote/{qid}

Deletes a quote by id. Must be the submitter in order to delete.

PUT /api/quote/{qid}/hide

Hides a quote by id

POST /api/quote/{qid}/vote

Upvotes a quote

Params

  • vote - Can be either upvote or downvote (Required)

DELETE /api/quote/{qid}/vote

Unvotes/removes the vote for a quote

POST /api/quote/{qid}/favorite

Favorites a quote

DELETE /api/quote/{qid}/favorite

Unfavorites a quote

POST /api/quote/{qid}/report

Reports a quote

Post Data

{
    "reason": "Post makes fun of eboard",
}

PUT /api/quote/{qid}/resolve

Resolves all reports for a given quote with some action.

Params

  • hide - Whether to hide a quote or not (Default: false)

GET /api/reports

Returns a list of reports

Response

[
    {
        "quote_id": 9,
        "reports": [
            {
                "reason": "Insults eboard",
                "timestamp": "2023-10-27T21:09:01.338863",
                "id": 10
            }
        ]
    }
]

GET /api/users

Gets a list of users

GET /api/hidden

Gets a list of hidden quotes. Admin exclusive.

Takes and returns the same data as /api/quotes

Response

[
    {
        "cn": "Cole Stowell",
        "uid": "cole"
    },
    {
        "cn": "Wilson McDade",
        "uid": "mcdade"
    }
]

GET /api/version

Response

{
    "revision": "75885a12aa68a3873bd9f88f54dadbeaedfe9460",
    "date": "2023-10-30T18:14:00.000000000-04:00",
    "build_date": "2023-10-30T22:14:52.337328855Z",
    "url": "https://github.com/costowell/quotefault-backend"
}

Database Schema

Quotes Table

CREATE TABLE Quotes (
    id INT4 PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    submitter VARCHAR(32) NOT NULL,
    timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    hidden BOOL NOT NULL DEFAULT FALSE
);

Quote Shards Table

CREATE TABLE Shards (
    quote_id INT4 REFERENCES quotes(id) ON DELETE CASCADE NOT NULL,
    index SMALLINT NOT NULL,
    body TEXT NOT NULL,
    speaker VARCHAR(32) NOT NULL,
    PRIMARY KEY (quote_id, index)
);

Reports Table

CREATE TABLE Reports (
    id INT4 GENERATED ALWAYS AS IDENTITY,
    quote_id INT4 REFERENCES quotes(id) ON DELETE CASCADE NOT NULL,
    reason TEXT NOT NULL,
    submitter_hash BYTEA NOT NULL,
    timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    resolver VARCHAR(32),
    PRIMARY KEY (quote_id, submitter_hash)
);

Votes Table

CREATE TYPE vote AS ENUM ('upvote', 'downvote');
CREATE TABLE Votes (
    quote_id INT4 REFERENCES quotes(id) ON DELETE CASCADE NOT NULL,
    vote VOTE NOT NULL,
    submitter VARCHAR(32) NOT NULL,
    timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (quote_id, submitter)
);

Favorites Table

CREATE TABLE favorites (
    quote_id INT4 REFERENCES quotes(id) ON DELETE CASCADE NOT NULL,
    username VARCHAR(32) NOT NULL,
    PRIMARY KEY (quote_id, username)
);

About

Rewriting the quotefault backend in πŸš€ blazing πŸš€ fast πŸš€ and πŸš€ memory safe πŸš€ rust πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •