Write order controller class - #4
Open
Nick040791 wants to merge 8 commits into
Open
Conversation
- Created MySQL 'web_shop' server running on port 3306 - Configured spring.datasource user/pass
1. Loaded/ran 'create-database.sql' script in My SQL workbench successfully serving over port 3306 2. Test ran Spring Boor Application in IntelliJ 3. Postman collections loaded from import into workspace 3. Ran POST login to authenticate as Admin 4. Ran Profile and User REST endpoint requests with success. using Postman *Read for exercises*
-OrderController.java -OrderItemController.java -ProdcutController.java
Created the Product DAO class, fixed capitalization issues and ran the spring boot application. implemented: get create update delete tests never reach the DAO because there is no ProductController yet.
implemented Product Controller for Product DAO get create update delete -all ProductEndpointTests unit tests pass -all Postman Products API endpoint tests pass
implemented the Order Data Access Object with: list order, list order by username, get order by id, create order,
OrderController for OrderDao implemented: list, get, create, update, delete, controls units tests pass for OrderEndpointTests, ProductsEndpointTests, and UserEndpointTests Postman API endpoint tests pass for Orders other than update order --
There was a problem hiding this comment.
Pull request overview
This PR introduces JDBC-based DAOs and REST controllers for products and orders, adds Postman collections for exercising the API, and updates local project configuration (DB config, Maven compiler settings, IntelliJ metadata).
Changes:
- Added DAO + controller layers for
ProductandOrder, plus skeletons forOrderItem. - Added Postman workspace/collection request YAMLs for users/profile/products/orders/order-items/login flows.
- Updated build/IDE/local configuration (DB credentials in
application.properties, Maven compiler plugin settings, IntelliJ.ideafiles).
Reviewed changes
Copilot reviewed 45 out of 59 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| java-springboot-final/src/main/resources/application.properties | Updates datasource username/password for local DB connection. |
| java-springboot-final/src/main/java/org/example/daos/ProductDao.java | Adds JDBC DAO for products CRUD. |
| java-springboot-final/src/main/java/org/example/daos/OrderItemDao.java | Adds (currently empty) DAO placeholder for order_items. |
| java-springboot-final/src/main/java/org/example/daos/OrderDao.java | Adds JDBC DAO for orders CRUD and username filtering. |
| java-springboot-final/src/main/java/org/example/controllers/ProductController.java | Adds REST controller for /api/products CRUD. |
| java-springboot-final/src/main/java/org/example/controllers/OrderItemController.java | Adds (currently empty) controller placeholder for /api/order-items. |
| java-springboot-final/src/main/java/org/example/controllers/OrderController.java | Adds REST controller for /api/orders CRUD (with optional username query param). |
| java-springboot-final/postman/postman/globals/workspace.globals.yaml | Adds Postman globals scaffold. |
| java-springboot-final/postman/postman/collections/web-store/Users/Get Test User.request.yaml | Adds Postman request to fetch a test user. |
| java-springboot-final/postman/postman/collections/web-store/Users/Get Test User Roles.request.yaml | Adds Postman request to fetch roles for a test user. |
| java-springboot-final/postman/postman/collections/web-store/Users/Get All Users.request.yaml | Adds Postman request to list users. |
| java-springboot-final/postman/postman/collections/web-store/Users/Delete Test User.request.yaml | Adds Postman request to delete a test user. |
| java-springboot-final/postman/postman/collections/web-store/Users/Delete TEST role from test.request.yaml | Adds Postman request to remove a role from a user. |
| java-springboot-final/postman/postman/collections/web-store/Users/Create Test User.request.yaml | Adds Postman request to create a test user. |
| java-springboot-final/postman/postman/collections/web-store/Users/Change Test Password.request.yaml | Adds Postman request to change a user's password. |
| java-springboot-final/postman/postman/collections/web-store/Users/Add TEST role to test.request.yaml | Adds Postman request to add a role to a user. |
| java-springboot-final/postman/postman/collections/web-store/Users/Add ADMIN role to test.request.yaml | Adds Postman request to add ADMIN role to a user. |
| java-springboot-final/postman/postman/collections/web-store/Users/.resources/definition.yaml | Adds Postman collection folder metadata for Users. |
| java-springboot-final/postman/postman/collections/web-store/Profile/Get Profile.request.yaml | Adds Postman request to fetch current profile. |
| java-springboot-final/postman/postman/collections/web-store/Profile/Get Profile Roles.request.yaml | Adds Postman request to fetch current profile roles. |
| java-springboot-final/postman/postman/collections/web-store/Profile/Change Password To -test-.request.yaml | Adds Postman request to change password to "test". |
| java-springboot-final/postman/postman/collections/web-store/Profile/Change Password To -admin-.request.yaml | Adds Postman request to change password to "admin". |
| java-springboot-final/postman/postman/collections/web-store/Profile/.resources/definition.yaml | Adds Postman collection folder metadata for Profile. |
| java-springboot-final/postman/postman/collections/web-store/Products/Update Product 6.request.yaml | Adds Postman request to update a product. |
| java-springboot-final/postman/postman/collections/web-store/Products/Get Product By Id.request.yaml | Adds Postman request to fetch product by id. |
| java-springboot-final/postman/postman/collections/web-store/Products/Get All Products.request.yaml | Adds Postman request to list products. |
| java-springboot-final/postman/postman/collections/web-store/Products/Delete Product 6.request.yaml | Adds Postman request to delete a product. |
| java-springboot-final/postman/postman/collections/web-store/Products/Create Product 6.request.yaml | Adds Postman request to create a product. |
| java-springboot-final/postman/postman/collections/web-store/Products/.resources/definition.yaml | Adds Postman collection folder metadata for Products. |
| java-springboot-final/postman/postman/collections/web-store/Orders/Update Order 6.request.yaml | Adds Postman request to update an order. |
| java-springboot-final/postman/postman/collections/web-store/Orders/Get Order By Id.request.yaml | Adds Postman request to fetch order by id. |
| java-springboot-final/postman/postman/collections/web-store/Orders/Get All Orders.request.yaml | Adds Postman request to list orders. |
| java-springboot-final/postman/postman/collections/web-store/Orders/Delete Order 6.request.yaml | Adds Postman request to delete an order. |
| java-springboot-final/postman/postman/collections/web-store/Orders/Create Order 6.request.yaml | Adds Postman request to create an order. |
| java-springboot-final/postman/postman/collections/web-store/Orders/.resources/definition.yaml | Adds Postman collection folder metadata for Orders. |
| java-springboot-final/postman/postman/collections/web-store/Order Items/Update Order Item 1.request.yaml | Adds Postman request to update an order item. |
| java-springboot-final/postman/postman/collections/web-store/Order Items/Get Order Item By Id.request.yaml | Adds Postman request to fetch order item by id. |
| java-springboot-final/postman/postman/collections/web-store/Order Items/Get All Order Items.request.yaml | Adds Postman request to list order items. |
| java-springboot-final/postman/postman/collections/web-store/Order Items/Delete Order Item 1.request.yaml | Adds Postman request to delete an order item. |
| java-springboot-final/postman/postman/collections/web-store/Order Items/Create Order Item 1.request.yaml | Adds Postman request to create an order item. |
| java-springboot-final/postman/postman/collections/web-store/Order Items/.resources/definition.yaml | Adds Postman collection folder metadata for Order Items. |
| java-springboot-final/postman/postman/collections/web-store/login.request.yaml | Adds Postman login request (captures bearer token). |
| java-springboot-final/postman/postman/collections/web-store/.resources/definition.yaml | Adds Postman collection definition (variables + auth). |
| java-springboot-final/postman/.postman/resources.yaml | Adds Postman workspace resource mapping. |
| java-springboot-final/pom.xml | Adds Maven compiler plugin configuration. |
| java-springboot-final/.idea/sqldialects.xml | Adds IntelliJ SQL dialect mappings. |
| java-springboot-final/.idea/dataSources/data_sources_history.xml | Adds IntelliJ datasource history metadata. |
| java-springboot-final/.idea/dataSources.xml | Adds IntelliJ datasource configuration metadata. |
| java-springboot-final/.idea/dataSources.local.xml | Adds IntelliJ local datasource metadata. |
| java-springboot-final/.idea/data_source_mapping.xml | Adds IntelliJ per-file datasource mapping. |
| .idea/vcs.xml | Adds IntelliJ VCS mapping. |
| .idea/modules.xml | Adds IntelliJ module list. |
| .idea/misc.xml | Adds IntelliJ project settings (JDK/output). |
| .idea/jarRepositories.xml | Adds IntelliJ remote repository settings. |
| .idea/flexpath-unit-2-final.iml | Adds IntelliJ module file. |
| .idea/encodings.xml | Adds IntelliJ encoding settings. |
| .idea/dataSources.xml | Adds IntelliJ datasource configuration metadata (root project). |
| .idea/compiler.xml | Adds IntelliJ compiler/annotation processing settings. |
| .idea/.gitignore | Adds IntelliJ directory-local ignore rules. |
Files not reviewed (14)
- .idea/.gitignore: Generated file
- .idea/compiler.xml: Generated file
- .idea/dataSources.xml: Generated file
- .idea/encodings.xml: Generated file
- .idea/flexpath-unit-2-final.iml: Generated file
- .idea/jarRepositories.xml: Generated file
- .idea/misc.xml: Generated file
- .idea/modules.xml: Generated file
- .idea/vcs.xml: Generated file
- java-springboot-final/.idea/dataSources.local.xml: Generated file
- java-springboot-final/.idea/dataSources.xml: Generated file
- java-springboot-final/.idea/dataSources/data_sources_history.xml: Generated file
- java-springboot-final/.idea/data_source_mapping.xml: Generated file
- java-springboot-final/.idea/sqldialects.xml: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
1
to
+3
| spring.datasource.url=jdbc:mysql://localhost:3306/web_shop | ||
| spring.datasource.username=root | ||
| spring.datasource.password=your-password | ||
| spring.datasource.username=nick0 | ||
| spring.datasource.password=Nb221291?? |
Comment on lines
+43
to
+47
| public Product createProduct(Product product) { | ||
| String sql = "INSERT INTO products (name, price) VALUES (?,?)"; | ||
| jdbcTemplate.update(sql, product.getName(), product.getPrice()); | ||
| return jdbcTemplate.queryForObject("SELECT * FROM products WHERE id = LAST_INSERT_ID();", this::mapToProduct); | ||
| } |
Comment on lines
+37
to
+43
| public Order createOrder(Order order) { | ||
| String sql = "INSERT INTO orders (username) VALUES (?);"; | ||
| jdbcTemplate.update(sql, order.getUsername()); | ||
| return jdbcTemplate.queryForObject( | ||
| "SELECT * FROM orders WHERE id = LAST_INSERT_ID();", | ||
| this::mapToOrder); | ||
| } |
Comment on lines
+37
to
+41
| try { | ||
| return productDao.updateProduct(product); | ||
| } catch (RuntimeException e) { | ||
| throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found"); | ||
| } |
Comment on lines
+51
to
+55
| try { | ||
| return orderDao.updateOrder(order); | ||
| } catch (RuntimeException e) { | ||
| throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Order not found"); | ||
| } |
Comment on lines
+98
to
+101
| <configuration> | ||
| <source>25</source> | ||
| <target>25</target> | ||
| </configuration> |
Comment on lines
+1
to
+4
| package org.example.controllers; | ||
|
|
||
| public class OrderItemController { | ||
| } |
Comment on lines
+1
to
+4
| package org.example.daos; | ||
|
|
||
| public class OrderItemDao { | ||
| } |
Comment on lines
+7
to
+11
| <imported>true</imported> | ||
| <remarks>C:/Users/nicho/OneDrive/Documents/GitHub/flexpath-unit-2-final/java-springboot-final/src/main/resources/application.properties</remarks> | ||
| <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver> | ||
| <jdbc-url>jdbc:mysql://localhost:3306/web_shop</jdbc-url> | ||
| <jdbc-additional-properties> |
Comment on lines
+4
to
+8
| <data-source name="web_shop@localhost" uuid="85733b47-5a05-4bc1-95af-19085e761aa9"> | ||
| <database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="MYSQL" /> | ||
| <secret-storage>master_key</secret-storage> | ||
| <user-name>nick0</user-name> | ||
| <schema-mapping /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.