Skip to content

Instantly share code, notes, and snippets.

@MelTravelz
Last active October 23, 2023 07:18
Show Gist options
  • Save MelTravelz/8983a104ca5c4e822dedb8d5e1c42622 to your computer and use it in GitHub Desktop.
Save MelTravelz/8983a104ca5c4e822dedb8d5e1c42622 to your computer and use it in GitHub Desktop.
missing_piece_JSON_contract

JSON Contract: The Missing Piece

Women Who Code 2023 Hackathon for Social Good

FE Team:

BE Team:


Get all Puzzles by Zip Code / PuzzlesController#index

PUT "/api/v1/puzzles"

Body of Request:

{
  "zip_code": 12345
}

Response:

Status: 200

{
    "data": [
        {
            "id": "1",
            "type": "puzzle",
            "attributes": {
                "user_id": 1,
                "status": "Available",
                "title": "Flower Cycle",
                "description": "A flower collage by Rosalind Wise",
                "total_pieces": 1000,
                "notes": "Very Difficult! Only for the brave of heart!",
                "puzzle_image_url": "https://cloudinary.com/image/Flower_Cycle.jpg"
            }
        },
        {
            "id": "2",
            "type": "puzzle",
            "attributes": {
                "user_id": 1,
                "status": "Available",
                "title": "Mountain Chalet",
                "description": "Cabin near lake and mountains",
                "total_pieces": 1000,
                "notes": "Relaxing, feels like you're in Colorado!",
                "puzzle_image_url": "https://cloudinary.com/image/Mountain_Chalet.jpg"
            }
        }, {...}
    ]
}

Create a new User / UsersController#create

POST "/api/v1/users"

Body of Request:

{
  "full_name": "Diana Puzzler",
  "email": "d.puzzle@gmail.com",
  "password": "PuzzleQueen1",
  "password_confirmation": "PuzzleQueen1",
  "zip_code": 12345, 
  "phone_number": 5051230000
}

Response:

Status: 201

{
    "data": {
        "id": "1",
        "type": "user",
        "attributes": {
            "full_name": "Diana Puzzler",
            "email": "d.puzzle@gmail.com",
            "zip_code": 12345,
            "phone_number": "(505) 123-0000"
        }
    }
}

User Login / SessionsController#create

POST "/api/v1/login"

Body of Request:

{
  "email": "d.puzzle@gmail.com",
  "password": "PuzzleQueen1"
}

Response:

Status: 201

{
    "data": {
        "id": "1",
        "type": "user",
        "attributes": {
            "full_name": "Diana Puzzler",
            "email": "d.puzzle@gmail.com",
            "zip_code": 12345,
            "phone_number": "(505) 123-0000"
        }
    }
}

User Logout / SessionsController#destroy

DELETE "/api/v1/users/:id/logout"

Response:

Status: 204


Get a User / UsersController#show

GET "/api/v1/users/:id"

Response:

Status: 200

{
    "data": {
        "id": "1",
        "type": "user",
        "attributes": {
            "full_name": "Diana Puzzler",
            "email": "d.puzzle@gmail.com",
            "zip_code": 12345,
            "phone_number": "(505) 123-0000"
        }
    }
}

Get a User's Dashboard / UsersController#dashboard

GET "/api/v1/users/:id/dashboard"

Response:

Status: 200

{
    "data": {
        "id": "1",
        "type": "dashboard",
        "attributes": {
            "user_info": {
                "full_name": "Diana Puzzler",
                "email": "d.puzzle@gmail.com",
                "zip_code": 12345,
                "phone_number": "(505) 123-0000"
            },
            "owner_loans": [
                {
                    "loan_id": 1,
                    "owner_id": 1,
                    "borrower_id": 2,
                    "loan_status": "Pending",
                    "loan_created_at": "2023-10-21T02:52:18.777Z",
                    "puzzle_id": 1,
                    "puzzle_image_url": "https://cloudinary.com/image/Flower_Cycle.jpg",
                    "puzzle_title": "Flower Cycle",
                    "puzzle_status": "Pending"
                }, {...}
            ],
            "borrower_loans": [
                {
                    "loan_id": 5,
                    "owner_id": 2,
                    "borrower_id": 1,
                    "loan_status": "Accepted",
                    "loan_created_at": "2023-10-21T17:01:40.848Z",
                    "puzzle_id": 55,
                    "puzzle_image_url": "https://cloudinary.com/image/Maroon_Lake.jpg",
                    "puzzle_title": "Maroon Lake",
                    "puzzle_status": "Not Available"
                }, {...}
            ]
        }
    }
}

