StaffCoder
Spring Boot
Spring BootSpring Boot 4.1Java 25
12 modules · 48 challengesSign up
Module 6 · DTOs, Mapping and Pagination

Museum Exhibit Management API

medium100%1 of 1 solved

Problem statement

Build a REST API for a museum exhibit catalog with paged list responses built from dedicated response classes.

Requirements

ExhibitMapper

Implement the three mapping methods that turn stored entities into the response classes:

  • toSummary builds the list view of an exhibit, flattening the hall of its display slot into a single hall value
  • toDetail builds the detail view of an exhibit, nesting its display slot as its own object
  • toSlotSummary builds the list view of a display slot, carrying a count of the exhibits it holds

Every response below is built from these classes, and stored entities are never serialized directly. The acquisitionCost of an exhibit is internal to the museum and must never appear in any response of any endpoint.

ExhibitController

Each endpoint must be reachable at exactly the verb and path listed below.

POST /exhibits

  • Accept a JSON body carrying title, era, slotId, and optionally acquisitionCost, and validate it
  • If title is missing, empty, or whitespace-only, return 400 Bad Request with error message: "Title must not be blank"
  • If era is missing, empty, or whitespace-only, return 400 Bad Request with error message: "Era must not be blank"
  • If slotId is missing, return 400 Bad Request with error message: "Slot id is required"
  • If slotId matches no display slot, return 404 Not Found with error message: "Slot not found with id: " followed by the requested slotId
  • A rejected body stores nothing, and neither does a request naming an unknown slot
  • On a valid body, store the exhibit and return 201 Created with the exhibit detail: its generated id, its title and era, and a slot object holding the id, hall, and positionCode of its display slot; the detail carries exactly those four keys and the slot object exactly those three keys
  • A supplied acquisitionCost is stored with the exhibit but does not appear in the response; a body without acquisitionCost is accepted the same way

GET /exhibits

  • Return 200 OK with a JSON object holding exactly five keys: content, page, size, totalElements, and totalPages
  • content is the requested page of exhibits, each carrying exactly id, title, era, and hall, where hall is the hall of the exhibit's display slot; acquisitionCost is never included
  • Exhibits are ordered by id ascending, whatever their titles, and the order carries across pages
  • When page is omitted it defaults to 0, the first page; when size is omitted it defaults to 10
  • page reports the zero-based page number that was served, size the page size that was applied, totalElements the total number of stored exhibits, and totalPages the number of pages the catalog spans at that size; for example, 12 exhibits at size 5 span 3 pages
  • A page past the end of the catalog returns 200 OK with an empty content array while totalElements and totalPages stay correct
  • When no exhibits are stored, return 200 OK with an empty content array, a totalElements of 0, and a totalPages of 0

GET /exhibits/{id}

  • Return 200 OK with the same exhibit detail shape as the create endpoint, nothing more and nothing less
  • If id matches no exhibit, return 404 Not Found with error message: "Exhibit not found with id: " followed by the requested id

SlotController

The endpoint must be reachable at exactly the verb and path listed below.

GET /slots

  • Return 200 OK with a page object holding exactly the same five keys as GET /exhibits; the two list endpoints are indistinguishable in envelope shape
  • content is the requested page of display slots, each carrying exactly id, hall, positionCode, and exhibitCount
  • exhibitCount is the number of exhibits currently stored in that slot, and 0 for a slot holding none
  • Slots are ordered by id ascending; page defaults to 0 and size to 10; the envelope math follows the same rules as above, for example the 12 seeded slots at size 4 span 3 pages
  • A page past the end returns 200 OK with an empty content array while totalElements and totalPages stay correct

Sample Requests & Responses

Expand to view details on sample requests and responses.

POST /exhibits

Request body:

{
    "title": "Bronze Astrolabe",
    "era": "Medieval",
    "acquisitionCost": 12500.50,
    "slotId": 1
}

Response (201 Created):

{
    "id": 1,
    "title": "Bronze Astrolabe",
    "era": "Medieval",
    "slot": {
        "id": 1,
        "hall": "East Wing",
        "positionCode": "E-01"
    }
}

POST /exhibits

Request body:

{
    "era": "Medieval",
    "slotId": 1
}

