Skip to content

Commit ba5b1dc

Browse files
authored
Merge pull request #80 from imcaizheng/add-skills-endpoint
implement taas-teams skills endpoint
2 parents 5ccfb7a + be275c8 commit ba5b1dc

File tree

8 files changed

+254
-0
lines changed

8 files changed

+254
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The following parameters can be set in config files or in env variables:
3636
- `PROJECT_API_URL`: the project service url
3737
- `TC_API`: the Topcoder v5 url
3838
- `ORG_ID`: the organization id
39+
- `TOPCODER_SKILL_PROVIDER_ID`: the referenced skill provider id
3940

4041
- `esConfig.HOST`: the elasticsearch host
4142
- `esConfig.ES_INDEX_JOB`: the job index

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121

2222
TC_API: process.env.TC_API || 'https://api.topcoder-dev.com/v5',
2323
ORG_ID: process.env.ORG_ID || '36ed815b-3da1-49f1-a043-aaed0a4e81ad',
24+
TOPCODER_SKILL_PROVIDER_ID: process.env.TOPCODER_SKILL_PROVIDER_ID,
2425

2526
TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',
2627

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,6 +4366,45 @@
43664366
}
43674367
},
43684368
"response": []
4369+
},
4370+
{
4371+
"name": "GET /taas-teams/skills",
4372+
"request": {
4373+
"method": "GET",
4374+
"header": [
4375+
{
4376+
"key": "Authorization",
4377+
"value": "Bearer {{token_member}}",
4378+
"type": "text"
4379+
}
4380+
],
4381+
"url": {
4382+
"raw": "{{URL}}/taas-teams/skills?perPage=10&page=1&orderBy=name",
4383+
"host": [
4384+
"{{URL}}"
4385+
],
4386+
"path": [
4387+
"taas-teams",
4388+
"skills"
4389+
],
4390+
"query": [
4391+
{
4392+
"key": "perPage",
4393+
"value": "10"
4394+
},
4395+
{
4396+
"key": "page",
4397+
"value": "1"
4398+
},
4399+
{
4400+
"key": "orderBy",
4401+
"value": "name",
4402+
"description": "possible values are defined by /v5/skills"
4403+
}
4404+
]
4405+
}
4406+
},
4407+
"response": []
43694408
}
43704409
],
43714410
"protocolProfileBehavior": {}

docs/swagger.yaml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,96 @@ paths:
14911491
application/json:
14921492
schema:
14931493
$ref: '#/components/schemas/Error'
1494+
/taas-teams/skills:
1495+
get:
1496+
tags:
1497+
- Teams
1498+
description: |
1499+
Serves as a proxy endpoint for /v5/skills, allowing to be accessed by any topcoder user.
1500+
parameters:
1501+
- in: query
1502+
name: page
1503+
required: false
1504+
schema:
1505+
type: integer
1506+
default: 1
1507+
description: The page number.
1508+
- in: query
1509+
name: perPage
1510+
required: false
1511+
schema:
1512+
type: integer
1513+
default: 20
1514+
description: The number of items to list per page.
1515+
- name: orderBy
1516+
in: query
1517+
schema:
1518+
type: string
1519+
description: "Specify by which field to sort by. Sorts in ascending order only"
1520+
security:
1521+
- bearerAuth: []
1522+
responses:
1523+
'200':
1524+
description: OK
1525+
content:
1526+
application/json:
1527+
schema:
1528+
type: array
1529+
items:
1530+
$ref: '#/components/schemas/UbahnSkill'
1531+
headers:
1532+
X-Next-Page:
1533+
schema:
1534+
type: integer
1535+
description: The index of the next page
1536+
X-Page:
1537+
schema:
1538+
type: integer
1539+
description: The index of the current page (starting at 1)
1540+
X-Per-Page:
1541+
schema:
1542+
type: integer
1543+
description: The number of items to list per page
1544+
X-Prev-Page:
1545+
schema:
1546+
type: integer
1547+
description: The index of the previous page
1548+
X-Total:
1549+
schema:
1550+
type: integer
1551+
description: The total number of items
1552+
X-Total-Pages:
1553+
schema:
1554+
type: integer
1555+
description: The total number of pages
1556+
Link:
1557+
schema:
1558+
type: string
1559+
description: Pagination link header.
1560+
'400':
1561+
description: Bad request
1562+
content:
1563+
application/json:
1564+
schema:
1565+
$ref: '#/components/schemas/Error'
1566+
'401':
1567+
description: Not authenticated
1568+
content:
1569+
application/json:
1570+
schema:
1571+
$ref: '#/components/schemas/Error'
1572+
'403':
1573+
description: Forbidden
1574+
content:
1575+
application/json:
1576+
schema:
1577+
$ref: '#/components/schemas/Error'
1578+
'500':
1579+
description: Internal Server Error
1580+
content:
1581+
application/json:
1582+
schema:
1583+
$ref: '#/components/schemas/Error'
14941584
/health:
14951585
get:
14961586
tags:
@@ -2056,6 +2146,42 @@ components:
20562146
type: string
20572147
example: 'React'
20582148
description: The skill name.
2149+
UbahnSkill:
2150+
type: object
2151+
properties:
2152+
id:
2153+
type: "string"
2154+
format: "UUID"
2155+
description: "The skill id"
2156+
skillProviderId:
2157+
type: "string"
2158+
format: "UUID"
2159+
description: "The referenced skill provider id"
2160+
name:
2161+
type: "string"
2162+
description: "The name of the skill"
2163+
externalId:
2164+
type: "string"
2165+
description: "The external id for the skill"
2166+
uri:
2167+
type: "string"
2168+
description: "The uri for the skill"
2169+
created:
2170+
type: "string"
2171+
format: "date-time"
2172+
description: "When the entity was created."
2173+
updated:
2174+
type: "string"
2175+
format: "date-time"
2176+
description: "When the entity was updated."
2177+
createdBy:
2178+
type: "string"
2179+
format: "UUID"
2180+
description: "Creator of the entity."
2181+
updatedBy:
2182+
type: "string"
2183+
format: "UUID"
2184+
description: "User that last updated the entity."
20592185
JobForTeam:
20602186
properties:
20612187
id:

