diff --git a/pom.xml b/pom.xml index 0f766ca..1933576 100644 --- a/pom.xml +++ b/pom.xml @@ -1,97 +1,97 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.3.3 - - - bookrepo - bookrepo - 0.0.1-SNAPSHOT - bookrepo - Demo project for Spring Boot - - - - - - - - - - - - - - - 17 - 17 - UTF-8 - UTF-8 - 3.1.1 - - https://raw.githubusercontent.com/mate-academy/style-guides/master/java/checkstyle.xml - - 0.2.0 - 1.5.5.Final + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.3 + + + bookrepo + bookrepo + 0.0.1-SNAPSHOT + bookrepo + Demo project for Spring Boot + + + + + + + + + + + + + + + 17 + 17 + UTF-8 + UTF-8 + 3.1.1 + + https://raw.githubusercontent.com/mate-academy/style-guides/master/java/checkstyle.xml + + 0.2.0 + 1.5.5.Final 0.11.5 1.19.0 - - - - org.springframework.boot - spring-boot-starter-data-jpa - + + + + org.springframework.boot + spring-boot-starter-data-jpa + org.springframework.boot spring-boot-docker-compose 3.1.1 - - com.mysql - mysql-connector-j - 8.4.0 - - - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - 1.18.36 - provided - - - org.hibernate.validator - hibernate-validator - - - org.springframework.boot - spring-boot-starter-validation - + + com.mysql + mysql-connector-j + 8.4.0 + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + 1.18.36 + provided + + + org.hibernate.validator + hibernate-validator + + + org.springframework.boot + spring-boot-starter-validation + org.liquibase liquibase-core - org.springframework.boot - spring-boot-starter-web - - - org.mapstruct - mapstruct - ${mapstruct.version} - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.1.0 - + org.springframework.boot + spring-boot-starter-web + + + org.mapstruct + mapstruct + ${mapstruct.version} + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.1.0 + org.springframework.boot spring-boot-starter-security @@ -137,6 +137,11 @@ spring-security-test test + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.1.0 + @@ -152,61 +157,61 @@ - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.3.0 - - - compile - - check - - - - - ${maven.checkstyle.plugin.configLocation} - true - true - false - src - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - org.projectlombok - lombok - ${lombok.version} - - - org.projectlombok - lombok-mapstruct-binding - ${lombok.mapstruct.binding.version} - - - org.mapstruct - mapstruct-processor - ${mapstruct.version} - - - - - - org.liquibase - liquibase-maven-plugin - ${liquibase.version} - - - + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.3.0 + + + compile + + check + + + + + ${maven.checkstyle.plugin.configLocation} + true + true + false + src + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + + org.projectlombok + lombok + ${lombok.version} + + + org.projectlombok + lombok-mapstruct-binding + ${lombok.mapstruct.binding.version} + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + + + + + + org.liquibase + liquibase-maven-plugin + ${liquibase.version} + + + \ No newline at end of file diff --git a/src/main/java/bookrepo/docs/model-diagram.png b/src/main/java/bookrepo/docs/model-diagram.png new file mode 100644 index 0000000..fe8332c Binary files /dev/null and b/src/main/java/bookrepo/docs/model-diagram.png differ diff --git a/src/main/java/bookrepo/docs/postman/postman_collection.json b/src/main/java/bookrepo/docs/postman/postman_collection.json new file mode 100644 index 0000000..7b322f3 --- /dev/null +++ b/src/main/java/bookrepo/docs/postman/postman_collection.json @@ -0,0 +1,160 @@ +{ + "info": { + "name": "Book Ordering API", + "description": "Postman collection for testing book ordering endpoints", + "version": "1.0.0", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Auth", + "item": [ + { + "name": "Register", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "url": { + "raw": "http://localhost:8080/auth/register" + }, + "body": { + "mode": "raw", + "raw": "{ \"email\": \"user@example.com\", \"password\": \"123456\" }" + } + } + }, + { + "name": "Authenticate", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "url": { + "raw": "http://localhost:8080/auth/authenticate" + }, + "body": { + "mode": "raw", + "raw": "{ \"email\": \"user@example.com\", \"password\": \"123456\" }" + } + } + } + ] + }, + { + "name": "Books", + "item": [ + { + "name": "Get All Books", + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:8080/books" + } + } + }, + { + "name": "Get Book by ID", + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:8080/books/1" + } + } + }, + { + "name": "Add Book", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "url": { + "raw": "http://localhost:8080/books" + }, + "body": { + "mode": "raw", + "raw": "{ \"title\": \"New Book\", \"author\": \"Author\", \"price\": 19.99, \"stock\": 10 }" + } + } + } + ] + }, + { + "name": "Cart", + "item": [ + { + "name": "Get Cart", + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:8080/cart" + } + } + }, + { + "name": "Add to Cart", + "request": { + "method": "POST", + "url": { + "raw": "http://localhost:8080/cart/add/1" + } + } + }, + { + "name": "Remove from Cart", + "request": { + "method": "DELETE", + "url": { + "raw": "http://localhost:8080/cart/remove/1" + } + } + } + ] + }, + { + "name": "Orders", + "item": [ + { + "name": "Get Orders", + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:8080/orders" + } + } + }, + { + "name": "Place Order", + "request": { + "method": "POST", + "url": { + "raw": "http://localhost:8080/orders" + }, + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{}" + } + } + } + ] + } + ] +} diff --git a/src/main/java/bookrepo/docs/swagger/api-docs.json b/src/main/java/bookrepo/docs/swagger/api-docs.json new file mode 100644 index 0000000..e45142e --- /dev/null +++ b/src/main/java/bookrepo/docs/swagger/api-docs.json @@ -0,0 +1 @@ +{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8080/api","description":"Generated server url"}],"tags":[{"name":"Book Controller","description":"Endpoints for managing books"},{"name":"Authentication","description":"Endpoints for user registration and authentication"},{"name":"Shopping Cart","description":"Endpoints for managing user's shopping cart"},{"name":"Order Controller","description":"Endpoints for managing orders and order items"},{"name":"Category","description":"Endpoints for managing categories and related books"}],"paths":{"/categories/{id}":{"get":{"tags":["Category"],"summary":"Get category by ID","description":"Returns category by ID. Requires USER role.","operationId":"getCategoryById","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/CategoryDto"}}}}}},"put":{"tags":["Category"],"summary":"Update category","description":"Updates category by ID. Requires ADMIN role.","operationId":"updateCategory","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CategoryDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/CategoryDto"}}}}}},"delete":{"tags":["Category"],"summary":"Delete category","description":"Deletes category by ID. Requires ADMIN role.","operationId":"deleteCategory","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"204":{"description":"No Content"}}}},"/cart/cart-items/{cartItemId}":{"put":{"tags":["Shopping Cart"],"summary":"Update quantity of a cart item","operationId":"updateCartItem","parameters":[{"name":"cartItemId","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateCarItemQuantityDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ShoppingCartDto"}}}}}},"delete":{"tags":["Shopping Cart"],"summary":"Remove a book from the shopping cart","operationId":"deleteCartItem","parameters":[{"name":"cartItemId","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK"}}}},"/books/{id}":{"get":{"tags":["Book Controller"],"summary":"Get book by ID","description":"Returns a book by its unique identifier","operationId":"getBookById","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/BookDto"}}}}}},"put":{"tags":["Book Controller"],"summary":"Update book","description":"Updates an existing book with new data","operationId":"updateBook","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateBookRequestDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/BookDto"}}}}}},"delete":{"tags":["Book Controller"],"summary":"Delete book by ID","description":"Removes a book from the repository by ID","operationId":"deleteBookById","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"204":{"description":"No Content"}}}},"/orders":{"get":{"tags":["Order Controller"],"summary":"Get all orders","description":"Returns a paginated list of all orders. Accessible only by ADMIN.","operationId":"getAllOrders","parameters":[{"name":"pageable","in":"query","required":true,"schema":{"$ref":"#/components/schemas/Pageable"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageOrderDto"}}}}}},"post":{"tags":["Order Controller"],"summary":"Create a new order","description":"Creates a new order for the authenticated USER.","operationId":"createOrder","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/OrderDto"}}}}}},"patch":{"tags":["Order Controller"],"summary":"Update order status","description":"Updates the status of an existing order. Accessible by USER.","operationId":"updateOrderStatus","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateOrderStatusDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/OrderDto"}}}}}}},"/categories":{"get":{"tags":["Category"],"summary":"Get all categories","description":"Returns paginated list of categories. Requires USER role.","operationId":"getAll","parameters":[{"name":"pageable","in":"query","required":true,"schema":{"$ref":"#/components/schemas/Pageable"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageCategoryDto"}}}}}},"post":{"tags":["Category"],"summary":"Create category","description":"Creates a new category. Requires ADMIN role.","operationId":"createCategory","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CategoryDto"}}},"required":true},"responses":{"201":{"description":"Created","content":{"*/*":{"schema":{"$ref":"#/components/schemas/CategoryDto"}}}}}}},"/cart":{"get":{"tags":["Shopping Cart"],"summary":"Get current user's shopping cart","operationId":"getShoppingCart","responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ShoppingCartDto"}}}}}},"post":{"tags":["Shopping Cart"],"summary":"Add a book to the shopping cart","operationId":"addToCart","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateCartItemDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ShoppingCartDto"}}}}}}},"/books":{"get":{"tags":["Book Controller"],"summary":"Get all books","description":"Returns a paginated list of all books","operationId":"findAll","parameters":[{"name":"pageable","in":"query","required":true,"schema":{"$ref":"#/components/schemas/Pageable"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageBookDto"}}}}}},"post":{"tags":["Book Controller"],"summary":"Create a new book","description":"Adds a new book to the repository","operationId":"createBook","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateBookRequestDto"}}},"required":true},"responses":{"201":{"description":"Created","content":{"*/*":{"schema":{"$ref":"#/components/schemas/BookDto"}}}}}}},"/auth/registration":{"post":{"tags":["Authentication"],"summary":"Register a new user","description":"Creates a new user account with the provided credentials","operationId":"register","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserRegistrationRequestDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponseDto"}}}}}}},"/auth/login":{"post":{"tags":["Authentication"],"summary":"Login a user","description":"Login a user account with the provided login and password","operationId":"login","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserLoginRequestDto"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserLoginResponseDto"}}}}}}},"/orders/{orderId}/items":{"get":{"tags":["Order Controller"],"summary":"Get order items by order ID","description":"Returns all items for a specific order. Accessible by USER.","operationId":"getOrderItems","parameters":[{"name":"orderId","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/OrderItemDto"}}}}}}}},"/orders/{orderId}/items/{itemId}":{"get":{"tags":["Order Controller"],"summary":"Get specific order item","description":"Returns a specific item from an order by order ID and item ID.","operationId":"getSpecificOrderItem","parameters":[{"name":"orderId","in":"path","required":true,"schema":{"type":"integer","format":"int64"}},{"name":"itemId","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/OrderItemDto"}}}}}}},"/categories/{id}/books":{"get":{"tags":["Category"],"summary":"Get books by category","description":"Returns books linked to category. Requires USER role.","operationId":"getBooksByCategoryId","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/BookDtoWithoutCategoryIds"}}}}}}}},"/books/search":{"get":{"tags":["Book Controller"],"summary":"Search books","description":"Search books by title, author, or other parameters","operationId":"searchBooks","parameters":[{"name":"searchParams","in":"query","required":true,"schema":{"$ref":"#/components/schemas/BookSearchParameters"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/BookDto"}}}}}}}}},"components":{"schemas":{"CategoryDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"name":{"type":"string"},"description":{"type":"string"}}},"UpdateCarItemQuantityDto":{"type":"object","properties":{"quantity":{"type":"integer","format":"int32"}}},"CartItemDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"bookId":{"type":"integer","format":"int64"},"bookTitle":{"type":"string"},"quantity":{"type":"integer","format":"int32"}}},"ShoppingCartDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"userId":{"type":"integer","format":"int64"},"cartItems":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/CartItemDto"}}}},"CreateBookRequestDto":{"required":["author","categoryIds","isbn","price","title"],"type":"object","properties":{"title":{"type":"string"},"author":{"type":"string"},"isbn":{"type":"string"},"price":{"type":"number"},"description":{"type":"string"},"coverImage":{"type":"string"},"categoryIds":{"uniqueItems":true,"type":"array","items":{"type":"integer","format":"int64"}}}},"BookDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"title":{"type":"string"},"author":{"type":"string"},"isbn":{"type":"string"},"price":{"type":"number"},"description":{"type":"string"},"coverImage":{"type":"string"},"categoryIds":{"uniqueItems":true,"type":"array","items":{"type":"integer","format":"int64"}}}},"CreateOrderDto":{"required":["shippingAddress"],"type":"object","properties":{"shippingAddress":{"type":"string"}}},"OrderDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"userId":{"type":"integer","format":"int64"},"orderItems":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/OrderItemDto"}},"orderDate":{"type":"string"},"total":{"type":"number"},"status":{"type":"string"}}},"OrderItemDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"bookId":{"type":"integer","format":"int64"},"quantity":{"type":"integer","format":"int32"}}},"CreateCartItemDto":{"required":["bookId"],"type":"object","properties":{"bookId":{"type":"integer","format":"int64"},"quantity":{"type":"integer","format":"int32"}}},"UserRegistrationRequestDto":{"required":["email","firstName","lastName","password","repeatPassword"],"type":"object","properties":{"email":{"type":"string"},"password":{"type":"string"},"repeatPassword":{"type":"string"},"firstName":{"type":"string"},"lastName":{"type":"string"},"shippingAddress":{"type":"string"}}},"UserResponseDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"email":{"type":"string"},"firstName":{"type":"string"},"lastName":{"type":"string"},"shippingAddress":{"type":"string"}}},"UserLoginRequestDto":{"required":["email","password"],"type":"object","properties":{"email":{"maxLength":20,"minLength":8,"type":"string"},"password":{"maxLength":20,"minLength":8,"type":"string"}}},"UserLoginResponseDto":{"type":"object","properties":{"token":{"type":"string"}}},"UpdateOrderStatusDto":{"required":["status"],"type":"object","properties":{"status":{"type":"string"}}},"Pageable":{"type":"object","properties":{"page":{"minimum":0,"type":"integer","format":"int32"},"size":{"minimum":1,"type":"integer","format":"int32"},"sort":{"type":"array","items":{"type":"string"}}}},"PageOrderDto":{"type":"object","properties":{"totalPages":{"type":"integer","format":"int32"},"totalElements":{"type":"integer","format":"int64"},"size":{"type":"integer","format":"int32"},"content":{"type":"array","items":{"$ref":"#/components/schemas/OrderDto"}},"number":{"type":"integer","format":"int32"},"sort":{"$ref":"#/components/schemas/SortObject"},"pageable":{"$ref":"#/components/schemas/PageableObject"},"numberOfElements":{"type":"integer","format":"int32"},"first":{"type":"boolean"},"last":{"type":"boolean"},"empty":{"type":"boolean"}}},"PageableObject":{"type":"object","properties":{"offset":{"type":"integer","format":"int64"},"sort":{"$ref":"#/components/schemas/SortObject"},"paged":{"type":"boolean"},"pageNumber":{"type":"integer","format":"int32"},"pageSize":{"type":"integer","format":"int32"},"unpaged":{"type":"boolean"}}},"SortObject":{"type":"object","properties":{"empty":{"type":"boolean"},"unsorted":{"type":"boolean"},"sorted":{"type":"boolean"}}},"PageCategoryDto":{"type":"object","properties":{"totalPages":{"type":"integer","format":"int32"},"totalElements":{"type":"integer","format":"int64"},"size":{"type":"integer","format":"int32"},"content":{"type":"array","items":{"$ref":"#/components/schemas/CategoryDto"}},"number":{"type":"integer","format":"int32"},"sort":{"$ref":"#/components/schemas/SortObject"},"pageable":{"$ref":"#/components/schemas/PageableObject"},"numberOfElements":{"type":"integer","format":"int32"},"first":{"type":"boolean"},"last":{"type":"boolean"},"empty":{"type":"boolean"}}},"BookDtoWithoutCategoryIds":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"title":{"type":"string"},"author":{"type":"string"},"isbn":{"type":"string"},"price":{"type":"number"},"description":{"type":"string"},"coverImage":{"type":"string"}}},"PageBookDto":{"type":"object","properties":{"totalPages":{"type":"integer","format":"int32"},"totalElements":{"type":"integer","format":"int64"},"size":{"type":"integer","format":"int32"},"content":{"type":"array","items":{"$ref":"#/components/schemas/BookDto"}},"number":{"type":"integer","format":"int32"},"sort":{"$ref":"#/components/schemas/SortObject"},"pageable":{"$ref":"#/components/schemas/PageableObject"},"numberOfElements":{"type":"integer","format":"int32"},"first":{"type":"boolean"},"last":{"type":"boolean"},"empty":{"type":"boolean"}}},"BookSearchParameters":{"type":"object","properties":{"authors":{"type":"array","items":{"type":"string"}},"titles":{"type":"array","items":{"type":"string"}},"isbns":{"type":"array","items":{"type":"string"}},"descriptions":{"type":"array","items":{"type":"string"}},"coverImages":{"type":"array","items":{"type":"string"}},"prices":{"type":"array","items":{"type":"string"}}}}}}} \ No newline at end of file