-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcourses.controller.ts
More file actions
218 lines (197 loc) · 6.48 KB
/
courses.controller.ts
File metadata and controls
218 lines (197 loc) · 6.48 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import {
Body,
Controller,
Get,
HttpStatus,
Logger,
Param,
ParseUUIDPipe,
Post,
Query,
Res,
} from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CourseResponseDto } from '../filter/dto/course-response.dto';
import { RedisStoreService } from '../redis-store/redis-store.service';
import { CoursesService } from './courses.service';
import {
ConfirmRequestDto,
CourseDefaultResponseDto,
CourseRatingRequestDto,
UpdateRequestDto,
} from './dto';
@Controller('courses')
@ApiTags('courses')
export class CoursesController {
private readonly logger = new Logger(CoursesController.name);
constructor(
private readonly coursesService: CoursesService,
private readonly redisStoreService: RedisStoreService,
) {}
@Get('/search')
@ApiOperation({
summary: 'search request from consumer and forward it to the onest network',
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Acknowledgement of confirm request',
type: CourseDefaultResponseDto,
})
async search(
@Res() res,
@Query('searchText') searchText: string,
): Promise<CourseDefaultResponseDto> {
try {
this.logger.log(
`Initiated triggering backen gateway for searching courses on onest network for:- ${searchText}`,
);
const response = await this.coursesService.search(searchText);
this.logger.log(
`Successfully triggered backen gateway to search courses on onest network for:- ${searchText}`,
);
return res.status(HttpStatus.OK).json(response);
} catch (error) {
this.logger.error(
`Failed to trigger backen gateway to search courses on onest network for:- ${searchText}`,
error,
);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
message: error.message,
});
}
}
@Get('/poll/:messageId')
@ApiOperation({
summary:
'Api to poll search results for a specific search query(a particular messageId)',
})
@ApiResponse({
status: HttpStatus.OK,
type: CourseResponseDto,
isArray: true,
})
async pollSearchResults(
@Param('messageId', ParseUUIDPipe) messageId: string,
@Res() res,
): Promise<CourseResponseDto[]> {
try {
this.logger.log(
`Initiated polling search result for message id #${messageId} on redis`,
);
const results = await this.redisStoreService.pollValue(messageId);
this.logger.log(
`Successfully polled search result for message id #${messageId} on redis`,
);
return res.status(HttpStatus.OK).json({
message: 'New Search responses fetched',
data: results,
});
} catch (error) {
this.logger.error(
`Failed to poll search result for message id #${messageId} on redis`,
error,
);
return res
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.json({ message: error.message });
}
}
@Post('/confirm')
@ApiOperation({
summary: 'confirm request from consumer and forward it to the bpp',
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Acknowledgement of confirm request',
type: CourseDefaultResponseDto,
})
async confirmOrder(
@Res() res,
@Body() confirmDto: ConfirmRequestDto,
): Promise<CourseDefaultResponseDto> {
try {
this.logger.log(
`Initiated triggering bpp uri for confirmation of course with id #${confirmDto.courseId} and provider id #${confirmDto.providerId}`,
);
const response = await this.coursesService.confirmOrder(confirmDto);
this.logger.log(
`Successfully triggered bpp uri for confirmation course with id #${confirmDto.courseId} and provider id #${confirmDto.providerId}`,
);
return res.status(HttpStatus.OK).json(response);
} catch (error) {
this.logger.error(
`Failed to trigger bpp uri for confirmation of course with id #${confirmDto.courseId} and provider id #${confirmDto.providerId}`,
error,
);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
message: error.message,
});
}
}
@Post('/update')
@ApiOperation({
summary: 'update request from consumer and forward it to the bpp',
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Acknowledgement of confirm request',
type: CourseDefaultResponseDto,
})
async updateOrder(
@Res() res,
@Body() updateRequestDto: UpdateRequestDto,
): Promise<CourseDefaultResponseDto> {
try {
this.logger.log(
`Initiated triggering bpp uri for status updating of purchased course with message id #${updateRequestDto.messageId} and transactionId id #${updateRequestDto.transactionId}`,
);
const response = await this.coursesService.updateOrder(updateRequestDto);
this.logger.log(
`Successfully triggered bpp uri for status updating of purchased course with message id #${updateRequestDto.messageId} and transactionId id #${updateRequestDto.transactionId}`,
);
return res.status(HttpStatus.OK).json(response);
} catch (error) {
this.logger.error(
`Failed to trigger bpp uri for status updating of purchased course with message id #${updateRequestDto.messageId} and transactionId id #${updateRequestDto.transactionId}`,
error,
);
return res
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.json({ message: error.message });
}
}
@Post('/rating')
@ApiOperation({
summary: 'course rating request from consumer and forward it to the bpp',
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Acknowledgement of confirm request',
type: CourseDefaultResponseDto,
})
async courseRating(
@Res() res,
@Body() courseRatingRequestDto: CourseRatingRequestDto,
): Promise<CourseDefaultResponseDto> {
try {
this.logger.log(
`Initiated triggering bpp uri for rating of course with id #${courseRatingRequestDto.courseId}`,
);
const response = await this.coursesService.courseRating(
courseRatingRequestDto,
);
this.logger.log(
`Successfully to trigger bpp uri for rating of course with id #${courseRatingRequestDto.courseId}`,
);
return res.status(HttpStatus.OK).json(response);
} catch (error) {
this.logger.error(
`Failed to trigger bpp uri for rating of course with id #${courseRatingRequestDto.courseId}`,
error,
);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
message: error.message,
});
}
}
}