src/common/helper.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,38 @@ async function getProjectById (currentUser, id) {
473473
}
474474
}
475475

476+
/**
477+
* Function to search skills from v5/skills
478+
* @param {Object} criteria the search criteria
479+
* @returns the request result
480+
*/
481+
async function getSkills (criteria) {
482+
const token = await getM2Mtoken()
483+
try {
484+
const res = await request
485+
.get(`${config.TC_API}/skills`)
486+
.query({
487+
skillProviderId: config.TOPCODER_SKILL_PROVIDER_ID,
488+
...criteria
489+
})
490+
.set('Authorization', `Bearer ${token}`)
491+
.set('Content-Type', 'application/json')
492+
.set('Accept', 'application/json')
493+
localLogger.debug({ context: 'getSkills', message: `response body: ${JSON.stringify(res.body)}` })
494+
return {
495+
total: Number(_.get(res.headers, 'x-total')),
496+
page: Number(_.get(res.headers, 'x-page')),
497+
perPage: Number(_.get(res.headers, 'x-per-page')),
498+
result: res.body
499+
}
500+
} catch (err) {
501+
if (err.status === HttpStatus.BAD_REQUEST) {
502+
throw new errors.BadRequestError(err.response.body.message)
503+
}
504+
throw err
505+
}
506+
}
507+
476508
/**
477509
* Function to get skill by id
478510
* @param {String} skillId the skill Id
@@ -591,6 +623,7 @@ module.exports = {
591623
getUserById,
592624
getMembers,
593625
getProjectById,
626+
getSkills,
594627
getSkillById,
595628
getUserSkill,
596629
ensureJobById,

src/controllers/SkillController.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Controller for skills endpoints
3+
*/
4+
const service = require('../services/SkillService')
5+
const helper = require('../common/helper')
6+
7+
/**
8+
* Search skills
9+
* @param req the request
10+
* @param res the response
11+
*/
12+
async function searchSkills (req, res) {
13+
const result = await service.searchSkills(req.query)
14+
helper.setResHeaders(req, res, result)
15+
res.send(result.result)
16+
}
17+
18+
module.exports = {
19+
searchSkills
20+
}

src/routes/TeamRoutes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ module.exports = {
1212
scopes: [constants.Scopes.READ_TAAS_TEAM]
1313
}
1414
},
15+
'/taas-teams/skills': {
16+
get: {
17+
controller: 'SkillController',
18+
method: 'searchSkills',
19+
auth: 'jwt',
20+
scopes: [constants.Scopes.READ_TAAS_TEAM]
21+
}
22+
},
1523
'/taas-teams/:id': {
1624
get: {
1725
controller: 'TeamController',

src/services/SkillService.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* This service provides operations of Skill.
3+
*/
4+
const Joi = require('joi')
5+
const helper = require('../common/helper')
6+
7+
/**
8+
* Search skills
9+
* @param {Object} criteria the search criteria
10+
* @returns {Object} the search result, contain total/page/perPage and result array
11+
*/
12+
async function searchSkills (criteria) {
13+
return helper.getSkills(criteria)
14+
}
15+
16+
searchSkills.schema = Joi.object().keys({
17+
criteria: Joi.object().keys({
18+
page: Joi.page(),
19+
perPage: Joi.perPage(),
20+
orderBy: Joi.string()
21+
}).required()
22+
}).required()
23+
24+
module.exports = {
25+
searchSkills
26+
}

0 commit comments

Comments
 (0)