Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Completed training module "01-openapi"
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hellen committed Apr 4, 2024
1 parent 27e7f9b commit 962033f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/folio/sample/controller/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,25 @@ public ResponseEntity<BookDTO> getBook(UUID bookId) {
HttpStatus.OK
);
}

public ResponseEntity<BookDTO> updateBook(UUID bookId, BookForCreationDTO apiInfo) {
log.info("Called PUT /books/{}", bookId);

//Get the current book based of off ID
BookDTO currentBook = bookMapper.toDto(
bookService
.getBookById(bookId)
.orElseThrow(() -> new NotFoundException("Book not found"))
);

//Get info provided from API and set the current books info to new info
currentBook.setName(apiInfo.getName());
currentBook.setPublishedDate(apiInfo.getPublishedDate());

//Save updated book information
return new ResponseEntity<>(
bookMapper.toDto(bookService.createBook(bookMapper.fromDto(currentBook))),
HttpStatus.OK
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface BookMapper {

@Mapping(target = "id", ignore = true)
Book fromDto(BookForCreationDTO source);
Book fromDto(BookDTO source);
}
26 changes: 26 additions & 0 deletions src/main/resources/api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,29 @@ paths:
$ref: "./schemas/book.yaml"
"404":
description: The book was not found
put:
summary: Update a book
description: Update a single books attributes
operationId: updateBook
parameters:
- in: path
name: bookId
required: true
schema:
type: string
format: uuid
requestBody:
required: true
content:
application/json:
schema:
$ref: "./schemas/bookForCreation.yaml"
responses:
"200":
description: The updated book results
content:
application/json:
schema:
$ref: "./schemas/book.yaml"
"404":
description: The book was not found

0 comments on commit 962033f

Please sign in to comment.