Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
25 changes: 25 additions & 0 deletions .github/instructions/copilot-instructions.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
description: Describe when these instructions should be loaded by the agent based on task context
applyTo: '**/*.ts, **/*.js'
---

<!-- Tip: Use /create-instructions in chat to generate content with agent assistance -->

I want to create a rating feature for my application. The rating feature should allow users to rate products on a scale of 1 to 5 stars. The ratings should be stored in a database and displayed on the product page. Additionally, I want to calculate the average rating for each product and display it alongside the individual ratings.

To implement the rating feature for your application, you can follow these steps:
1. **Database Schema**: Create a database schema to store the ratings. You can create a table called `ratings` with the following columns:
- `id`: Primary key, auto-incrementing integer
- `product_id`: Foreign key referencing the product being rated
- `user_id`: Foreign key referencing the user who provided the rating
- `rating`: Integer value between 1 and 5
- `created_at`: Timestamp of when the rating was created
2. **API Endpoints**: Create API endpoints to handle rating submissions and retrieval. For example:
- `POST /api/ratings`: Endpoint to submit a new rating. This endpoint should
- Validate the input to ensure the rating is between 1 and 5
- Check if the user has already rated the product and update the rating if necessary
- Store the rating in the database

3. **Backend Logic**: Implement the backend logic to calculate the average rating for each product. You can create a function that queries the `ratings` table to calculate the average rating for a given product ID. This function can be called whenever a new rating is submitted or when the product page is loaded.
4. **Frontend Implementation**: On the product page, display the individual ratings and the average
rating. You can use a star rating component to visually represent the ratings. When a user submits a new rating, update the displayed average rating and individual ratings accordingly.
8 changes: 8 additions & 0 deletions .github/prompts/APIPrompt.prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: APIPrompt
description: Describe when to use this prompt
---

<!-- Tip: Use /create-prompt in chat to generate content with agent assistance -->

Define the prompt content here. You can include instructions, examples, and any other relevant information to guide the AI's responses.
9 changes: 9 additions & 0 deletions .github/prompts/jiraIssuePrompt.prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: jiraIssuePrompt
description: Describe when to use this prompt
---

<!-- Tip: Use /create-prompt in chat to generate content with agent assistance -->

implement {jira_id} in the following format: {jira_id} - {jira_title}
Example: JIRA-123 - Fix login bug
8 changes: 8 additions & 0 deletions .github/skills/ratingskills/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: ratingskills
description: Describe what this skill does and when to use it. Include keywords that help agents identify relevant tasks.
---

<!-- Tip: Use /create-skill in chat to generate content with agent assistance -->

when implementing a rating feature for an application, this skill can be used to guide the development process. It provides a structured approach to creating a rating system that allows users to rate products on a scale of 1 to 5 stars. The skill covers database schema design, API endpoint creation, backend logic for calculating average ratings, and frontend implementation for displaying ratings. This skill is particularly useful for developers looking to add user feedback and rating functionality to their applications. Keywords: rating feature, database schema, API endpoints, average rating calculation, frontend implementation.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
tasks.db
*.log
nohup.out
18 changes: 18 additions & 0 deletions CHAT_HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Chat History

## 2026-03-16

### User
I want to create an issue "Label Feature Implementation" in this repo

### Copilot
Issue created successfully.

- Title: `Label Feature Implementation`
- Issue number: `#5`
- Link: `https://github.com/CanarysPlayground/TaskManagerApp/issues/5`

## 2026-03-17

### User
create a md file and add the chat history to store it in a file
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A simple Node.js Express app for managing tasks with SQLite database.
- ✅ Mark tasks as completed
- ✅ Set task priority (Low, Medium, High)
- ✅ Task descriptions
- ✅ Rate each task (1-5 stars)
- ✅ Clean and responsive UI
- ✅ RESTful API

