feat: implement core BlackStream platform functionality

Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-10 09:26:09 +00:00
parent 49a4eb2e6e
commit 797fc691f3
23 changed files with 21774 additions and 50 deletions

View File

@@ -1,15 +1,57 @@
const express = require('express');
const cors = require('cors');
const app = express();
const port = process.env.PORT || 4000;
app.use(cors());
app.use(express.json());
// Mock streaming content catalog
const catalog = [
{ id: 1, title: 'The Office', genre: 'Comedy', platform: 'Peacock', year: 2005, rating: 9.0 },
{ id: 2, title: 'Stranger Things', genre: 'Sci-Fi', platform: 'Netflix', year: 2016, rating: 8.7 },
{ id: 3, title: 'The Crown', genre: 'Drama', platform: 'Netflix', year: 2016, rating: 8.6 },
{ id: 4, title: 'Breaking Bad', genre: 'Drama', platform: 'Netflix', year: 2008, rating: 9.5 },
{ id: 5, title: 'Game of Thrones', genre: 'Fantasy', platform: 'HBO Max', year: 2011, rating: 9.2 },
{ id: 6, title: 'The Mandalorian', genre: 'Sci-Fi', platform: 'Disney+', year: 2019, rating: 8.7 },
{ id: 7, title: 'Ted Lasso', genre: 'Comedy', platform: 'Apple TV+', year: 2020, rating: 8.8 },
{ id: 8, title: 'Severance', genre: 'Thriller', platform: 'Apple TV+', year: 2022, rating: 8.7 },
{ id: 9, title: 'Succession', genre: 'Drama', platform: 'HBO Max', year: 2018, rating: 8.9 },
{ id: 10, title: 'Squid Game', genre: 'Thriller', platform: 'Netflix', year: 2021, rating: 8.0 },
{ id: 11, title: 'The Boys', genre: 'Action', platform: 'Prime Video', year: 2019, rating: 8.7 },
{ id: 12, title: 'Rings of Power', genre: 'Fantasy', platform: 'Prime Video', year: 2022, rating: 6.9 },
{ id: 13, title: 'Andor', genre: 'Sci-Fi', platform: 'Disney+', year: 2022, rating: 8.4 },
{ id: 14, title: 'House of the Dragon', genre: 'Fantasy', platform: 'HBO Max', year: 2022, rating: 8.5 },
{ id: 15, title: 'Loki', genre: 'Sci-Fi', platform: 'Disney+', year: 2021, rating: 8.2 },
];
app.get('/', (req, res) => {
res.send('Welcome to the BlackStream API Gateway');
res.json({ service: 'BlackStream API Gateway', status: 'ok', version: '0.1.0' });
});
// Example search endpoint
app.get('/search', (req, res) => {
const { q } = req.query;
res.json({ query: q, results: [] });
const { q, genre, platform } = req.query;
let results = catalog;
if (q) {
const query = q.toLowerCase();
results = results.filter(
(item) =>
item.title.toLowerCase().includes(query) ||
item.genre.toLowerCase().includes(query) ||
item.platform.toLowerCase().includes(query)
);
}
if (genre) {
results = results.filter((item) => item.genre.toLowerCase() === genre.toLowerCase());
}
if (platform) {
results = results.filter((item) => item.platform.toLowerCase() === platform.toLowerCase());
}
res.json({ query: q || '', total: results.length, results });
});
app.listen(port, () => {

View File

@@ -0,0 +1,116 @@
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const request = require('supertest');
const express = require('express');
const cors = require('cors');
// Subset of the catalog used for predictable assertions
const catalog = [
{ id: 1, title: 'The Office', genre: 'Comedy', platform: 'Peacock', year: 2005, rating: 9.0 },
{ id: 2, title: 'Stranger Things', genre: 'Sci-Fi', platform: 'Netflix', year: 2016, rating: 8.7 },
{ id: 3, title: 'Breaking Bad', genre: 'Drama', platform: 'Netflix', year: 2008, rating: 9.5 },
{ id: 4, title: 'The Boys', genre: 'Action', platform: 'Prime Video', year: 2019, rating: 8.7 },
];
function buildApp() {
const app = express();
app.use(cors());
app.use(express.json());
app.get('/', (req, res) => {
res.json({ service: 'BlackStream API Gateway', status: 'ok', version: '0.1.0' });
});
app.get('/search', (req, res) => {
const { q, genre, platform } = req.query;
let results = catalog;
if (q) {
const query = q.toLowerCase();
results = results.filter(
(item) =>
item.title.toLowerCase().includes(query) ||
item.genre.toLowerCase().includes(query) ||
item.platform.toLowerCase().includes(query)
);
}
if (genre) {
results = results.filter((item) => item.genre.toLowerCase() === genre.toLowerCase());
}
if (platform) {
results = results.filter((item) => item.platform.toLowerCase() === platform.toLowerCase());
}
res.json({ query: q || '', total: results.length, results });
});
return app;
}
describe('API Gateway', () => {
const app = buildApp();
describe('GET /', () => {
it('returns health check', async () => {
const res = await request(app).get('/');
assert.equal(res.status, 200);
assert.equal(res.body.status, 'ok');
assert.equal(res.body.service, 'BlackStream API Gateway');
});
});
describe('GET /search', () => {
it('returns all results when no query given', async () => {
const res = await request(app).get('/search');
assert.equal(res.status, 200);
assert.equal(res.body.total, catalog.length);
assert.ok(Array.isArray(res.body.results));
});
it('filters results by title keyword', async () => {
const res = await request(app).get('/search?q=office');
assert.equal(res.status, 200);
assert.equal(res.body.total, 1);
assert.equal(res.body.results[0].title, 'The Office');
});
it('filters results by genre keyword', async () => {
const res = await request(app).get('/search?q=drama');
assert.equal(res.status, 200);
assert.ok(res.body.results.every((r) => r.genre === 'Drama'));
});
it('filters results by platform keyword', async () => {
const res = await request(app).get('/search?q=netflix');
assert.equal(res.status, 200);
assert.ok(res.body.results.every((r) => r.platform === 'Netflix'));
});
it('returns empty results for no match', async () => {
const res = await request(app).get('/search?q=xyznoshow');
assert.equal(res.status, 200);
assert.equal(res.body.total, 0);
assert.deepEqual(res.body.results, []);
});
it('includes query in response', async () => {
const res = await request(app).get('/search?q=boys');
assert.equal(res.status, 200);
assert.equal(res.body.query, 'boys');
});
it('filters by genre param', async () => {
const res = await request(app).get('/search?genre=Action');
assert.equal(res.status, 200);
assert.ok(res.body.results.every((r) => r.genre === 'Action'));
});
it('filters by platform param', async () => {
const res = await request(app).get('/search?platform=Netflix');
assert.equal(res.status, 200);
assert.ok(res.body.results.every((r) => r.platform === 'Netflix'));
});
});
});

1121
backend/api-gateway/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,9 +4,14 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"cors": "^2.8.6",
"express": "^4.18.2"
},
"scripts": {
"start": "node index.js"
"start": "node index.js",
"test": "node --test"
},
"devDependencies": {
"supertest": "^7.2.2"
}
}