Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server API #49

Closed
wants to merge 1 commit into from
Closed

Add server API #49

wants to merge 1 commit into from

Conversation

dev-737
Copy link
Member

@dev-737 dev-737 commented Mar 9, 2024


Generated summary (powered by Graphite)

TL;DR

This pull request introduces a new server.js file for the graphite-demo project. The server is built with Express.js and includes a /search endpoint that allows users to search through a list of tasks.

What changed

A new file, server.js, was added to the graphite-demo project. This file sets up an Express.js server on port 3000 and includes a /search endpoint. This endpoint accepts a query parameter and returns a list of tasks that match the query. The tasks are sorted alphabetically by their description.

Here's the diff of the changes:

+const express = require('express');
+const app = express();
+const port = 3000;
+
+// Fake data for tasks
+const tasks = [
+  {
+    id: 1,
+    description: 'Complete monthly financial report'
+  },
+  {
+    id: 2,
+    description: 'Plan team building activity'
+  },
+  {
+    id: 3,
+    description: 'Update project documentation'
+  }
+];
+
+app.get('/search', (req, res) => {
+  // Retrieve the query parameter
+  const query = req.query.query?.toLowerCase() || '';
+
+  // Filter tasks based on the query
+  const filteredTasks = tasks.filter(task => task.description.toLowerCase().includes(query));
+
+  // Sort the filtered tasks alphabetically by description
+  const sortedTasks = filteredTasks.sort((a, b) => a.description.localeCompare(b.description));
+
+  res.json(sortedTasks);
+});
+
+app.listen(port, () => {
+  console.log(`Server running on port ${port}`);
+});

How to test

  1. Pull down the changes from this branch.
  2. Run node server.js to start the server.
  3. Visit http://localhost:3000/search?query=<your_query> in your browser, replacing <your_query> with the term you want to search for.
  4. You should see a list of tasks that match your query, sorted alphabetically by their description.

Why make this change

This change was made to provide a way for users to search through a list of tasks. This could be useful in a variety of scenarios, such as a user trying to find a specific task in a large list.

Copy link
Member Author

dev-737 commented Mar 9, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @dev-737 and the rest of your teammates on Graphite Graphite

@dev-737 dev-737 mentioned this pull request Mar 9, 2024
@dev-737 dev-737 force-pushed the 03-09-demo_a9b837d7_Add_server_API branch from bdfa433 to 2658f0d Compare March 9, 2024 13:15
@dev-737 dev-737 mentioned this pull request Mar 9, 2024
@dev-737 dev-737 closed this Mar 9, 2024
@dev-737 dev-737 deleted the 03-09-demo_a9b837d7_Add_server_API branch March 15, 2024 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant