Skip to content

3. APIs and Controller

Kaia edited this page Apr 18, 2023 · 53 revisions

Endpoints

Save a puzzle

Saves a puzzle the user has scanned.

Link to source code.

Endpoint: POST /postpuzzle/

Request Parameters:

Key Location Type Description
user_id Form String Unique identifier associating a user with their saved puzzles
puzzle_img Form text/jpeg Image file of the puzzle the user is saving

Response Codes:

Code Description
201 Created Success
202 Accepted Puzzle image too blurry
400 Bad Request Invalid parameters

Returns: No return values

Example:

Success image

Puzzle image too blurry image

Get Existing Puzzles

Returns the saved puzzle images.

Link to source code.

Endpoint: GET /getpuzzles/<str:user_id>/

Request Parameters:

Key Location Type Description
user_id Device ID String Unique identifier associating a user with their saved puzzles

Response Codes:

Code Description
200 OK Success
404 Not Found Invalid method or parameters

Returns:

Key Location Type Description
puzzles JSON JSON object JSON object containing the images, names, and unique identifying IDs for all puzzles saved by a particular user

Structure of the Puzzles JSON object:

Key Location Type Description
puzzle_id puzzles Integer Globally unique identifier for a given puzzle
puzzle_img puzzles text/jpeg Link to the image of the puzzle in the database

Example:

Success image

Delete Puzzle

The user clicks on an image of the puzzle that they'd like to delete on the front end and sends the request through a form

Link to source code.

Endpoint: DELETE /deletepuzzle/<int:puzzle_id>/

Request Parameters:

Key Location Type Description
puzzle_id url parameter Integer Unique id associated with the puzzle the user would like to delete

Response Codes:

Code Description
204 No Content Successfully deleted the puzzle image from the database
404 Not Found The puzzle_id selected for deletion does not exist within the database, or the user tried an invalid method
400 Bad Request Invalid parameters

Returns: No return values

Example:

Success image

Save a puzzle piece

Saves a puzzle piece the user has scanned and computes/stores the solution.

Link to source code.

Endpoint: POST /postpiece/

Request Parameters:

Key Location Type Description
puzzle_id Form Integer Globally unique identifier for a given puzzle
piece_img Form text/jpeg Link to the image of the puzzle piece in the database
difficulty Form Integer An integer representing the selected difficulty of the solution (0 for default, 1 for hard)

Response Codes:

Code Description
201 Created Success
202 Accepted Piece image too blurry
204 No Content Piece image too homogenous with background
400 Bad Request Invalid parameters

Returns: No return values

Example:

Success image

Piece image too homogenous with background image

Get Existing Pieces

Returns the saved piece images and their associated solutions for a given puzzle.

Link to source code.

Endpoint: GET /getpieces/<int:puzzle_id>/

Request Parameters:

Key Location Type Description
puzzle_id Form Integer Globally unique identifier for a given puzzle

Response Codes:

Code Description
200 OK Success
404 Not Found Invalid parameters or method

Returns:

Key Location Type Description
pieces JSON JSON object JSON object containing the images, solutions, and unique identifying IDs for all puzzle pieces of a particular puzzle

Structure of the Pieces JSON object:

Key Location Type Description
piece_id pieces Integer Globally unique identifier for a given puzzle piece
piece_img pieces text/jpeg Link to the image of the puzzle piece in the database
solution_img pieces text/jpeg Link to the image of the solution associated with the puzzle piece in the database
difficulty pieces Integer An integer representing the selected difficulty of the solution (0 for easy, 1 for hard)

Example:

Success image

Delete Piece

The user clicks on an image of the puzzle piece that they'd like to delete on the front end, and the piece is removed from the database

Link to source code.

Endpoint: DELETE /deletepiece/<int:piece_id>/

Request Parameters:

Key Location Type Description
piece_id url parameter Integer Globally unique identifier for a given puzzle piece

Response Codes:

Code Description
204 No Content Successfully deleted the puzzle image from the database
404 Not Found The puzzle_id selected for deletion does not exist within the database

Returns: No return values

Example:

Success image