Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 48d08f0

Browse files
committed
setting up stub server
1 parent f0d25ae commit 48d08f0

File tree

12 files changed

+633
-0
lines changed

12 files changed

+633
-0
lines changed

.swagger-codegen-ignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Swagger Codegen Ignore
2+
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md

.swagger-codegen/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.4.13

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node index.js

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1+
# Swagger generated server
2+
13
# u-bahn-search-ui-api
24
Universal Identity Search UI API
5+
6+
7+
## Overview
8+
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
9+
10+
### Running the server
11+
To run the server, run:
12+
13+
```
14+
npm start
15+
```
16+
17+
To view the Swagger UI interface:
18+
19+
```
20+
open http://localhost:8080/docs
21+
```
22+
23+
This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work.

api/swagger.yaml

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
---
2+
swagger: "2.0"
3+
info:
4+
description: "This is the API specification for the User Interface server that will\
5+
\ host the front end for the Project UBahn application"
6+
version: "1.0.0"
7+
title: "UBahn user interface server"
8+
host: "ubahn-dev-ui.com"
9+
basePath: "/api"
10+
tags:
11+
- name: "templates"
12+
description: "Template files to serve as reference for multitude of tasks"
13+
- name: "uploads"
14+
description: "Upload files for batch processing"
15+
schemes:
16+
- "https"
17+
- "http"
18+
paths:
19+
/templates:
20+
post:
21+
tags:
22+
- "templates"
23+
summary: "Create a new template"
24+
description: "Accepts a file as input and responds with an id to identify the\
25+
\ file later. Uploads the file to Amazon S3 and stores the url against the\
26+
\ template id in the database. Before upload to S3, the file type needs to\
27+
\ be detected and passed as content-type during S3 upload. Needs to restrict\
28+
\ file size to 2 MB"
29+
operationId: "createTemplate"
30+
consumes:
31+
- "multipart/form-data"
32+
produces:
33+
- "application/json"
34+
parameters:
35+
- name: "template"
36+
in: "formData"
37+
description: "The template file that needs to be created. Supports any format."
38+
required: true
39+
type: "file"
40+
- name: "name"
41+
in: "formData"
42+
description: "The name of the template. Should be unique"
43+
required: true
44+
type: "string"
45+
responses:
46+
"200":
47+
description: "Ok - the request was successful"
48+
schema:
49+
$ref: "#/definitions/Template"
50+
"400":
51+
$ref: "#/definitions/BadRequest"
52+
"401":
53+
$ref: "#/definitions/Unauthorized"
54+
"409":
55+
$ref: "#/definitions/Conflict"
56+
"500":
57+
$ref: "#/definitions/ServerError"
58+
security:
59+
- api_key: []
60+
x-swagger-router-controller: "Templates"
61+
/templates/:id:
62+
get:
63+
tags:
64+
- "templates"
65+
summary: "Get template identified by id"
66+
description: "Responds with the details of a template"
67+
operationId: "getTemplateById"
68+
produces:
69+
- "application/json"
70+
parameters: []
71+
responses:
72+
"200":
73+
description: "Success"
74+
schema:
75+
$ref: "#/definitions/Template"
76+
"401":
77+
$ref: "#/definitions/Unauthorized"
78+
"403":
79+
$ref: "#/definitions/Forbidden"
80+
"404":
81+
$ref: "#/definitions/NotFound"
82+
"500":
83+
$ref: "#/definitions/ServerError"
84+
security:
85+
- api_key: []
86+
x-swagger-router-controller: "Templates"
87+
/uploads:
88+
post:
89+
tags:
90+
- "uploads"
91+
summary: "Upload an excel file for batch processing"
92+
description: "Accepts only an excel file as input and responds with an id to\
93+
\ identify the upload later. Uploads the file to Amazon S3 and stores the\
94+
\ url against the upload id in the database. No restriction on file size for\
95+
\ now. On upload, the status against the upload id is set to `pending` in\
96+
\ the database and the entire upload object (the upload database item) is\
97+
\ posted to the Bus API"
98+
operationId: "createUpload"
99+
consumes:
100+
- "multipart/form-data"
101+
produces:
102+
- "application/json"
103+
parameters:
104+
- name: "upload"
105+
in: "formData"
106+
description: "The excel file that needs to be processed"
107+
required: true
108+
type: "file"
109+
responses:
110+
"200":
111+
description: "Success"
112+
schema:
113+
$ref: "#/definitions/Upload"
114+
"400":
115+
$ref: "#/definitions/BadRequest"
116+
"401":
117+
$ref: "#/definitions/Unauthorized"
118+
"404":
119+
$ref: "#/definitions/BadRequest"
120+
"500":
121+
$ref: "#/definitions/ServerError"
122+
security:
123+
- api_key: []
124+
x-swagger-router-controller: "Uploads"
125+
/uploads/:id:
126+
get:
127+
tags:
128+
- "uploads"
129+
summary: "Get the details of an upload"
130+
description: "Responds with the details of an upload"
131+
operationId: "getUploadById"
132+
produces:
133+
- "application/json"
134+
parameters: []
135+
responses:
136+
"200":
137+
description: "Success"
138+
schema:
139+
$ref: "#/definitions/Upload"
140+
"401":
141+
$ref: "#/definitions/Unauthorized"
142+
"403":
143+
$ref: "#/definitions/Forbidden"
144+
"404":
145+
$ref: "#/definitions/NotFound"
146+
"500":
147+
$ref: "#/definitions/ServerError"
148+
security:
149+
- api_key: []
150+
x-swagger-router-controller: "Uploads"
151+
patch:
152+
tags:
153+
- "uploads"
154+
summary: "Update the upload attributes"
155+
description: "For now, only support an update on the `status` attribute of the\
156+
\ upload associated with the id with either `completed` or `failed` value.\
157+
\ Optionally accept an update on the `info` attribute as well."
158+
operationId: "updateUploadById"
159+
consumes:
160+
- "application/json"
161+
produces:
162+
- "application/json"
163+
parameters:
164+
- in: "body"
165+
name: "body"
166+
description: "The request body"
167+
required: true
168+
schema:
169+
$ref: "#/definitions/body"
170+
responses:
171+
"200":
172+
description: "Success"
173+
schema:
174+
$ref: "#/definitions/Upload"
175+
"400":
176+
$ref: "#/definitions/BadRequest"
177+
"401":
178+
$ref: "#/definitions/Unauthorized"
179+
"403":
180+
$ref: "#/definitions/Forbidden"
181+
"404":
182+
$ref: "#/definitions/NotFound"
183+
"500":
184+
$ref: "#/definitions/ServerError"
185+
security:
186+
- api_key: []
187+
x-swagger-router-controller: "Uploads"
188+
securityDefinitions:
189+
api_key:
190+
type: "apiKey"
191+
name: "api_key"
192+
in: "header"
193+
definitions:
194+
Template:
195+
allOf:
196+
- type: "object"
197+
properties:
198+
id:
199+
type: "string"
200+
format: "uuid"
201+
name:
202+
type: "string"
203+
description: "The name of the template. Should be unique."
204+
url:
205+
type: "string"
206+
format: "uri"
207+
description: "S3 signed url"
208+
- $ref: "#/definitions/AuditFields"
209+
Upload:
210+
allOf:
211+
- type: "object"
212+
properties:
213+
id:
214+
type: "string"
215+
format: "uuid"
216+
url:
217+
type: "string"
218+
format: "uri"
219+
description: "S3 signed url"
220+
status:
221+
type: "string"
222+
enum:
223+
- "pending"
224+
- "completed"
225+
- "failed"
226+
info:
227+
type: "string"
228+
description: "If status is `failed`, then this field will contain information\
229+
\ on why the processing failed"
230+
- $ref: "#/definitions/AuditFields"
231+
AuditFields:
232+
type: "object"
233+
required:
234+
- "created"
235+
- "createdBy"
236+
- "updated"
237+
- "updatedBy"
238+
properties:
239+
created:
240+
type: "string"
241+
format: "date-time"
242+
description: "When the entity was created."
243+
updated:
244+
type: "string"
245+
format: "date-time"
246+
description: "When the entity was updated."
247+
createdBy:
248+
type: "integer"
249+
description: "Creator of the entity."
250+
updatedBy:
251+
type: "integer"
252+
description: "User that last updated the entity."
253+
description: "Describes the audit fields that are present in all the models in\
254+
\ this API."
255+
Unauthorized:
256+
type: "object"
257+
properties:
258+
message:
259+
type: "string"
260+
example: "Unable to authenticate the user."
261+
description: "The unauthorized error message."
262+
description: "The unauthorized error entity."
263+
NotFound:
264+
type: "object"
265+
properties:
266+
message:
267+
type: "string"
268+
example: "A resource with the name could not be found."
269+
description: "The not found error message."
270+
description: "The not found error entity."
271+
ServerError:
272+
type: "object"
273+
properties:
274+
message:
275+
type: "string"
276+
example: "Something went wrong while processing your request. We're sorry\
277+
\ for the trouble. We've been notified of the error and will correct it\
278+
\ as soon as possible. Please try your request again in a moment."
279+
description: "The server error message."
280+
description: "The server error entity."
281+
BadRequest:
282+
type: "object"
283+
properties:
284+
message:
285+
type: "string"
286+
example: "Invalid input."
287+
description: "The bad request error message."
288+
description: "The bad request error entity."
289+
Forbidden:
290+
type: "object"
291+
properties:
292+
message:
293+
type: "string"
294+
example: "You are not allowed to access the request."
295+
description: "The forbidden error message."
296+
description: "The permission error entity."
297+
Conflict:
298+
type: "object"
299+
required:
300+
- "message"
301+
properties:
302+
message:
303+
type: "string"
304+
example: "Creating a resource with a name already exists."
305+
description: "The conflict error message."
306+
description: "The conflict error entity."
307+
body:
308+
type: "object"
309+
required:
310+
- "status"
311+
properties:
312+
status:
313+
type: "string"
314+
info:
315+
type: "string"

controllers/Templates.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
var utils = require('../utils/writer.js');
4+
var Templates = require('../service/TemplatesService');
5+
6+
module.exports.createTemplate = function createTemplate (req, res, next) {
7+
var template = req.swagger.params['template'].value;
8+
var name = req.swagger.params['name'].value;
9+
Templates.createTemplate(template,name)
10+
.then(function (response) {
11+
utils.writeJson(res, response);
12+
})
13+
.catch(function (response) {
14+
utils.writeJson(res, response);
15+
});
16+
};
17+
18+
module.exports.getTemplateById = function getTemplateById (req, res, next) {
19+
Templates.getTemplateById()
20+
.then(function (response) {
21+
utils.writeJson(res, response);
22+
})
23+
.catch(function (response) {
24+
utils.writeJson(res, response);
25+
});
26+
};

0 commit comments

Comments
 (0)