Expand Down Expand Up @@ -66,7 +67,21 @@ Body: {
"title": "Updated title",
"description": "Updated description",
"priority": "high",
"completed": 1 // 0 or 1
"completed": 1, // 0 or 1
"rating": 4 // 0 to 5
}
```

### Get task rating
```
GET /api/tasks/:id/rating
```

### Set task rating
```
PUT /api/tasks/:id/rating
Body: {
"rating": 5 // 0 to 5
}
```

Expand Down
13 changes: 13 additions & 0 deletions __mocks__/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const database = {
initialize: jest.fn(),
createTask: jest.fn(),
getAllTasks: jest.fn(),
getTaskById: jest.fn(),
updateTask: jest.fn(),
deleteTask: jest.fn(),
setTaskRating: jest.fn(),
getTaskRating: jest.fn(),
closeDatabase: jest.fn(),
};

module.exports = database;
25 changes: 22 additions & 3 deletions database.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ const initialize = () => {
description TEXT,
priority TEXT DEFAULT 'medium',
completed INTEGER DEFAULT 0,
rating INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
// Add rating column for existing databases that predate this feature
db.run(`ALTER TABLE tasks ADD COLUMN rating INTEGER DEFAULT 0`, (err) => {
if (err && !err.message.includes('duplicate column name')) {
console.error('Error adding rating column:', err);
}
});
});
};

Expand All @@ -36,20 +43,30 @@ const getTaskById = (id, callback) => {
db.get(sql, [id], callback);
};

const updateTask = (id, title, description, priority, completed, callback) => {
const updateTask = (id, title, description, priority, completed, rating, callback) => {
const sql = `
UPDATE tasks
SET title = ?, description = ?, priority = ?, completed = ?, updated_at = CURRENT_TIMESTAMP
SET title = ?, description = ?, priority = ?, completed = ?, rating = ?, updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`;
db.run(sql, [title, description, priority, completed, id], callback);
db.run(sql, [title, description, priority, completed, rating, id], callback);
};

const deleteTask = (id, callback) => {
const sql = `DELETE FROM tasks WHERE id = ?`;
db.run(sql, [id], callback);
};

const setTaskRating = (id, rating, callback) => {
const sql = `UPDATE tasks SET rating = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?`;
db.run(sql, [rating, id], callback);
};

const getTaskRating = (id, callback) => {
const sql = `SELECT rating FROM tasks WHERE id = ?`;
db.get(sql, [id], callback);
};

const closeDatabase = () => {
db.close();
};
Expand All @@ -61,5 +78,7 @@ module.exports = {
getTaskById,
updateTask,
deleteTask,
setTaskRating,
getTaskRating,
closeDatabase
};
74 changes: 70 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ const validateCompleted = (completed) => {
return { valid: true };
};

const validateRating = (rating) => {
if (rating !== undefined && rating !== null) {
const ratingNum = parseInt(rating);
if (isNaN(ratingNum) || ratingNum < 0 || ratingNum > 5) {
return { valid: false, error: 'Rating must be between 0 and 5' };
}
}
return { valid: true };
};

const validateTaskId = (id) => {
if (!id || isNaN(parseInt(id))) {
return { valid: false, error: 'Invalid task ID' };
Expand Down Expand Up @@ -188,7 +198,7 @@ app.get('/api/tasks/:id', (req, res) => {
});

app.put('/api/tasks/:id', (req, res) => {
const { title, description, priority, completed } = req.body;
const { title, description, priority, completed, rating } = req.body;

// Validate task ID
const idValidation = validateTaskId(req.params.id);
Expand All @@ -197,8 +207,8 @@ app.put('/api/tasks/:id', (req, res) => {
}

// Validate at least one field is provided
if (!title && !description && !priority && completed === undefined) {
return res.status(400).json({ error: 'At least one field (title, description, priority, or completed) must be provided' });
if (!title && !description && !priority && completed === undefined && rating === undefined) {
return res.status(400).json({ error: 'At least one field (title, description, priority, completed, or rating) must be provided' });
}

// Validate title if provided
Expand Down Expand Up @@ -233,7 +243,15 @@ app.put('/api/tasks/:id', (req, res) => {
}
}

db.updateTask(req.params.id, title, description, priority, completed, (err) => {
// Validate rating if provided
if (rating !== undefined) {
const ratingValidation = validateRating(rating);
if (!ratingValidation.valid) {
return res.status(400).json({ error: ratingValidation.error });
}
}

db.updateTask(req.params.id, title, description, priority, completed, rating !== undefined ? parseInt(rating) : undefined, (err) => {
if (err) {
console.error('Error updating task:', err);
return res.status(500).json({ error: 'Error updating task', details: err.message });
Expand All @@ -242,6 +260,54 @@ app.put('/api/tasks/:id', (req, res) => {
});
});

app.get('/api/tasks/:id/rating', (req, res) => {
// Validate task ID
const idValidation = validateTaskId(req.params.id);
if (!idValidation.valid) {
return res.status(400).json({ error: idValidation.error });
}

db.getTaskRating(req.params.id, (err, result) => {
if (err) {
console.error('Error retrieving task rating:', err);
return res.status(500).json({ error: 'Error retrieving task rating', details: err.message });
}
if (!result) {
return res.status(404).json({ error: 'Task not found' });
}
res.json({ rating: result.rating });
});
});

app.put('/api/tasks/:id/rating', (req, res) => {
const { rating } = req.body;

// Validate task ID
const idValidation = validateTaskId(req.params.id);
if (!idValidation.valid) {
return res.status(400).json({ error: idValidation.error });
}

// Validate rating is provided
if (rating === undefined || rating === null) {
return res.status(400).json({ error: 'Rating is required' });
}

// Validate rating value
const ratingValidation = validateRating(rating);
if (!ratingValidation.valid) {
return res.status(400).json({ error: ratingValidation.error });
}

db.setTaskRating(req.params.id, parseInt(rating), (err) => {
if (err) {
console.error('Error updating task rating:', err);
return res.status(500).json({ error: 'Error updating task rating', details: err.message });
}
res.json({ message: 'Task rating updated successfully' });
});
});

app.delete('/api/tasks/:id', (req, res) => {
// Validate task ID
const idValidation = validateTaskId(req.params.id);
Expand Down
16 changes: 0 additions & 16 deletions node_modules/.bin/baseline-browser-mapping

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/baseline-browser-mapping.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions node_modules/.bin/baseline-browser-mapping.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions node_modules/.bin/browserslist

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/browserslist.cmd

This file was deleted.

Loading