Skip to content

Commit 73ab3b3

Browse files
Sameh16Mikhail Savelyev
andauthored
Collections management (#2872)
Signed-off-by: Sameh16 <sameh_mohamed16@hotmail.com> Co-authored-by: Mikhail Savelyev <msavelyev@contractor.linuxfoundation.org>
1 parent 2252a9c commit 73ab3b3

File tree

73 files changed

+4049
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+4049
-74
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../security/permissions'
4+
import PermissionChecker from '../../services/user/permissionChecker'
5+
6+
/**
7+
* POST /collections
8+
* @summary Create a collection
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Create a new collection
12+
* @bodyContent {CollectionCreateInput} application/json
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionEdit)
20+
21+
const service = new CollectionService(req)
22+
const payload = await service.createCollection(req.body)
23+
24+
await req.responseHandler.success(req, res, payload)
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../security/permissions'
4+
import PermissionChecker from '../../services/user/permissionChecker'
5+
6+
/**
7+
* DELETE /collections/{id}
8+
* @summary Delete a collection
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Delete a collection by ID
12+
* @pathParam {string} id - The ID of the collection
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionEdit)
20+
21+
const service = new CollectionService(req)
22+
await service.destroy(req.params.id)
23+
24+
await req.responseHandler.success(req, res, true)
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../security/permissions'
4+
import PermissionChecker from '../../services/user/permissionChecker'
5+
6+
/**
7+
* GET /collections/{id}
8+
* @summary Get a collection
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Get a collection by ID
12+
* @pathParam {string} id - The ID of the collection
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionRead)
20+
21+
const service = new CollectionService(req)
22+
const payload = await service.findById(req.params.id)
23+
24+
await req.responseHandler.success(req, res, payload)
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../security/permissions'
4+
import PermissionChecker from '../../services/user/permissionChecker'
5+
6+
/**
7+
* POST /collections/query
8+
* @summary Query collections
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Query collections with filters and pagination
12+
* @bodyContent {CollectionsQuery} application/json
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionRead)
20+
21+
const service = new CollectionService(req)
22+
const payload = await service.query(req.body)
23+
24+
await req.responseHandler.success(req, res, payload)
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../security/permissions'
4+
import PermissionChecker from '../../services/user/permissionChecker'
5+
6+
/**
7+
* POST /collection/:id
8+
* @summary Update a collection
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Update a collection
12+
* @bodyContent {CollectionUpdateInput} application/json
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionEdit)
20+
21+
const service = new CollectionService(req)
22+
const payload = await service.updateCollection(req.params.id, req.body)
23+
24+
await req.responseHandler.success(req, res, payload)
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { safeWrap } from '../../middlewares/errorMiddleware'
2+
3+
export default (app) => {
4+
// Insights projects routes
5+
app.post(
6+
'/collections/insights-projects/query',
7+
safeWrap(require('./insightsProjects/insightsProjectsQuery').default),
8+
)
9+
app.post(
10+
'/collections/insights-projects',
11+
safeWrap(require('./insightsProjects/insightsProjectsCreate').default),
12+
)
13+
app.delete(
14+
'/collections/insights-projects/:id',
15+
safeWrap(require('./insightsProjects/insightsProjectsDestroy').default),
16+
)
17+
app.post(
18+
'/collections/insights-projects/:id',
19+
safeWrap(require('./insightsProjects/insightsProjectsUpdate').default),
20+
)
21+
app.get(
22+
'/collections/insights-projects/:id',
23+
safeWrap(require('./insightsProjects/insightsProjectsGet').default),
24+
)
25+
26+
// Collections routes
27+
app.post('/collections/query', safeWrap(require('./collectionsQuery').default))
28+
app.post('/collections', safeWrap(require('./collectionsCreate').default))
29+
app.get('/collections/:id', safeWrap(require('./collectionsGet').default))
30+
app.post('/collections/:id', safeWrap(require('./collectionsUpdate').default))
31+
app.delete('/collections/:id', safeWrap(require('./collectionsDestroy').default))
32+
33+
app.get('/segments/:id/repositories', safeWrap(require('./segmentsRepositoriesGet').default))
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../../security/permissions'
4+
import PermissionChecker from '../../../services/user/permissionChecker'
5+
6+
/**
7+
* POST /collections/insights-projects
8+
* @summary Create an insights project
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Create a new insights project
12+
* @bodyContent {InsightsProjectCreateInput} application/json
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionEdit)
20+
21+
const service = new CollectionService(req)
22+
const payload = await service.createInsightsProject(req.body)
23+
24+
await req.responseHandler.success(req, res, payload)
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../../security/permissions'
4+
import PermissionChecker from '../../../services/user/permissionChecker'
5+
6+
/**
7+
* DELETE /collections/insights-projects/{id}
8+
* @summary Delete an insights project
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Delete an insights project by ID
12+
* @pathParam {string} id - The ID of the insights project
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionEdit)
20+
21+
const service = new CollectionService(req)
22+
await service.destroyInsightsProject(req.params.id)
23+
24+
await req.responseHandler.success(req, res, true)
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../../security/permissions'
4+
import PermissionChecker from '../../../services/user/permissionChecker'
5+
6+
/**
7+
* GET /collections/insights-projects/:id
8+
* @summary Get an insights project
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Get an insights project by ID
12+
* @response 200 - Ok
13+
* @response 401 - Unauthorized
14+
* @response 404 - Not found
15+
* @response 429 - Too many requests
16+
*/
17+
export default async (req, res) => {
18+
new PermissionChecker(req).validateHas(Permissions.values.collectionEdit)
19+
20+
const service = new CollectionService(req)
21+
const payload = await service.findInsightsProjectById(req.params.id)
22+
23+
await req.responseHandler.success(req, res, payload)
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CollectionService } from '@/services/collectionService'
2+
3+
import Permissions from '../../../security/permissions'
4+
import PermissionChecker from '../../../services/user/permissionChecker'
5+
6+
/**
7+
* POST /collections/insights-projects/query
8+
* @summary Query insights projects
9+
* @tag Collections
10+
* @security Bearer
11+
* @description Query insights projects with filters and pagination
12+
* @bodyContent {InsightsProjectsQuery} application/json
13+
* @response 200 - Ok
14+
* @response 401 - Unauthorized
15+
* @response 404 - Not found
16+
* @response 429 - Too many requests
17+
*/
18+
export default async (req, res) => {
19+
new PermissionChecker(req).validateHas(Permissions.values.collectionRead)
20+
21+
const service = new CollectionService(req)
22+
const payload = await service.queryInsightsProjects(req.body)
23+
24+
await req.responseHandler.success(req, res, payload)
25+
}

0 commit comments

Comments
 (0)