Response (400 Bad Request):

{
    "error": "Title must not be blank",
    "timestamp": "2026-07-30T11:07:15.023739",
    "path": "/exhibits"
}

POST /exhibits

Request body:

{
    "title": "Bronze Astrolabe",
    "era": "Medieval",
    "slotId": 99
}

Response (404 Not Found):

{
    "error": "Slot not found with id: 99",
    "timestamp": "2026-07-30T11:07:15.033969",
    "path": "/exhibits"
}

GET /exhibits

Response (200 OK):

{
    "content": [
        {
            "id": 1,
            "title": "Bronze Astrolabe",
            "era": "Medieval",
            "hall": "East Wing"
        },
        {
            "id": 2,
            "title": "Impressionist Landscape",
            "era": "Modern",
            "hall": "West Wing"
        },
        {
            "id": 3,
            "title": "Obsidian Blade",
            "era": "Prehistoric",
            "hall": "Grand Gallery"
        }
    ],
    "page": 0,
    "size": 10,
    "totalElements": 3,
    "totalPages": 1
}

GET /exhibits?page=1&size=2

Response (200 OK):

{
    "content": [
        {
            "id": 3,
            "title": "Obsidian Blade",
            "era": "Prehistoric",
            "hall": "Grand Gallery"
        }
    ],
    "page": 1,
    "size": 2,
    "totalElements": 3,
    "totalPages": 2
}

GET /exhibits/1

Response (200 OK):

{
    "id": 1,
    "title": "Bronze Astrolabe",
    "era": "Medieval",
    "slot": {
        "id": 1,
        "hall": "East Wing",
        "positionCode": "E-01"
    }
}

GET /exhibits/99

Response (404 Not Found):

{
    "error": "Exhibit not found with id: 99",
    "timestamp": "2026-07-30T11:07:15.121039",
    "path": "/exhibits/99"
}

GET /slots

Response (200 OK):

{
    "content": [
        {
            "id": 1,
            "hall": "East Wing",
            "positionCode": "E-01",
            "exhibitCount": 1
        },
        {
            "id": 2,
            "hall": "East Wing",
            "positionCode": "E-02",
            "exhibitCount": 0
        },
        {
            "id": 3,
            "hall": "East Wing",
            "positionCode": "E-03",
            "exhibitCount": 0
        },
        {
            "id": 4,
            "hall": "East Wing",
            "positionCode": "E-04",
            "exhibitCount": 0
        },
        {
            "id": 5,
            "hall": "West Wing",
            "positionCode": "W-01",
            "exhibitCount": 0
        },
        {
            "id": 6,
            "hall": "West Wing",
            "positionCode": "W-02",
            "exhibitCount": 0
        },
        {
            "id": 7,
            "hall": "West Wing",
            "positionCode": "W-03",
            "exhibitCount": 1
        },
        {
            "id": 8,
            "hall": "West Wing",
            "positionCode": "W-04",
            "exhibitCount": 0
        },
        {
            "id": 9,
            "hall": "Grand Gallery",
            "positionCode": "G-01",
            "exhibitCount": 1
        },
        {
            "id": 10,
            "hall": "Grand Gallery",
            "positionCode": "G-02",
            "exhibitCount": 0
        }
    ],
    "page": 0,
    "size": 10,
    "totalElements": 12,
    "totalPages": 2
}

GET /slots?page=1

Response (200 OK):

{
    "content": [
        {
            "id": 11,
            "hall": "Grand Gallery",
            "positionCode": "G-03",
            "exhibitCount": 0
        },
        {
            "id": 12,
            "hall": "Grand Gallery",
            "positionCode": "G-04",
            "exhibitCount": 0
        }
    ],
    "page": 1,
    "size": 10,
    "totalElements": 12,
    "totalPages": 2
}

More in DTOs, Mapping and Pagination

See the module
Veterinary Visit RecordsThis problem covers loading a record together with its children in a single database statement, without dropping the ones that have no children.0%0 of 1 solvedmediumJob Board Search & PaginationThis problem covers building a query from whichever filters the caller actually supplied, then paging the result.—No data yetmediumAquarium Species DirectoryThis problem covers returning only the columns a listing needs, and paging over the filtered set.—No data yetmedium

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.