forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgists.controller.ts
More file actions
69 lines (61 loc) 路 2.34 KB
/
Copy pathgists.controller.ts
File metadata and controls
69 lines (61 loc) 路 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Controller, Get, Post, Body, Param, Query, ParseUUIDPipe } from '@nestjs/common';
import { Throttle, SkipThrottle } from '@nestjs/throttler';
import { ApiOperation, ApiTags, ApiParam } from '@nestjs/swagger';
import { GistsService } from './gists.service';
import { CreateGistDto } from './dto/create-gist.dto';
import { QueryGistsDto } from './dto/query-gists.dto';
import { Gist } from './entities/gist.entity';
import { PaginatedResponse } from '../common/utils/pagination.helper';
@ApiTags('gists')
@Controller({ path: 'gists', version: '1' })
export class GistsController {
constructor(private readonly gistsService: GistsService) {}
@Post()
@Throttle({ default: { limit: 10, ttl: 60000 } })
@ApiOperation({ summary: 'Post a new anonymous gist at a location' })
async create(@Body() dto: CreateGistDto) {
return this.decorateGist(await this.gistsService.create(dto));
}
@Get()
@SkipThrottle()
@ApiOperation({ summary: 'Find gists near a location' })
async findNearby(@Query() query: QueryGistsDto) {
const response = await this.gistsService.findNearby(query);
return this.decoratePaginatedResponse(response);
}
// IMPORTANT: must be registered before @Get(':id') so NestJS does not
// match the literal string "count" as a UUID parameter.
@Get('count')
@SkipThrottle()
@ApiOperation({ summary: 'Count gists near a location (optionally broken down by cell)' })
countNearby(@Query() query: QueryGistsDto) {
return this.gistsService.countNearby(query);
}
@Get(':id/content')
@SkipThrottle()
@ApiOperation({ summary: 'Get the raw IPFS content for a gist' })
@ApiParam({ name: 'id', description: 'Gist UUID' })
findContent(@Param('id', ParseUUIDPipe) id: string) {
return this.gistsService.getContent(id);
}
@Get(':id')
@SkipThrottle()
@ApiOperation({ summary: 'Get a single gist by ID' })
@ApiParam({ name: 'id', description: 'Gist UUID' })
async findOne(@Param('id', ParseUUIDPipe) id: string) {
return this.decorateGist(await this.gistsService.findOne(id));
}
private decorateGist(gist: Gist) {
return {
...gist,
gist_id: gist.stellar_gist_id,
content_cid: gist.content_hash,
};
}
private decoratePaginatedResponse(response: PaginatedResponse<Gist>) {
return {
...response,
data: response.data.map((gist) => this.decorateGist(gist)),
};
}
}