김재형

Implement dummy file api

import { createServer, Model } from "miragejs";
import { createServer, Model, Response } from "miragejs";
import { ModelDefinition } from "miragejs/-types";
interface Item {
......@@ -51,10 +51,16 @@ createServer({
this.get("/items/:item_id/children", (schema, request) => {
const directory = schema.find("item", request.params.item_id);
if (!directory || !directory.is_folder) {
return {
return new Response(
404,
{
"Content-Type": "application/json",
},
JSON.stringify({
status: 404,
message: "Not Found",
};
})
);
}
const list = schema.where("item", { parent: directory.id }).models;
......@@ -68,9 +74,116 @@ createServer({
};
});
this.post("/items/:item_id/children", (schema, request) => {
return {
status: 200,
data: {
id: "2341",
is_folder: true,
name: "cloudComputing",
created_timestamp: "2020-05-14T06:20:44Z",
updated_timestamp: "2020-05-14T06:20:44Z",
size: 0,
},
};
});
this.post("/items/:item_id/upload", (schema, request) => {
return {
status: 200,
data: {
id: "2342",
name: "image.jpg",
is_folder: false,
size: 92929,
path:
"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",
},
};
});
this.post("/items/:item_id/status", (schema, request) => {
return {
status: 200,
message: "ok",
};
});
this.post("/items/:item_id/move", (schema, request) => {
return {
status: 200,
data: {
id: "2342",
name: "image.jpg",
is_folder: false,
parentinfo: {
id: "1234",
name: "folder",
is_folder: true,
updated_timestamp: "2020-05-14T06:20:44Z",
},
},
};
});
this.post("/items/:item_id/copy", (schema, request) => {
return {
status: 200,
data: {
id: "2342",
name: "image.jpg",
is_folder: false,
parentinfo: {
id: "1234",
name: "folder",
is_folder: true,
updated_timestamp: "2020-05-14T06:20:44Z",
},
},
};
});
this.get("/items/:item_id", (schema, request) => {
return {
status: 200,
data: {
id: "2342",
name: "image.jpg",
is_folder: false,
size: 92929,
path:
"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",
created_timestamp: "2020-05-14T06:20:44Z",
updated_timestamp: "2020-05-14T06:20:44Z",
},
};
});
this.delete("/items/:item_id", (schema, request) => {
return {
status: 200,
message: "ok",
};
});
this.post("/users/login", (schema, request) => {
const body = JSON.parse(request.requestBody);
if (body.user_id === "admin" && body.password === "password") {
const admin = schema.findBy("user", {
user_id: body.user_id,
password: body.password,
});
if (!admin) {
return new Response(
401,
{
"Content-Type": "application/json",
},
JSON.stringify({
status: 401,
message: "unauthorized",
})
);
}
return {
status: 200,
data: {
......@@ -81,18 +194,13 @@ createServer({
expiration: "2020-05-14T07:23:24Z",
},
};
}
return {
status: 401,
message: "unauthorized",
};
});
},
seeds(server) {
const user = server.create("user", {
id: "1",
user_id: "test",
user_id: "admin",
name: "테스트",
password: "password",
total_size: 1024 * 1024 * 1024 * 5, // 5GB
......