Merge "Common folder"
[ccsdk/cds.git] / cds-ui / server / src / controllers / blueprint-rest.controller.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
5 ===================================================================
6
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
20 */
21
22
23
24 import {
25   Count,
26   CountSchema,
27   Filter,
28   repository,
29   Where,
30 } from '@loopback/repository';
31 import {
32   post,
33   param,
34   get,
35   getFilterSchemaFor,
36   getWhereSchemaFor,
37   patch,
38   put,
39   del,
40   requestBody,
41 } from '@loopback/rest';
42 import {Blueprint} from '../models';
43 import {BlueprintRepository} from '../repositories';
44
45 export class BlueprintRestController {
46   constructor(
47     @repository(BlueprintRepository)
48     public blueprintRepository : BlueprintRepository,
49   ) {}
50
51   @post('/blueprints', {
52     responses: {
53       '200': {
54         description: 'Blueprint model instance',
55         content: {'application/json': {schema: {'x-ts-type': Blueprint}}},
56       },
57     },
58   })
59   async create(@requestBody() blueprint: Blueprint): Promise<Blueprint> {
60     return await this.blueprintRepository.create(blueprint);
61   }
62
63   @get('/blueprints/count', {
64     responses: {
65       '200': {
66         description: 'Blueprint model count',
67         content: {'application/json': {schema: CountSchema}},
68       },
69     },
70   })
71   async count(
72     @param.query.object('where', getWhereSchemaFor(Blueprint)) where?: Where,
73   ): Promise<Count> {
74     return await this.blueprintRepository.count(where);
75   }
76
77   @get('/blueprints', {
78     responses: {
79       '200': {
80         description: 'Array of Blueprint model instances',
81         content: {
82           'application/json': {
83             schema: {type: 'array', items: {'x-ts-type': Blueprint}},
84           },
85         },
86       },
87     },
88   })
89   async find(
90     @param.query.object('filter', getFilterSchemaFor(Blueprint)) filter?: Filter,
91   ): Promise<Blueprint[]> {
92     return await this.blueprintRepository.find(filter);
93   }
94
95   @patch('/blueprints', {
96     responses: {
97       '200': {
98         description: 'Blueprint PATCH success count',
99         content: {'application/json': {schema: CountSchema}},
100       },
101     },
102   })
103   async updateAll(
104     @requestBody() blueprint: Blueprint,
105     @param.query.object('where', getWhereSchemaFor(Blueprint)) where?: Where,
106   ): Promise<Count> {
107     return await this.blueprintRepository.updateAll(blueprint, where);
108   }
109
110   @get('/blueprints/{id}', {
111     responses: {
112       '200': {
113         description: 'Blueprint model instance',
114         content: {'application/json': {schema: {'x-ts-type': Blueprint}}},
115       },
116     },
117   })
118   async findById(@param.path.number('id') id: number): Promise<Blueprint> {
119     return await this.blueprintRepository.findById(id);
120   }
121
122   @patch('/blueprints/{id}', {
123     responses: {
124       '204': {
125         description: 'Blueprint PATCH success',
126       },
127     },
128   })
129   async updateById(
130     @param.path.number('id') id: number,
131     @requestBody() blueprint: Blueprint,
132   ): Promise<void> {
133     await this.blueprintRepository.updateById(id, blueprint);
134   }
135
136   @put('/blueprints/{id}', {
137     responses: {
138       '204': {
139         description: 'Blueprint PUT success',
140       },
141     },
142   })
143   async replaceById(
144     @param.path.number('id') id: number,
145     @requestBody() blueprint: Blueprint,
146   ): Promise<void> {
147     await this.blueprintRepository.replaceById(id, blueprint);
148   }
149
150   @del('/blueprints/{id}', {
151     responses: {
152       '204': {
153         description: 'Blueprint DELETE success',
154       },
155     },
156   })
157   async deleteById(@param.path.number('id') id: number): Promise<void> {
158     await this.blueprintRepository.deleteById(id);
159   }
160 }