Skip to content

Commit 332205f

Browse files
authored
Merge pull request #1 from ncdcdev/method
Method
2 parents f06cb3e + d6e7cf0 commit 332205f

File tree

17 files changed

+2841
-1
lines changed

17 files changed

+2841
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
volumes
2+
13
# Logs
24
logs
35
*.log

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,24 @@ yarn
1515
起動
1616
```
1717
yarn start
18-
```
18+
```
19+
20+
2. method
21+
インストール
22+
```
23+
cd samples/method
24+
yarn
25+
```
26+
27+
DB起動
28+
```
29+
// samplesディレクトリに移動
30+
cd ../
31+
docker-compose up -d
32+
```
33+
34+
起動
35+
```
36+
cd samples/method
37+
yarn start
38+
```

samples/docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use root/example as user/password credentials
2+
version: '3.1'
3+
4+
services:
5+
6+
db:
7+
image: mysql
8+
command: --default-authentication-plugin=mysql_native_password
9+
restart: always
10+
ports:
11+
- 13306:3306
12+
volumes:
13+
- ./volumes/example_db/db/data:/var/lib/mysql
14+
- ./volumes/example_db/db/my.cnf:/etc/mysql/conf.d/my.cnf
15+
environment:
16+
MYSQL_DATABASE: example_db
17+
MYSQL_ROOT_PASSWORD: example
18+
MYSQL_USER: docker
19+
MYSQL_PASSWORD: docker
20+
21+
adminer:
22+
image: adminer
23+
restart: always
24+
ports:
25+
- 8080:8080

samples/hello-world/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import express from 'express'
2+
import "reflect-metadata"
23

34
const app: express.Express = express()
45

samples/method/.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: [
7+
'airbnb-base',
8+
'prettier',
9+
],
10+
parser: '@typescript-eslint/parser',
11+
parserOptions: {
12+
ecmaVersion: 'latest',
13+
sourceType: 'module',
14+
},
15+
plugins: [
16+
'@typescript-eslint',
17+
],
18+
rules: {
19+
},
20+
};

samples/method/.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
singleQuote: true,
3+
trailingComma: 'es5',
4+
printWidth: 100,
5+
semi: false,
6+
}

samples/method/data-source.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { DataSource } from "typeorm";
2+
3+
const AppDataSource = new DataSource({
4+
type: "mysql",
5+
host: "localhost",
6+
port: 13306,
7+
username: "docker",
8+
password: "docker",
9+
database: "example_db",
10+
synchronize: false,
11+
logging: true,
12+
entities: ["src/entities/**/*.ts"],
13+
migrations: ["src/migrations/**/*.ts"],
14+
})
15+
16+
export default AppDataSource
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
openapi: 3.0.0
2+
x-stoplight:
3+
id: 70he5bttrcegx
4+
info:
5+
title: tutorial-api
6+
version: '1.0'
7+
servers:
8+
- url: 'http://localhost:3000'
9+
paths:
10+
/contents:
11+
post:
12+
summary: Create New Content
13+
operationId: post-content
14+
responses:
15+
'200':
16+
description: Content Created
17+
content:
18+
application/json:
19+
schema:
20+
type: array
21+
items:
22+
$ref: '#/components/schemas/Content'
23+
examples: {}
24+
requestBody:
25+
content:
26+
application/json:
27+
schema:
28+
$ref: '#/components/schemas/PostContentRequest'
29+
examples: {}
30+
description: Post the necessary fields for the API to create a new content.
31+
description: Create a new content.
32+
parameters: []
33+
get:
34+
summary: Get Contents
35+
operationId: get-contents
36+
responses:
37+
'200':
38+
description: OK
39+
content:
40+
application/json:
41+
schema:
42+
type: array
43+
items:
44+
$ref: '#/components/schemas/Content'
45+
tags:
46+
- Content
47+
'/contents/{contentId}':
48+
parameters:
49+
- schema:
50+
type: string
51+
name: contentId
52+
in: path
53+
required: true
54+
get:
55+
summary: Get Content Info by Content ID
56+
tags:
57+
- Content
58+
responses:
59+
'200':
60+
description: Content Found
61+
content:
62+
application/json:
63+
schema:
64+
$ref: '#/components/schemas/Content'
65+
examples:
66+
Get Content Alice Smith:
67+
value:
68+
id: 142
69+
firstName: Alice
70+
lastName: Smith
71+
72+
dateOfBirth: '1997-10-31'
73+
emailVerified: true
74+
signUpDate: '2019-08-24'
75+
operationId: get-contents-contentId
76+
description: Retrieve the information of the content with the matching content ID.
77+
delete:
78+
summary: Delete a Content by Content ID
79+
operationId: delete-contents-contentsId
80+
responses:
81+
'204':
82+
description: No Content
83+
tags:
84+
- Content
85+
put:
86+
summary: Update a Content
87+
operationId: put-contents-contentsId
88+
responses:
89+
'200':
90+
description: OK
91+
content:
92+
application/json:
93+
schema:
94+
$ref: '#/components/schemas/Content'
95+
tags:
96+
- Content
97+
requestBody:
98+
content:
99+
application/json:
100+
schema:
101+
$ref: '#/components/schemas/PostContentRequest'
102+
description: 一部のパラメータのみの更新も可能とする
103+
components:
104+
schemas:
105+
Content:
106+
title: Content
107+
type: object
108+
description: ''
109+
x-examples:
110+
Alice Smith:
111+
id: 142
112+
firstName: Alice
113+
lastName: Smith
114+
115+
dateOfBirth: '1997-10-31'
116+
emailVerified: true
117+
signUpDate: '2019-08-24'
118+
properties:
119+
id:
120+
type: integer
121+
description: Unique identifier for the given content.
122+
title:
123+
type: string
124+
body:
125+
type: string
126+
createdAt:
127+
type: string
128+
format: date
129+
description: The date that the content was created.
130+
updatedAt:
131+
type: string
132+
required:
133+
- id
134+
- title
135+
- body
136+
PostContentRequest:
137+
title: PostContentRequest
138+
x-stoplight:
139+
id: uyyane08s9ozp
140+
type: object
141+
properties:
142+
title:
143+
type: string
144+
body:
145+
type: string
146+
requestBodies: {}

samples/method/nodemon.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"watch": [
3+
"src"
4+
],
5+
"ext": "ts",
6+
"exec": "ts-node -r tsconfig-paths/register ./src/index.ts"
7+
}

samples/method/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "hello-world",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"dev": "./node_modules/.bin/nodemon",
8+
"start": "ts-node src/index.ts",
9+
"lint": "eslint --fix './src/**/*.{js,jsx,ts,tsx}'",
10+
"format": "prettier --write ./src",
11+
"make:migration": "typeorm-ts-node-commonjs migration:generate ./src/migrations -d ./data-source.ts",
12+
"migrate": "typeorm-ts-node-commonjs migration:run -d ./data-source.ts",
13+
"rollback": "typeorm-ts-node-commonjs migration:revert -d ./data-source.ts"
14+
},
15+
"dependencies": {
16+
"@typescript-eslint/eslint-plugin": "^5.32.0",
17+
"@typescript-eslint/parser": "^5.32.0",
18+
"eslint": "^7.32.0 || ^8.2.0",
19+
"express": "^4.18.1",
20+
"nodemon": "^2.0.19",
21+
"reflect-metadata": "^0.1.13",
22+
"typeorm": "^0.3.7"
23+
},
24+
"devDependencies": {
25+
"@types/express": "^4.17.13",
26+
"@types/node": "^18.6.4",
27+
"eslint-config-airbnb-base": "^15.0.0",
28+
"eslint-config-prettier": "^8.5.0",
29+
"eslint-plugin-import": "^2.25.2",
30+
"prettier": "^2.7.1",
31+
"ts-node": "^10.9.1",
32+
"typescript": "^4.7.4"
33+
}
34+
}

0 commit comments

Comments
 (0)