Ritarira / Books

0 stars 0 forks source link

Add a new field in Authors #8

Open Ritarira opened 6 years ago

Ritarira commented 6 years ago

User Story: As an API consumer, I want to see the number of books author has both when requesting a list of authors and a single author, So that I don't make extra requests to get info about the books.

Acceptance Criteria:

Ritarira commented 6 years ago

Test plan:

Ritarira commented 6 years ago

:white_check_mark: Check if I can get the full list of authors with the number of author's books field GET localhost:3000/authors Status 200

[
    {
        "id": 7,
        "first_name": "J",
        "last_name": "Lynn",
        "books_count": 3
    },
    {
        "id": 9,
        "first_name": "Sally",
        "last_name": "Thorne",
        "books_count": 0
    },
    {
        "id": 10,
        "first_name": "Katie",
        "last_name": "McGarry",
        "books_count": 3
    },
    {
        "id": 11,
        "first_name": "Vishen",
        "last_name": "Lakhiani",
        "books_count": 0
    },
    {
        "id": 14,
        "first_name": "Colleen",
        "last_name": "Hoover",
        "books_count": 1
    },
    {
        "id": 15,
        "first_name": "Monicka",
        "last_name": "Smith",
        "books_count": 1
    }
]
Ritarira commented 6 years ago

:white_check_mark: Check if I can get a single author with the number of author's books field GET localhost:3000/authors/9 Status 200

{
    "id": 9,
    "first_name": "Sally",
    "last_name": "Thorne",
    "books_count": 0
}
Ritarira commented 6 years ago

:white_check_mark: Check if I can create a new author with the number of author's books field Request: POST localhost:3000/authors

{       
    "first_name": "Kiera",
    "last_name": "Cass" 
}

Response: Status 201

{
    "id": 16,
    "first_name": "Kiera",
    "last_name": "Cass",
    "books_count": 0
}
Ritarira commented 6 years ago

:white_check_mark: Check if I can make changes to the number of author's books field by using PUT request. The number should not change

Request: GET localhost:3000/authors/10

Response: Status 200

{
    "id": 10,
    "first_name": "Katie",
    "last_name": "McGarry",
    "books_count": 3
}

Request: PUT localhost:3000/authors/10

{       
    "id": 10,
    "first_name": "Katie",
    "last_name": "McGarry",
    "books_count": 9    
}

Response: Status 200

{
    "id": 10,
    "first_name": "Katie",
    "last_name": "McGarry",
    "books_count": 3
}
Ritarira commented 6 years ago

:white_checkmark: Check if I can make changes to the number of author's books field by adding a new book Request: GET localhost:3000/authors/16

Response: Status 200

{
    "id": 16,
    "first_name": "Kiera",
    "last_name": "Cass",
    "books_count": 0
}

Request: POST localhost:3000/books

{       
    "author_id": 16,
    "title": "Selection",
    "description": "For thirty-five girls, the Selection is the chance of a lifetime. The opportunity to escape the life laid out for them since birth. To be swept up in a world of glittering gowns and priceless jewels. To live in a palace and compete for the heart of gorgeous Prince Maxon.",
    "rating": 6 
}

Response: Status 201

{
    "id": 23,
    "author_id": 16,
    "title": "Selection",
    "description": "For thirty-five girls, the Selection is the chance of a lifetime. The opportunity to escape the life laid out for them since birth. To be swept up in a world of glittering gowns and priceless jewels. To live in a palace and compete for the heart of gorgeous Prince Maxon.",
    "created_at": "2018-01-23T08:49:32.598Z",
    "updated_at": "2018-01-23T08:49:32.598Z",
    "rating": 6
}

Request: GET localhost:3000/authors/16

Response: Status 200

{
    "id": 16,
    "first_name": "Kiera",
    "last_name": "Cass",
    "books_count": 1
}
Ritarira commented 6 years ago

:white_check_mark: Check if I can make changes to the number of author's books field by deleting a book Request: GET localhost:3000/authors/16

Response: Status 200

{
    "id": 16,
    "first_name": "Kiera",
    "last_name": "Cass",
    "books_count": 1
}

Request: DELET localhost:3000/books/23

Response: Status 204

Request: GET localhost:3000/authors/16

Response: Status 200

{
    "id": 16,
    "first_name": "Kiera",
    "last_name": "Cass",
    "books_count": 0
}
Ritarira commented 6 years ago

:white_check_mark: Check the number of books of several authors and compare with results when requesting a list of books Request: GET localhost:3000/authors/7

Response: Status 200

{
    "id": 7,
    "first_name": "J",
    "last_name": "Lynn",
    "books_count": 3
}

Request: GET localhost:3000/authors/10

Response: Status 200

{
    "id": 10,
    "first_name": "Katie",
    "last_name": "McGarry",
    "books_count": 3
}

Request: GET localhost:3000/books

Response: Status 200

