Skip to content

Commit e82e6b5

Browse files
committed
refactor(be): remove deprecated endpoints
1 parent 019b56f commit e82e6b5

File tree

4 files changed

+2
-226
lines changed

4 files changed

+2
-226
lines changed

apps/backend/src/constants/swagger.const.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,4 @@ Thank you for checking out my project.
1414
- [GraphQL Playground](${GRAPHQL_PATH})
1515
- [Swagger JSON file](${SWAGGER_JSON_PATH})
1616
- [Source code](${SOURCE_CODE_URL})
17-
18-
### ⚠️ Warning
19-
Do __NOT__ use non-versioned endpoints (e.g. \`/stop/all\`). Use versioned endpoints instead (e.g. \`/v1/stop/all\`).
20-
21-
Non-versioned endpoints are deprecated and will be removed in the future.
22-
2317
`;

apps/backend/src/modules/departure/departure.controller.ts

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import {
77
Query,
88
UseInterceptors,
99
Version,
10-
VERSION_NEUTRAL,
1110
} from "@nestjs/common";
12-
import { ApiOperation, ApiTags } from "@nestjs/swagger";
11+
import { ApiTags } from "@nestjs/swagger";
1312
import { z } from "zod";
1413

15-
import { QUERY_IDS_COUNT_MAX } from "src/constants/constants";
16-
import { ApiDescription, ApiQueries } from "src/decorators/swagger.decorator";
14+
import { ApiQueries } from "src/decorators/swagger.decorator";
1715
import { EndpointVersion } from "src/enums/endpoint-version";
1816
import { DepartureServiceV1 } from "src/modules/departure/departure-v1.service";
1917
import { DepartureServiceV2 } from "src/modules/departure/departure-v2.service";
@@ -27,7 +25,6 @@ import {
2725
vehicleTypeSchema,
2826
} from "src/schema/metro-only.schema";
2927
import { metroOnlyQuery } from "src/swagger/query.swagger";
30-
import { toArray } from "src/utils/array.utils";
3128

3229
@ApiTags("departure")
3330
@Controller("departure")
@@ -39,64 +36,6 @@ export class DepartureController {
3936
private readonly departureServiceV2: DepartureServiceV2,
4037
) {}
4138

42-
@Get()
43-
@Version([VERSION_NEUTRAL])
44-
@ApiQueries([
45-
metroOnlyQuery,
46-
{
47-
name: "platform[]",
48-
description: "Platform IDs",
49-
type: [String],
50-
isArray: true,
51-
allowEmptyValue: true,
52-
required: false,
53-
},
54-
{
55-
name: "stop[]",
56-
description: "Stop IDs",
57-
type: [String],
58-
isArray: true,
59-
allowEmptyValue: true,
60-
required: false,
61-
},
62-
])
63-
@ApiOperation({
64-
deprecated: true,
65-
})
66-
@ApiDescription({
67-
deprecated: true,
68-
})
69-
async getDepartures(@Query() query): Promise<DepartureSchema[]> {
70-
const schema = z.object({
71-
metroOnly: metroOnlySchema,
72-
platform: z.string().array().optional().default([]),
73-
stop: z.string().array().optional().default([]),
74-
});
75-
const parsed = schema.safeParse(query);
76-
if (!parsed.success) {
77-
throw new HttpException(
78-
"Invalid query params",
79-
HttpStatus.BAD_REQUEST,
80-
);
81-
}
82-
const parsedQuery = parsed.data;
83-
84-
if (parsedQuery.platform.length + parsedQuery.stop.length === 0) {
85-
throw new HttpException(
86-
"At least one platform or stop ID must be provided",
87-
HttpStatus.BAD_REQUEST,
88-
);
89-
}
90-
91-
const departures = await this.departureServiceV1.getDepartures({
92-
stopIds: parsedQuery.stop,
93-
platformIds: parsedQuery.platform,
94-
metroOnly: parsedQuery.metroOnly,
95-
});
96-
97-
return departureSchema.array().parse(departures);
98-
}
99-
10039
@Get()
10140
@Version([EndpointVersion.v1])
10241
@ApiQueries([
@@ -149,35 +88,6 @@ export class DepartureController {
14988
return departureSchema.array().parse(departures);
15089
}
15190

152-
@Get("/platform")
153-
@Version([VERSION_NEUTRAL, EndpointVersion.v1])
154-
@ApiDescription({
155-
deprecated: true,
156-
})
157-
async getDeparturesByPlatform(@Query("id") id): Promise<DepartureSchema[]> {
158-
const platformSchema = z
159-
.string()
160-
.array()
161-
.min(1)
162-
.max(QUERY_IDS_COUNT_MAX);
163-
const parsed = platformSchema.safeParse(toArray(id));
164-
165-
if (!parsed.success) {
166-
throw new HttpException(
167-
"Invalid query params",
168-
HttpStatus.BAD_REQUEST,
169-
);
170-
}
171-
172-
const departures = await this.departureServiceV1.getDepartures({
173-
stopIds: [],
174-
platformIds: parsed.data,
175-
metroOnly: false,
176-
});
177-
178-
return departureSchema.array().parse(departures);
179-
}
180-
18191
@Get()
18292
@Version([EndpointVersion.v2])
18393
@ApiQueries([

apps/backend/src/modules/platform/platform.controller.ts

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Query,
88
UseInterceptors,
99
Version,
10-
VERSION_NEUTRAL,
1110
} from "@nestjs/common";
1211
import { ApiQuery, ApiTags } from "@nestjs/swagger";
1312
import { z } from "zod";
@@ -39,32 +38,6 @@ import {
3938
export class PlatformController {
4039
constructor(private readonly platformService: PlatformService) {}
4140

42-
@Get("/all")
43-
@Version([VERSION_NEUTRAL])
44-
@ApiDescription({
45-
summary: "List of all platforms",
46-
deprecated: true,
47-
})
48-
@ApiQuery(metroOnlyQuery)
49-
async getAllPlatforms(@Query() query): Promise<PlatformSchema[]> {
50-
const schema = z.object({
51-
metroOnly: metroOnlySchema,
52-
});
53-
const parsed = schema.safeParse(query);
54-
if (!parsed.success) {
55-
throw new HttpException(
56-
parsed.error.format(),
57-
HttpStatus.BAD_REQUEST,
58-
);
59-
}
60-
61-
const platforms = await this.platformService.getAllPlatforms(
62-
parsed.data,
63-
);
64-
65-
return platformSchema.array().parse(platforms);
66-
}
67-
6841
@Get("/all")
6942
@Version([EndpointVersion.v1])
7043
@ApiDescription({
@@ -90,56 +63,6 @@ export class PlatformController {
9063
return platformSchema.array().parse(platforms);
9164
}
9265

93-
@Get("/closest")
94-
@Version([VERSION_NEUTRAL])
95-
@ApiDescription({
96-
description: `
97-
⚠️ _For better privacy consider using \`/in-box\`_
98-
99-
100-
Sort platforms by distance to a given location. Location may be saved in logs.
101-
`,
102-
summary: "List of platforms sorted by distance to a given location",
103-
deprecated: true,
104-
})
105-
@ApiQueries([
106-
metroOnlyQuery,
107-
latitudeQuery,
108-
longitudeQuery,
109-
{
110-
name: "count",
111-
type: Number,
112-
required: false,
113-
example: 100,
114-
description: "number of platforms to return, default is `0` (all)",
115-
},
116-
])
117-
async getPlatformsByDistance(
118-
@Query() query,
119-
): Promise<PlatformWithDistanceSchema[]> {
120-
const schema = z.object({
121-
latitude: z.coerce.number(),
122-
longitude: z.coerce.number(),
123-
count: z.coerce.number().int().nonnegative().default(0),
124-
metroOnly: metroOnlySchema,
125-
});
126-
127-
const parsed = schema.safeParse(query);
128-
129-
if (!parsed.success) {
130-
throw new HttpException(
131-
parsed.error.format(),
132-
HttpStatus.BAD_REQUEST,
133-
);
134-
}
135-
136-
const platforms = await this.platformService.getPlatformsByDistance(
137-
parsed.data,
138-
);
139-
140-
return platformWithDistanceSchema.array().parse(platforms);
141-
}
142-
14366
@Get("/closest")
14467
@Version([EndpointVersion.v1])
14568
@ApiDescription({
@@ -189,40 +112,6 @@ Sort platforms by distance to a given location. Location may be saved in logs.
189112
return platformWithDistanceSchema.array().parse(platforms);
190113
}
191114

192-
@Get("/in-box")
193-
@Version([VERSION_NEUTRAL])
194-
@ApiDescription({
195-
summary: "List of platforms within a given bounding box",
196-
deprecated: true,
197-
})
198-
@ApiQueries([metroOnlyQuery, ...boundingBoxQuery])
199-
async getPlatformsInBoundingBox(@Query() query): Promise<PlatformSchema[]> {
200-
const schema = z.object({
201-
boundingBox: boundingBoxSchema,
202-
metroOnly: metroOnlySchema,
203-
});
204-
const parsed = schema.safeParse({
205-
boundingBox: {
206-
latitude: query?.latitude,
207-
longitude: query?.longitude,
208-
},
209-
metroOnly: query?.metroOnly,
210-
});
211-
212-
if (!parsed.success) {
213-
throw new HttpException(
214-
"Invalid query params",
215-
HttpStatus.BAD_REQUEST,
216-
);
217-
}
218-
219-
const platforms = await this.platformService.getPlatformsInBoundingBox(
220-
parsed.data,
221-
);
222-
223-
return platformSchema.array().parse(platforms);
224-
}
225-
226115
@Get("/in-box")
227116
@Version([EndpointVersion.v1])
228117
@ApiDescription({

apps/backend/src/modules/stop/stop.controller.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import {
55
Query,
66
UseInterceptors,
77
Version,
8-
VERSION_NEUTRAL,
98
} from "@nestjs/common";
109
import { ApiQuery, ApiTags } from "@nestjs/swagger";
1110

12-
import { ApiDescription } from "src/decorators/swagger.decorator";
1311
import { EndpointVersion } from "src/enums/endpoint-version";
1412
import { LogInterceptor } from "src/modules/logger/log.interceptor";
1513
import { StopService } from "src/modules/stop/stop.service";
@@ -21,21 +19,6 @@ import { metroOnlyQuery } from "src/swagger/query.swagger";
2119
export class StopController {
2220
constructor(private readonly stopService: StopService) {}
2321

24-
@Get("/all")
25-
@Version([VERSION_NEUTRAL])
26-
@ApiQuery(metroOnlyQuery)
27-
@ApiDescription({
28-
deprecated: true,
29-
})
30-
async getAllStops(
31-
@Query("metroOnly")
32-
metroOnlyQuery: unknown,
33-
) {
34-
const metroOnly: boolean = metroOnlyQuery === "true";
35-
36-
return this.stopService.getAll({ metroOnly });
37-
}
38-
3922
@Get("/all")
4023
@Version([EndpointVersion.v1])
4124
@ApiQuery(metroOnlyQuery)

0 commit comments

Comments
 (0)