Project Specification: Medal Table Overview You are designing a web application for…
- User
Project Specification: Medal Table
Overview You are designing a web application for managing a medal table of medallists in this group project. This application will include a user interface developed with Vue.js, a REST-style Web API, and a database where the information is stored. The user interface will show the list items to users and allow users to manipulate the list. The actions performed by users should send to the Web API, which will perform CRUD operations in a sqlite database and return the results via HTTP response messages to the client side. Definition of Medal Table At least, a medal table should contain the following information: A primary key to identify a medallist (pk; type: number) A nationality of the medallist (nationality; type: string) A name of the medallist (name; type: string) Number fields to represent how many medals (gold, silver and bronze) a medallist obtained (goldMedal, silverMedal and bronzeMedal; type: number) A sample database with sample data is given to you (please refer to file db.sqlite) Client-side Requirements The user interface is expected to work in modern web browsers with a professional looking and should at least provide the following functions. The file named App.vue should be the starting point of your implementation. Load the medal table from the Web API when the application is loaded Allow users to add new record (medallist) and the obtained medals Display the nationality, the name and the obtained medals of a medallist Allow users to delete items Calculate and display the total number of medals Sort the list based on gold medals or total medals Use fetch() to retrieve the table and send user actions to the server-side Display error messages to inform users when things go wrong Server-side Requirements The server-side Web API should be in REST-style. It should be implemented in JavaScript and is expected to be runnable on Node.js. The API should at least fulfil the following requirements. Your implementation should be implemented in the file api.mjs, or imported to this file if you choose to write your program in other files. Follow the standard REST style that uses appropriate HTTP methods and suitable payload format for sending responses or receiving requests Use appropriate status codes and response bodies for communicating with the client-side Handle potential errors appropriately Check whether the inputs sent by the client is correct and appropriate Provide an endpoint for the client to retrieve the medal table Provide an endpoint for creating, updating, and deleting a medal table item Store table changes to a database Some sample screenshots are displayed below:
Medal Table User Interface User Interface for Adding New Items
Additional Notes The sample screenshots are provided for reference only. You are allowed to design your own user interface and use any approach to implement the user interface. The above requirements are minimum requirements. That means you must fulfil these requirements. However, you are also allowed to add additional features and functions to this web application as long as they are deemed useful. The database schema can also be adjusted by you when this is necessary. A Git repository is provided to each group, and this must be used to build this project. You need to use commit, push and branching throughout the project and these will be marked.
- Assistant
Certainly! I'd be happy to help you plan and approach your Medal Table web application project. Let's break down the requirements and outline how you might implement each part step by step.
Project Overview
You are to create a web application that manages a medal table of medallists. The application comprises:
- Client-Side: A user interface built with Vue.js.
- Server-Side: A RESTful Web API developed in JavaScript (Node.js).
- Database: A SQLite database to store medallist information.
Understanding the Requirements
Client-Side Requirements
-
Load Medal Table on Application Load
- Fetch the medal data from the Web API using
fetch()when the app initializes. - Display the data in a user-friendly format.
- Fetch the medal data from the Web API using
-
Add New Record (Medallist)
- Provide a form for users to input:
- Nationality
- Name
- Number of Gold, Silver, and Bronze medals
- Validate user input before sending it to the server.
- Send a POST request to the server to add the new medallist.
- Provide a form for users to input:
-
Display Medallist Information
- Show the medallist's nationality, name, and medal counts.
- Present the data in a clean and organized layout (e.g., table or list).
-
Delete Items
- Allow users to delete a medallist from the table.
- Implement a delete button for each medallist entry.
- Send a DELETE request to the server to remove the item from the database.
-
Calculate and Display Total Number of Medals
- Compute the total medals for each category (gold, silver, bronze).
- Optionally, compute the total number of medals per medallist.
- Display these totals prominently in the UI.
-
Sort the List
- Provide sorting options to order medallists by:
- Number of gold medals.
- Total number of medals.
- Implement sorting logic in the client-side code.
- Provide sorting options to order medallists by:
-
Use
fetch()for HTTP Requests- Utilize the
fetch()API for all communication with the server. - Handle the responses and update the UI accordingly.
- Utilize the
-
Display Error Messages
- Inform users when errors occur (e.g., network issues, server errors).
- Provide clear and user-friendly error notifications.
Server-Side Requirements
-
RESTful API Design
- Create endpoints following REST principles.
- Use appropriate HTTP methods:
- GET for retrieving data.
- POST for creating new entries.
- DELETE for deleting entries.
- (Optional) PUT/PATCH for updating entries.
-
HTTP Status Codes and Response Bodies
- Use correct status codes (e.g., 200 OK, 201 Created, 400 Bad Request, 404 Not Found, 500 Internal Server Error).
- Include meaningful messages in the response body, especially in case of errors.
-
Error Handling
- Gracefully handle potential errors (e.g., invalid input, database errors).
- Ensure the server doesn't crash due to unhandled exceptions.
-
Input Validation
- Check incoming data from the client for correctness.
- Validate data types and required fields.
- Return appropriate error messages for invalid inputs.
-
Medal Table Endpoints
- GET /medallists: Retrieve the list of medallists.
- POST /medallists: Add a new medallist.
- DELETE /medallists/:id: Delete a medallist by primary key.
-
Database Persistence
- Perform CRUD operations on the SQLite database.
- Ensure that changes made via the API are reflected in the database.
Implementation Plan
Client-Side (Vue.js)
-
Set Up the Project
- Initialize a Vue.js project if not already done.
- Use
App.vueas the starting point.
-
Create Components
- MedallistList.vue: To display the list of medallists.
- AddMedallistForm.vue: A form to add new medallists.
-
Fetching Data
- In the main app component or a dedicated data service, implement a method to fetch data from the API when the app loads.
- Use
fetch()to make a GET request to the server.
-
Displaying Data
- Use Vue's reactive data binding to display medallist information.
- Iterate over the medallist data using
v-for.
-
Adding New Medallists
- Implement the form component with inputs for all required fields.
- On form submission:
- Validate the inputs.
- Send a POST request to the server with the new medallist data.
- Update the UI upon successful addition.
-
Deleting Medallists
- Add a delete button/icon next to each medallist entry.
- On click:
- Send a DELETE request to the server with the medallist's ID.
- Remove the medallist from the UI upon successful deletion.
-
Calculating Totals
- Compute total medals using computed properties or methods.
- Recalculate totals whenever the medallist data changes.
-
Sorting Medallists
- Provide UI controls to select sorting criteria.
- Implement sorting logic in a computed property or watch for changes.
-
Error Handling
- Wrap
fetch()calls in try-catch blocks or handle promises with.catch(). - Display error messages using a notification component or alert boxes.
- Wrap
Server-Side (Node.js)
-
Set Up Server
- Initialize a Node.js project.
- Install necessary packages (e.g., Express for server, sqlite3 for database interaction).
-
Create API Endpoints
- GET /medallists: Return the list of medallists from the database.
- POST /medallists: Accept new medallist data and insert it into the database.
- DELETE /medallists/:id: Remove the medallist with the given ID from the database.
-
Database Interaction
- Connect to the SQLite database using the appropriate driver.
- Write SQL queries for each CRUD operation.
- Use parameterized queries to prevent SQL injection.
-
Input Validation and Error Handling
- Validate incoming request data.
- Use middleware or validation libraries if needed.
- Handle exceptions and send appropriate responses.
-
Sending Responses
- Send JSON responses with data or error messages.
- Set the correct HTTP status codes.
-
Testing the API
- Use tools like Postman or curl to test the endpoints.
Version Control with Git
-
Initialize Repository
- Ensure that the provided Git repository is set up.
-
Branching
- Create branches for different features or components (e.g.,
feature/add-medallist-form). - Merge branches back to the main branch after code review.
- Create branches for different features or components (e.g.,
-
Commit Messages
- Write clear and descriptive commit messages.
- Follow a consistent format (e.g., "Add feature: Medallist deletion").
-
Collaboration
- Coordinate with team members.
- Resolve merge conflicts promptly.
- Use pull requests and code reviews if applicable.
Additional Tips
Client-Side Enhancements
-
Form Validation
- Provide immediate feedback to users on the form (e.g., required fields, incorrect input types).
-
Responsive Design
- Use CSS frameworks like Bootstrap or Tailwind CSS to enhance the user interface.
- Ensure the app is usable on various screen sizes.
-
State Management
- For larger applications, consider using Vuex for state management.
- For this project, component-level state management may suffice.
Server-Side Enhancements
-
Logging
- Implement logging to monitor requests and errors (e.g., using
morganorwinston).
- Implement logging to monitor requests and errors (e.g., using
-
Security
- Set up basic security measures (e.g., handling CORS, limiting payload sizes).
-
Environment Variables
- Use environment variables for configuration (though for a simple project, this might be minimal).
Testing
-
Unit Tests
- Write unit tests for server-side logic using frameworks like Mocha or Jest.
-
Integration Tests
- Test the complete flow from the client to the server and back.
Potential Additional Features
-
Update Medallist Information
- Implement PUT/PATCH endpoints to allow updating existing records.
- Add an edit button in the UI to modify medallist details.
-
Search Functionality
- Allow users to search for medallists by name or nationality.
-
Pagination
- Implement pagination for scenarios with a large number of medallists.
-
Data Visualization
- Use charting libraries to visualize medal counts (e.g., pie charts, bar graphs).
Error Handling Strategies
-
Client-Side
- Use a global error handling component or Vue's error handling hooks.
- Provide users with actionable messages (e.g., "Unable to load data. Please try again later.").
-
Server-Side
- Catch and handle exceptions in API endpoints.
- Avoid sending stack traces to the client; instead, log them on the server and send a generic error message.
Final Notes
-
Documentation
- Document your code with comments where necessary.
- Provide a README file with instructions on how to run the application.
-
Collaboration
- Maintain clear communication with your team.
- Regularly update your team on progress and blockers.
-
Time Management
- Prioritize core functionality before working on additional features.
- Set milestones for each part of the project.
By following this structured approach, you'll be able to meet the project requirements and build a functional and user-friendly Medal Table web application. Remember to test each part thoroughly before moving on to the next.
If you have any specific questions or need further clarification on any aspect of the project, feel free to ask!