Showing
1 changed file
with
126 additions
and
18 deletions
1 | -import { createServer, Model } from "miragejs"; | 1 | +import { createServer, Model, Response } from "miragejs"; |
2 | import { ModelDefinition } from "miragejs/-types"; | 2 | import { ModelDefinition } from "miragejs/-types"; |
3 | 3 | ||
4 | interface Item { | 4 | interface Item { |
... | @@ -51,10 +51,16 @@ createServer({ | ... | @@ -51,10 +51,16 @@ createServer({ |
51 | this.get("/items/:item_id/children", (schema, request) => { | 51 | this.get("/items/:item_id/children", (schema, request) => { |
52 | const directory = schema.find("item", request.params.item_id); | 52 | const directory = schema.find("item", request.params.item_id); |
53 | if (!directory || !directory.is_folder) { | 53 | if (!directory || !directory.is_folder) { |
54 | - return { | 54 | + return new Response( |
55 | - status: 404, | 55 | + 404, |
56 | - message: "Not Found", | 56 | + { |
57 | - }; | 57 | + "Content-Type": "application/json", |
58 | + }, | ||
59 | + JSON.stringify({ | ||
60 | + status: 404, | ||
61 | + message: "Not Found", | ||
62 | + }) | ||
63 | + ); | ||
58 | } | 64 | } |
59 | 65 | ||
60 | const list = schema.where("item", { parent: directory.id }).models; | 66 | const list = schema.where("item", { parent: directory.id }).models; |
... | @@ -68,23 +74,125 @@ createServer({ | ... | @@ -68,23 +74,125 @@ createServer({ |
68 | }; | 74 | }; |
69 | }); | 75 | }); |
70 | 76 | ||
77 | + this.post("/items/:item_id/children", (schema, request) => { | ||
78 | + return { | ||
79 | + status: 200, | ||
80 | + data: { | ||
81 | + id: "2341", | ||
82 | + is_folder: true, | ||
83 | + name: "cloudComputing", | ||
84 | + created_timestamp: "2020-05-14T06:20:44Z", | ||
85 | + updated_timestamp: "2020-05-14T06:20:44Z", | ||
86 | + size: 0, | ||
87 | + }, | ||
88 | + }; | ||
89 | + }); | ||
90 | + | ||
91 | + this.post("/items/:item_id/upload", (schema, request) => { | ||
92 | + return { | ||
93 | + status: 200, | ||
94 | + data: { | ||
95 | + id: "2342", | ||
96 | + name: "image.jpg", | ||
97 | + is_folder: false, | ||
98 | + size: 92929, | ||
99 | + path: | ||
100 | + "https://presignedurldemo.s3.eu-west-2.amazonaws.com/image.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJJWZ7B6WCRGMKFGQ%2F20180210%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20180210T171315Z&X-Amz-Expires=1800&X-Amz-Signature=12b74b0788aa036bc7c3d03b3f20c61f1f91cc9ad8873e3314255dc479a25351&X-Amz-SignedHeaders=host", | ||
101 | + }, | ||
102 | + }; | ||
103 | + }); | ||
104 | + | ||
105 | + this.post("/items/:item_id/status", (schema, request) => { | ||
106 | + return { | ||
107 | + status: 200, | ||
108 | + message: "ok", | ||
109 | + }; | ||
110 | + }); | ||
111 | + | ||
112 | + this.post("/items/:item_id/move", (schema, request) => { | ||
113 | + return { | ||
114 | + status: 200, | ||
115 | + data: { | ||
116 | + id: "2342", | ||
117 | + name: "image.jpg", | ||
118 | + is_folder: false, | ||
119 | + parentinfo: { | ||
120 | + id: "1234", | ||
121 | + name: "folder", | ||
122 | + is_folder: true, | ||
123 | + updated_timestamp: "2020-05-14T06:20:44Z", | ||
124 | + }, | ||
125 | + }, | ||
126 | + }; | ||
127 | + }); | ||
128 | + | ||
129 | + this.post("/items/:item_id/copy", (schema, request) => { | ||
130 | + return { | ||
131 | + status: 200, | ||
132 | + data: { | ||
133 | + id: "2342", | ||
134 | + name: "image.jpg", | ||
135 | + is_folder: false, | ||
136 | + parentinfo: { | ||
137 | + id: "1234", | ||
138 | + name: "folder", | ||
139 | + is_folder: true, | ||
140 | + updated_timestamp: "2020-05-14T06:20:44Z", | ||
141 | + }, | ||
142 | + }, | ||
143 | + }; | ||
144 | + }); | ||
145 | + | ||
146 | + this.get("/items/:item_id", (schema, request) => { | ||
147 | + return { | ||
148 | + status: 200, | ||
149 | + data: { | ||
150 | + id: "2342", | ||
151 | + name: "image.jpg", | ||
152 | + is_folder: false, | ||
153 | + size: 92929, | ||
154 | + path: | ||
155 | + "https://presignedurldemo.s3.eu-west-2.amazonaws.com/image.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJJWZ7B6WCRGMKFGQ%2F20180210%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20180210T171315Z&X-Amz-Expires=1800&X-Amz-Signature=12b74b0788aa036bc7c3d03b3f20c61f1f91cc9ad8873e3314255dc479a25351&X-Amz-SignedHeaders=host", | ||
156 | + created_timestamp: "2020-05-14T06:20:44Z", | ||
157 | + updated_timestamp: "2020-05-14T06:20:44Z", | ||
158 | + }, | ||
159 | + }; | ||
160 | + }); | ||
161 | + | ||
162 | + this.delete("/items/:item_id", (schema, request) => { | ||
163 | + return { | ||
164 | + status: 200, | ||
165 | + message: "ok", | ||
166 | + }; | ||
167 | + }); | ||
168 | + | ||
71 | this.post("/users/login", (schema, request) => { | 169 | this.post("/users/login", (schema, request) => { |
72 | const body = JSON.parse(request.requestBody); | 170 | const body = JSON.parse(request.requestBody); |
73 | - if (body.user_id === "admin" && body.password === "password") { | 171 | + const admin = schema.findBy("user", { |
74 | - return { | 172 | + user_id: body.user_id, |
75 | - status: 200, | 173 | + password: body.password, |
76 | - data: { | 174 | + }); |
77 | - access_token: | 175 | + if (!admin) { |
78 | - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", | 176 | + return new Response( |
79 | - refresh_token: | 177 | + 401, |
80 | - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", | 178 | + { |
81 | - expiration: "2020-05-14T07:23:24Z", | 179 | + "Content-Type": "application/json", |
82 | }, | 180 | }, |
83 | - }; | 181 | + JSON.stringify({ |
182 | + status: 401, | ||
183 | + message: "unauthorized", | ||
184 | + }) | ||
185 | + ); | ||
84 | } | 186 | } |
85 | return { | 187 | return { |
86 | - status: 401, | 188 | + status: 200, |
87 | - message: "unauthorized", | 189 | + data: { |
190 | + access_token: | ||
191 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", | ||
192 | + refresh_token: | ||
193 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", | ||
194 | + expiration: "2020-05-14T07:23:24Z", | ||
195 | + }, | ||
88 | }; | 196 | }; |
89 | }); | 197 | }); |
90 | }, | 198 | }, |
... | @@ -92,7 +200,7 @@ createServer({ | ... | @@ -92,7 +200,7 @@ createServer({ |
92 | seeds(server) { | 200 | seeds(server) { |
93 | const user = server.create("user", { | 201 | const user = server.create("user", { |
94 | id: "1", | 202 | id: "1", |
95 | - user_id: "test", | 203 | + user_id: "admin", |
96 | name: "테스트", | 204 | name: "테스트", |
97 | password: "password", | 205 | password: "password", |
98 | total_size: 1024 * 1024 * 1024 * 5, // 5GB | 206 | total_size: 1024 * 1024 * 1024 * 5, // 5GB | ... | ... |
-
Please register or login to post a comment