[
    {
        "id": 10,
        "author_id": 7,
        "title": "Wait for you",
        "description": "Love isn't meant to be perfect... Except when it is",
        "created_at": "2017-12-07T07:51:51.868Z",
        "updated_at": "2017-12-13T08:24:33.098Z",
        "rating": 6,
        "author": {
            "first_name": "J",
            "last_name": "Lynn"
        }
    },
    {
        "id": 16,
        "author_id": 10,
        "title": "Cars",
        "description": "A new novel about risking everything for love",
        "created_at": "2017-12-12T12:19:03.858Z",
        "updated_at": "2017-12-12T12:19:03.858Z",
        "rating": 10,
        "author": {
            "first_name": "Katie",
            "last_name": "McGarry"
        }
    },
    {
        "id": 17,
        "author_id": 10,
        "title": "Beautiful Disaster",
        "description": "The new Abby Abernathy is a good girl. She doesn’t drink or swear, and she has the appropriate percentage of cardigans in her wardrobe. Abby believes she has enough distance between her and the darkness of her past, but when she arrives at college with her best friend America, her path to a new beginning is quickly challenged by Eastern University’s Walking One-Night Stand. Travis Maddox, lean, cut, and covered in tattoos, is exactly what Abby needs—and wants—to avoid. He spends his nights winning money in a floating fight ring, and his days as the charming college co-ed. Intrigued by Abby’s resistance to his charms, Travis tricks her into his daily life with a simple bet. If he loses, he must remain abstinent for a month. If Abby loses, she must live in Travis’ apartment for the same amount of time. Either way, Travis has no idea that he has met his match.",
        "created_at": "2017-12-13T08:28:54.872Z",
        "updated_at": "2017-12-13T08:28:54.872Z",
        "rating": 9,
        "author": {
            "first_name": "Katie",
            "last_name": "McGarry"
        }
    },
    {
        "id": 18,
        "author_id": 7,
        "title": "Trust in me",
        "description": "Traveling thousands of miles from home to enter college is the only way nineteen-year-old Avery Morgansten can escape what happened at the Halloween party five years ago—an event that forever changed her life. All she needs to do is make it to her classes on time, make sure the bracelet on her left wrist stays in place, not draw any attention to herself, and maybe—please God—make a few friends, because surely that would be a nice change of pace. The one thing she didn’t need and never planned on was capturing the attention of the one guy who could shatter the precarious future she’s building for herself.",
        "created_at": "2017-12-14T07:42:35.524Z",
        "updated_at": "2017-12-14T07:42:35.524Z",
        "rating": 0,
        "author": {
            "first_name": "J",
            "last_name": "Lynn"
        }
    },
    {
        "id": 19,
        "author_id": 7,
        "title": "Trust in me",
        "description": "Traveling thousands of miles from home to enter college is the only way nineteen-year-old Avery Morgansten can escape what happened at the Halloween party five years ago—an event that forever changed her life. All she needs to do is make it to her classes on time, make sure the bracelet on her left wrist stays in place, not draw any attention to herself, and maybe—please God—make a few friends, because surely that would be a nice change of pace. The one thing she didn’t need and never planned on was capturing the attention of the one guy who could shatter the precarious future she’s building for herself.",
        "created_at": "2017-12-14T07:42:50.096Z",
        "updated_at": "2017-12-14T07:42:50.096Z",
        "rating": 0,
        "author": {
            "first_name": "J",
            "last_name": "Lynn"
        }
    },
    {
        "id": 20,
        "author_id": 14,
        "title": "Maybe someday",
        "description": "Sydney is living in an idyllic bubble—she's a dedicated student with a steady job on the side. She lives with her best friend, has a great boyfriend, and the music coming from the balcony opposite hers is fast becoming the soundtrack to her life. But when Sydney finds out her boyfriend is cheating on her, the bubble bursts. The mysterious and attractive man behind the music, Ridge, gives Sydney hope that she can move on and they begin to write songs together. But moving on is harder than she expects, Sydney can only hope…. ",
        "created_at": "2017-12-14T07:54:52.922Z",
        "updated_at": "2017-12-14T07:54:52.922Z",
        "rating": 10,
        "author": {
            "first_name": "Colleen",
            "last_name": "Hoover"
        }
    },
    {
        "id": 21,
        "author_id": 15,
        "title": "Wait for you",
        "description": "Except when it is",
        "created_at": "2017-12-14T08:07:04.386Z",
        "updated_at": "2017-12-14T08:07:04.386Z",
        "rating": 6,
        "author": {
            "first_name": "Monicka",
            "last_name": "Smith"
        }
    },
    {
        "id": 22,
        "author_id": 10,
        "title": "A beautiful disaster",
        "description": "The new Abby Abernathy is a good girl. She doesn’t drink or swear, and she has the appropriate percentage of cardigans in her wardrobe. Abby believes she has enough distance between her and the darkness of her past, but when she arrives at college with her best friend America, her path to a new beginning is quickly challenged by Eastern University’s Walking One-Night Stand. Travis Maddox, lean, cut, and covered in tattoos, is exactly what Abby needs—and wants—to avoid. He spends his nights winning money in a floating fight ring, and his days as the charming college co-ed. Intrigued by Abby’s resistance to his charms, Travis tricks her into his daily life with a simple bet. If he loses, he must remain abstinent for a month. If Abby loses, she must live in Travis’ apartment for the same amount of time. Either way, Travis has no idea that he has met his match.",
        "created_at": "2018-01-23T07:24:52.143Z",
        "updated_at": "2018-01-23T07:24:52.143Z",
        "rating": 0,
        "author": {
            "first_name": "Katie",
            "last_name": "McGarry"
        }
    }
]
Ritarira commented 6 years ago

:white_check_mark: Check status codes of all valid responses