Create a new Puzzle / UserPuzzlesController#create

POST "/api/v1/users/:id/puzzles"

Body of Request:

{
    "title": "Wild Beauty",
    "description": "Horses running in the snow by Chris Cummings.",
    "total_pieces": 1000,
    "notes": "Lots of white snow...beware!",
    "puzzle_image_url": "https://cloudinary.com/image/Wild_Beauty.jpg"
}

Response:

Status: 201

{
    "data": {
        "id": "3",
        "type": "puzzle",
        "attributes": {
            "user_id": 1,
            "status": "Available",
            "title": "Wild Beauty",
            "description": "Horses running in the snow by Chris Cummings.",
            "total_pieces": 1000,
            "notes": Lots of white snow...beware!",
            "puzzle_image_url": "https://res.cloudinary.com/image/info/Wild_Beauty.jpg"
        }
    }
}

Get all Puzzles of a User / UserPuzzlesController#index

GET "/api/v1/users/:id/puzzles"

Response:

Status: 200

{
    "data": [
        {...},
        {
            "id": "4",
            "type": "puzzle",
            "attributes": {
                "user_id": 1,
                "status": "Available",
                "title": "Humming Bird & Flowers",
                "description": "Hummingbirds investigating some pretty flowers.",
                "total_pieces": 1000,
                "notes": "Not as hard as you might think!",
                "puzzle_image_url": "https://res.cloudinary.com/image/info/Hummingbirds_Flowers.jpg"
            }
        },
        {
            "id": "5",
            "type": "puzzle",
            "attributes": {
                "user_id": 1,
                "status": "Available",
                "title": "Durango Silverton",
                "description": "Train coming around the bend!",
                "total_pieces": 1000,
                "notes": "Feels like a step back in time!",
                "puzzle_image_url": "https://res.cloudinary.com/image/info/Durango_Silverton.jpg"
            }
        }, {...}
    ]
}

Get a Puzzle / UserPuzzlesController#show

GET "/api/v1/users/:id/puzzles/:id" 

Response:

Status: 200

{
    "data": {
        "id": "1",
        "type": "puzzle",
        "attributes": {
            "user_id": 1,
            "status": "Available",
            "title": "Flower Cycle",
            "description": "A flower collage by Rosalind Wise",
            "total_pieces": 1000,
            "notes": "Very Difficult! Only for the brave of heart!",
            "puzzle_image_url": "https://cloudinary.com/image/Flower_Cycle.jpg"
        }
    }
}

Edit a Puzzle / UserPuzzlesController#update

PATCH "/api/v1/users/:id/puzzles/:id"

Body of Request:

{
  "status": 2, 
  "title": "Rosalind Wise Flower Cycle", 
  "description": "A colorful flower collage", 
  "total_pieces": 2000, 
  "notes":  "Challenging but not too much. The brave of heart can do it!" 
}

Response:

Status: 200

{
    "data": {
        "id": "1",
        "type": "puzzle",
        "attributes": {
            "user_id": 1,
            "status": "Not Available",
            "title": "Rosalind Wise Flower Cycle",
            "description": "A colorful flower collage",
            "total_pieces": 2000,
            "notes": "Challenging but not too much. The brave of heart can do it!",
            "puzzle_image_url": "https://res.cloudinary.com/image/info/Flower_Cycle.jpg"
        }
    }
}

Create a Loan / UserLoansController#create

POST "/api/v1/users/:id/loans"

Body of Request:

{
    "borrower_id": 2, 
    "puzzle_id": 2
}

Response:

Status: 201

{
    "data": {
        "id": "7",
        "type": "loan",
        "attributes": {
            "owner_id": 1,
            "borrower_id": 2,
            "puzzle_id": 2,
            "status": "Pending"
        }
    }
}

Update a Loan status / UserLoansController#update

owner clicks accept OR borrower clicks withdraw OR owner clicks deny OR when loan is complete

PATCH "/api/v1/users/:id/loans/:id"

Body of Request:

{
  "action_type": "accept"
}

Response:

Status: 200

{
    "data": {
        "id": "7",
        "type": "loan",
        "attributes": {
            "owner_id": 1,
            "borrower_id": 2,
            "puzzle_id": 2,
            "status": "Accepted"
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment