Skip to content

Commit f48c7cc

Browse files
authored
Merge pull request #7 from programeryk/feat-structured-logging-request-id
feat(api): add root API home endpoint with quick links to docs, healt…
2 parents 37054bb + 1eff81a commit f48c7cc

4 files changed

Lines changed: 52 additions & 8 deletions

File tree

‎src/app.controller.spec.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ describe('AppController', () => {
1515
});
1616

1717
describe('root', () => {
18-
it('should return "This is the stateful engagement system!"', () => {
19-
expect(appController.getHello()).toBe(
20-
'This is the stateful engagement system!',
18+
it('should return API home metadata and quick links', () => {
19+
expect(appController.getHome()).toEqual(
20+
expect.objectContaining({
21+
name: 'Stateful Engagement Backend',
22+
docs: '/api',
23+
health: '/health',
24+
}),
2125
);
2226
});
2327
});

‎src/app.controller.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class AppController {
66
constructor(private readonly appService: AppService) {}
77

88
@Get()
9-
getHello(): string {
10-
return this.appService.getHello();
9+
getHome() {
10+
return this.appService.getApiHome();
1111
}
1212
}

‎src/app.service.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
import { Injectable } from '@nestjs/common';
22

3+
type EndpointGroup = {
4+
name: string;
5+
path: string;
6+
};
7+
8+
type ApiHomeResponse = {
9+
name: string;
10+
message: string;
11+
version: string;
12+
docs: string;
13+
health: string;
14+
endpoints: EndpointGroup[];
15+
};
16+
317
@Injectable()
418
export class AppService {
5-
getHello(): string {
6-
return 'This is the stateful engagement system!';
19+
getApiHome(): ApiHomeResponse {
20+
return {
21+
name: 'Stateful Engagement Backend',
22+
message: 'API is running. Open /api for Swagger and test endpoints.',
23+
version: 'v1',
24+
docs: '/api',
25+
health: '/health',
26+
endpoints: [
27+
{ name: 'Auth', path: '/auth' },
28+
{ name: 'Check-ins', path: '/checkins' },
29+
{ name: 'Tools', path: '/tools' },
30+
{ name: 'Rewards', path: '/rewards' },
31+
{ name: 'Profile', path: '/me' },
32+
],
33+
};
734
}
835
}

‎test/app.e2e-spec.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ describe('AppController (e2e)', () => {
2424
return request(app.getHttpServer())
2525
.get('/')
2626
.expect(200)
27-
.expect('This is the stateful engagement system!');
27+
.expect({
28+
name: 'Stateful Engagement Backend',
29+
message: 'API is running. Open /api for Swagger and test endpoints.',
30+
version: 'v1',
31+
docs: '/api',
32+
health: '/health',
33+
endpoints: [
34+
{ name: 'Auth', path: '/auth' },
35+
{ name: 'Check-ins', path: '/checkins' },
36+
{ name: 'Tools', path: '/tools' },
37+
{ name: 'Rewards', path: '/rewards' },
38+
{ name: 'Profile', path: '/me' },
39+
],
40+
});
2841
});
2942
});

0 commit comments

Comments
 (0)