Skip to content

Commit 4b63c3a

Browse files
authored
refactor(controllers): implement @api class-level annotation (#89)
1 parent a44d90e commit 4b63c3a

File tree

8 files changed

+53
-34
lines changed

8 files changed

+53
-34
lines changed

src/controllers/activity.controller.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
import {service} from '@loopback/core';
22
import {Filter, repository} from '@loopback/repository';
33
import {
4+
api,
45
get,
56
getModelSchemaRef,
67
HttpErrors,
78
param,
89
patch,
910
post,
1011
put,
11-
requestBody
12+
requestBody,
1213
} from '@loopback/rest';
1314
import {BigNumber} from 'ethers';
1415
import {ErrorResponse, GoodActivity} from '../models';
1516
import {GoodActivityRepository} from '../repositories';
1617
import {ProofOfGoodSmartContractService} from '../services';
18+
19+
@api({basePath: '/activity'})
1720
export class ActivityController {
1821
constructor(
1922
@repository(GoodActivityRepository)
2023
public goodActivityRepository: GoodActivityRepository,
2124
@service(ProofOfGoodSmartContractService)
2225
private proofOfGoodSmartContractService: ProofOfGoodSmartContractService,
23-
) { }
26+
) {}
2427

2528
/**
2629
* Create a new Activity
2730
*
2831
* @param activity
2932
*/
30-
@post('/activity', {
33+
@post('/', {
3134
summary: 'Create an Activity',
3235
operationId: 'post-activity',
3336
responses: {
@@ -152,7 +155,7 @@ export class ActivityController {
152155
* @param id The PoG ID of the Activity
153156
* @param oracle
154157
*/
155-
@patch('/activity/{id}', {
158+
@patch('/{id}', {
156159
summary: 'Change Activity Details',
157160
operationId: 'put-activity',
158161
responses: {
@@ -302,7 +305,7 @@ export class ActivityController {
302305
* @param id The PoG ID of the activity
303306
* @param activity
304307
*/
305-
@put('/activity/{id}', {
308+
@put('/{id}', {
306309
summary: 'Change Activity Details',
307310
operationId: 'put-activity',
308311
responses: {
@@ -401,7 +404,7 @@ export class ActivityController {
401404
* @param id The PoG ID of the activity
402405
* @returns A Proof of Good Activity
403406
*/
404-
@get('/activity/{id}', {
407+
@get('/{id}', {
405408
summary: 'Get Activity',
406409
operationId: 'get-activity',
407410
responses: {
@@ -449,7 +452,7 @@ export class ActivityController {
449452
return this.goodActivityRepository.findById(id);
450453
}
451454

452-
@get('/activity', {
455+
@get('/', {
453456
responses: {
454457
'200': {
455458
description: 'Retrieve all Proof of Good Activities',

src/controllers/auth.controller.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import {authenticate} from '@loopback/authentication';
22
import {authorize} from '@loopback/authorization';
33
import {inject, service} from '@loopback/core';
44
import {repository} from '@loopback/repository';
5-
import {getModelSchemaRef, post, requestBody, response} from '@loopback/rest';
5+
import {
6+
api,
7+
getModelSchemaRef,
8+
post,
9+
requestBody,
10+
response,
11+
} from '@loopback/rest';
612
import {SecurityBindings} from '@loopback/security';
713
import {GoodOracle, OracleApiKey} from '../models';
814
import {AUTH_STRATEGY_NAME} from '../providers/passport-bearer-auth.provider';
915
import {AuthRepository} from '../repositories';
1016
import {AuthService} from '../services';
1117

18+
@api({basePath: '/auth'})
19+
@authenticate(AUTH_STRATEGY_NAME)
1220
export class AuthController {
1321
constructor(
1422
@repository(AuthRepository) public authRepository: AuthRepository,
@@ -17,9 +25,8 @@ export class AuthController {
1725
private oracle: GoodOracle,
1826
) {}
1927

20-
@authenticate(AUTH_STRATEGY_NAME)
2128
@authorize({resource: 'SYSTEM_ONLY'})
22-
@post('/auth')
29+
@post('/')
2330
@response(200, {
2431
description: 'OracleApiKey model instance',
2532
content: {'application/json': {schema: getModelSchemaRef(OracleApiKey)}},
@@ -47,7 +54,6 @@ export class AuthController {
4754
return this.authRepository.create(oracleApiKey);
4855
}
4956

50-
@authenticate(AUTH_STRATEGY_NAME)
5157
@post('/refresh')
5258
@response(200, {
5359
description: 'OracleApiKey model instance',

src/controllers/category.controller.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {service} from '@loopback/core';
22
import {Filter, repository} from '@loopback/repository';
33
import {
4+
api,
45
get,
56
getModelSchemaRef,
67
HttpErrors,
@@ -14,6 +15,7 @@ import {ErrorResponse, GoodCategory} from '../models';
1415
import {GoodCategoryRepository} from '../repositories';
1516
import {ProofOfGoodSmartContractService} from '../services';
1617

18+
@api({basePath: '/category'})
1719
export class CategoryController {
1820
constructor(
1921
@repository(GoodCategoryRepository)
@@ -28,7 +30,7 @@ export class CategoryController {
2830
* @param id The PoG ID of the category
2931
* @param category
3032
*/
31-
@post('/category', {
33+
@post('/', {
3234
summary: 'Create a Category',
3335
operationId: 'post-category',
3436
responses: {
@@ -125,7 +127,7 @@ export class CategoryController {
125127
return response;
126128
}
127129

128-
@patch('/category/{id}', {
130+
@patch('/{id}', {
129131
summary: 'Change Category Details',
130132
operationId: 'patch-category',
131133
responses: {
@@ -256,7 +258,7 @@ export class CategoryController {
256258
* @param id The PoG ID of the category
257259
* @param category
258260
*/
259-
@put('/category/{id}', {
261+
@put('/{id}', {
260262
summary: 'Change Category Details',
261263
operationId: 'put-category',
262264
responses: {
@@ -353,7 +355,7 @@ export class CategoryController {
353355
* @param id The PoG ID of the category
354356
* @returns A Proof of Good Category
355357
*/
356-
@get('/category/{id}', {
358+
@get('/{id}', {
357359
summary: 'Get Category',
358360
operationId: 'get-category',
359361
responses: {
@@ -405,7 +407,7 @@ export class CategoryController {
405407
return this.goodCategoryRepository.findById(id);
406408
}
407409

408-
@get('/category', {
410+
@get('/', {
409411
responses: {
410412
'200': {
411413
description: 'Retrieve all Proof of Good Categories',

src/controllers/entry.controller.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {service} from '@loopback/core';
22
import {Filter, repository} from '@loopback/repository';
33
import {
4+
api,
45
get,
56
getModelSchemaRef,
67
HttpErrors,
@@ -22,6 +23,8 @@ export type PogProfileParams = {
2223
email: string;
2324
doGooder: string;
2425
};
26+
27+
@api({basePath: '/entry'})
2528
export class GoodEntryController {
2629
constructor(
2730
@repository(GoodEntryRepository)
@@ -40,7 +43,7 @@ export class GoodEntryController {
4043
* @param id The PoG ID of the entry
4144
* @returns A Proof of Good Entry
4245
*/
43-
@get('/entry/{id}', {
46+
@get('/{id}', {
4447
summary: 'Get Proof of Good Entry',
4548
operationId: 'get-entry',
4649
responses: {
@@ -88,7 +91,7 @@ export class GoodEntryController {
8891
return this.goodEntryRepository.findById(id);
8992
}
9093

91-
@get('/entry', {
94+
@get('/', {
9295
responses: {
9396
'200': {
9497
description: 'Retrieve all Proof of Good Entries',
@@ -117,7 +120,7 @@ export class GoodEntryController {
117120
* @param entry The PoG ID of the entry
118121
* @returns A Proof of Good Entry
119122
*/
120-
@post('/entry', {
123+
@post('/', {
121124
summary: 'Create a GoodEntry',
122125
operationId: 'post-pog-entry',
123126
responses: {

src/controllers/oracle.controller.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {authorize} from '@loopback/authorization';
33
import {inject, service} from '@loopback/core';
44
import {Filter, repository} from '@loopback/repository';
55
import {
6+
api,
67
get,
78
getModelSchemaRef,
89
HttpErrors,
@@ -19,6 +20,7 @@ import {AUTH_STRATEGY_NAME} from '../providers/passport-bearer-auth.provider';
1920
import {GoodOracleRepository} from '../repositories';
2021
import {ProofOfGoodSmartContractService} from '../services';
2122

23+
@api({basePath: '/oracle'})
2224
@authenticate(AUTH_STRATEGY_NAME)
2325
@authorize({resource: 'oracle'})
2426
export class OracleController {
@@ -36,7 +38,7 @@ export class OracleController {
3638
*
3739
* @param oracle
3840
*/
39-
@post('/oracle', {
41+
@post('/', {
4042
summary: 'Create an Oracle',
4143
operationId: 'post-oracle',
4244
responses: {
@@ -149,7 +151,7 @@ export class OracleController {
149151
* @param id The PoG ID of the oracle
150152
* @returns A Proof of Good Oracle
151153
*/
152-
@get('/oracle/{id}', {
154+
@get('/{id}', {
153155
summary: 'Get Oracle',
154156
operationId: 'get-oracle',
155157
responses: {
@@ -203,7 +205,7 @@ export class OracleController {
203205
return this.goodOracleRepository.findById(id);
204206
}
205207

206-
@get('/oracle', {
208+
@get('/', {
207209
responses: {
208210
'200': {
209211
description: 'Retrieve all Proof of Good Oracles',
@@ -232,7 +234,7 @@ export class OracleController {
232234
* @param id The ID of the oracle
233235
* @param oracle
234236
*/
235-
@patch('/oracle/{id}', {
237+
@patch('/{id}', {
236238
summary: 'Change Oracle Details',
237239
operationId: 'patch-oracle',
238240
responses: {
@@ -376,7 +378,7 @@ export class OracleController {
376378
* @param id The PoG ID of the oracle
377379
* @param oracle
378380
*/
379-
@put('/oracle/{id}', {
381+
@put('/{id}', {
380382
summary: 'Change Oracle Details',
381383
operationId: 'put-oracle',
382384
responses: {
@@ -458,7 +460,7 @@ export class OracleController {
458460
*
459461
* @param oracle
460462
*/
461-
@post('/oracle/cap', {
463+
@post('/cap', {
462464
summary: 'Set Oracle cap',
463465
operationId: 'post-oracle-cap',
464466
responses: {

src/controllers/profile.controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import {authenticate} from '@loopback/authentication';
22
import {authorize} from '@loopback/authorization';
33
import {inject, service} from '@loopback/core';
44
import {repository} from '@loopback/repository';
5-
import {get, param, post, requestBody} from '@loopback/rest';
5+
import {api, get, param, post, requestBody} from '@loopback/rest';
66
import {SecurityBindings} from '@loopback/security';
77
import {GoodOracle, PogProfile} from '../models';
88
import {AUTH_STRATEGY_NAME} from '../providers/passport-bearer-auth.provider';
99
import {PogProfileRepository} from '../repositories';
1010
import {ProofOfGoodSmartContractService} from '../services';
1111

12+
@api({basePath: '/profile'})
1213
export class ProfileController {
1314
constructor(
1415
@repository(PogProfileRepository)
@@ -21,7 +22,7 @@ export class ProfileController {
2122

2223
@authenticate(AUTH_STRATEGY_NAME)
2324
@authorize({resource: 'SYSTEM_ONLY'})
24-
@post('/profile/consolidate')
25+
@post('/consolidate')
2526
async merge(
2627
@requestBody({
2728
content: {
@@ -132,7 +133,7 @@ export class ProfileController {
132133
return {};
133134
}
134135

135-
@get('/profile/{id}/points')
136+
@get('/{id}/points')
136137
async getUserGoodPoints(
137138
@param({
138139
schema: {

src/controllers/type.controller.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {service} from '@loopback/core';
22
import {Filter, repository} from '@loopback/repository';
33
import {
4+
api,
45
get,
56
getModelSchemaRef,
67
HttpErrors,
@@ -14,6 +15,7 @@ import {ErrorResponse, GoodType} from '../models';
1415
import {GoodTypeRepository} from '../repositories';
1516
import {ProofOfGoodSmartContractService} from '../services';
1617

18+
@api({basePath: '/type'})
1719
export class GoodTypeController {
1820
constructor(
1921
@repository(GoodTypeRepository)
@@ -22,7 +24,7 @@ export class GoodTypeController {
2224
private proofOfGoodSmartContractService: ProofOfGoodSmartContractService,
2325
) {}
2426

25-
@post('/type', {
27+
@post('/', {
2628
summary: 'Create a Good Type',
2729
operationId: 'post-good-type',
2830
responses: {
@@ -115,7 +117,7 @@ export class GoodTypeController {
115117
} as GoodType);
116118
}
117119

118-
@patch('/type/{id}', {
120+
@patch('/{id}', {
119121
summary: 'Update a Good Type',
120122
operationId: 'patch-good-type',
121123
responses: {
@@ -238,7 +240,7 @@ export class GoodTypeController {
238240
});
239241
}
240242

241-
@put('/type/{id}', {
243+
@put('/{id}', {
242244
summary: 'Change Good Type Details',
243245
operationId: 'put-good-type',
244246
responses: {
@@ -322,7 +324,7 @@ export class GoodTypeController {
322324
return this.patchGoodType(id, goodType);
323325
}
324326

325-
@get('/type/{id}', {
327+
@get('/{id}', {
326328
summary: 'Get Good Type',
327329
operationId: 'get-good-type',
328330
responses: {
@@ -374,7 +376,7 @@ export class GoodTypeController {
374376
return this.goodTypeRepository.findById(id);
375377
}
376378

377-
@get('/type', {
379+
@get('/', {
378380
responses: {
379381
'200': {
380382
description: 'Retrieve all Proof of Good Categories',

src/models/oracle-api-key.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class OracleApiKey extends Entity {
5656
default: false,
5757
},
5858
})
59-
expired: boolean;
59+
expired: boolean = false;
6060
}
6161

6262
export interface OracleApiKeyRelations {

0 commit comments

Comments
 (0)