Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4fcd805

Browse files
change contract (models) and implement api in RestController
1 parent 73286db commit 4fcd805

File tree

2 files changed

+96
-12
lines changed

2 files changed

+96
-12
lines changed

‎api-first-development-service-api-contract/src/main/resources/service-contract-api.yaml

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ paths:
2626
schema:
2727
type: array
2828
items:
29-
$ref: '#/components/schemas/Book'
29+
$ref: '#/components/schemas/BookModel'
3030
'400':
3131
description: Bad request
3232
'401':
@@ -48,15 +48,15 @@ paths:
4848
content:
4949
application/json:
5050
schema:
51-
$ref: '#/components/schemas/Book'
51+
$ref: '#/components/schemas/NewBookModel'
5252
required: true
5353
responses:
5454
'201':
5555
description: Successful operation
5656
content:
5757
application/json:
5858
schema:
59-
$ref: '#/components/schemas/Book'
59+
$ref: '#/components/schemas/BookModel'
6060
'405':
6161
description: Invalid input
6262
/books/{bookId}:
@@ -80,7 +80,7 @@ paths:
8080
content:
8181
application/json:
8282
schema:
83-
$ref: '#/components/schemas/Book'
83+
$ref: '#/components/schemas/BookModel'
8484
'400':
8585
description: Invalid ID supplied
8686
'404':
@@ -104,15 +104,15 @@ paths:
104104
content:
105105
application/json:
106106
schema:
107-
$ref: '#/components/schemas/Book'
107+
$ref: '#/components/schemas/ModifiedBookModel'
108108
required: true
109109
responses:
110110
'200':
111111
description: Successful operation
112112
content:
113113
application/json:
114114
schema:
115-
$ref: '#/components/schemas/Book'
115+
$ref: '#/components/schemas/BookModel'
116116
'400':
117117
description: Invalid ID supplied
118118
'404':
@@ -139,7 +139,42 @@ paths:
139139

140140
components:
141141
schemas:
142-
Book:
142+
NewBookModel:
143+
type: object
144+
properties:
145+
title:
146+
description: Title of book entity
147+
type: string
148+
example: 'Cat Among the Pigeons'
149+
isbn:
150+
description: ISBN number of the book (13 characters)
151+
type: number
152+
example: 9780671557003
153+
genre:
154+
description: Genre of the book entity
155+
type: string
156+
example: DETECTIVE_FICTION
157+
enum:
158+
- DETECTIVE FICTION
159+
- NOVEL
160+
- MYSTERY
161+
- THRILLER
162+
- HORROR
163+
- HISTORICAL
164+
- ROMANCE
165+
- WESTERN
166+
- BILDUNGSROMAN
167+
- SCIENCE_FICTION
168+
- FICTION
169+
- FANTASY
170+
- MAGICAL_REALISM
171+
- REALIST_LITERATURE
172+
- OTHER
173+
required:
174+
- title
175+
- isbn
176+
- genre
177+
BookModel:
143178
type: object
144179
properties:
145180
id:
@@ -211,3 +246,50 @@ components:
211246
- AVAILABLE
212247
- ARCHIVE
213248
- DELETED
249+
ModifiedBookModel:
250+
type: object
251+
properties:
252+
title:
253+
description: Title of book entity
254+
type: string
255+
example: 'Cat Among the Pigeons'
256+
isbn:
257+
description: ISBN number of the book (13 characters)
258+
type: number
259+
example: 9780671557003
260+
genre:
261+
description: Genre of the book entity
262+
type: string
263+
example: DETECTIVE_FICTION
264+
enum:
265+
- DETECTIVE FICTION
266+
- NOVEL
267+
- MYSTERY
268+
- THRILLER
269+
- HORROR
270+
- HISTORICAL
271+
- ROMANCE
272+
- WESTERN
273+
- BILDUNGSROMAN
274+
- SCIENCE_FICTION
275+
- FICTION
276+
- FANTASY
277+
- MAGICAL_REALISM
278+
- REALIST_LITERATURE
279+
- OTHER
280+
status:
281+
description: Status of the book
282+
type: string
283+
example: SOLD
284+
enum:
285+
- AVAILABLE
286+
- PENDING
287+
- SOLD
288+
availability:
289+
description: Status of book availability
290+
type: string
291+
example: AVAILABLE
292+
enum:
293+
- AVAILABLE
294+
- ARCHIVE
295+
- DELETED

‎api-first-development-service/src/main/java/com/csaba79coder/apifirstdevelopment/controller/BookController.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.csaba79coder.apifirstdevelopment.controller;
22

33
import com.csaba79coder.api.BooksApi;
4-
import com.csaba79coder.models.Book;
4+
import com.csaba79coder.models.BookModel;
5+
import com.csaba79coder.models.ModifiedBookModel;
6+
import com.csaba79coder.models.NewBookModel;
57
import org.springframework.http.ResponseEntity;
68
import org.springframework.web.bind.annotation.CrossOrigin;
79
import org.springframework.web.bind.annotation.RestController;
@@ -14,7 +16,7 @@
1416
public class BookController implements BooksApi {
1517

1618
@Override
17-
public ResponseEntity<Book> addBook(Book body) {
19+
public ResponseEntity<BookModel> addBook(NewBookModel body) {
1820
return null;
1921
}
2022

@@ -24,17 +26,17 @@ public ResponseEntity<Void> deleteBook(UUID bookId) {
2426
}
2527

2628
@Override
27-
public ResponseEntity<Book> getBookById(UUID bookId) {
29+
public ResponseEntity<BookModel> getBookById(UUID bookId) {
2830
return null;
2931
}
3032

3133
@Override
32-
public ResponseEntity<List<Book>> renderAllBooks() {
34+
public ResponseEntity<List<BookModel>> renderAllBooks() {
3335
return null;
3436
}
3537

3638
@Override
37-
public ResponseEntity<Book> updateBook(UUID bookId, Book body) {
39+
public ResponseEntity<BookModel> updateBook(UUID bookId, ModifiedBookModel body) {
3840
return null;
3941
}
4042
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /