Skip to content

Commit

Permalink
Merge pull request #144 from sparcs-kaist/feature/board
Browse files Browse the repository at this point in the history
Zabo boards 서비스 관련 API 작업
  • Loading branch information
withSang authored May 5, 2024
2 parents db6e744 + 9509403 commit 8568ef2
Show file tree
Hide file tree
Showing 24 changed files with 2,090 additions and 1,572 deletions.
16 changes: 16 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ services:
- DB_STR=zabo
volumes:
- zabo-scheduler-log:/backup_log:rw

# zabo-worker:
# container_name: zabo-worker
# restart: always
# build:
# context: ..
# dockerfile: .worker/Dockerfile
# environment:
# - NODE_ENV=${NODE_ENV:-production}
# - MINIMUM_LOG_LEVEL=info
# - MONGODB_URL=mongodb://zabo-mongo:27017/zabo
# - DB_STR=zabo
# volumes:
# - zabo-worker-log:/backup_log:rw

volumes:
zabo-server-log:
Expand All @@ -61,3 +75,5 @@ volumes:
external: true
zabo-scheduler-log:
external: true
# zabo-worker-log:
# external: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

.uuid
# dependencies
/node_modules

Expand Down
1 change: 1 addition & 0 deletions .uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a957a967-540e-49b2-b11a-17f32887ba0f
14 changes: 14 additions & 0 deletions .worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:16-alpine


RUN apk add --no-cache git

WORKDIR '/app'

COPY ./package.json ./
COPY ./yarn.lock ./
RUN yarn

COPY . .

CMD ["node", "worker.js"]
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/register": "^7.21.0",
"@tiptap/pm": "^2.3.1",
"adminjs": "^6.8.7",
"aws-sdk": "^2.485.0",
"axios": ">=0.18.1",
"bcrypt": "^5.1.1",
"chalk": "^2.4.2",
"connect-redis": "^3.4.1",
"cors": "^2.8.5",
Expand All @@ -56,7 +58,7 @@
"http-errors": "~1.6.2",
"ioredis": "^4.14.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.19",
"lodash": "^4.17.21",
"migrate-mongoose": "^4.0.0",
"moment": "^2.24.0",
"mongoose": "^5.7.5",
Expand Down Expand Up @@ -84,7 +86,7 @@
"figlet": "^1.2.4",
"husky": "^4.0.6",
"inquirer": "^7.0.3",
"lint-staged": "^9.5.0",
"lint-staged": "^15.1.0",
"nodemon": "^1.18.11",
"prettier": "^1.17.0"
},
Expand Down
42 changes: 42 additions & 0 deletions routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
* [`POST`](routes.md) /zabo/:zaboId/share
* [`DELETE`](routes.md) /zabo/:zaboId/

### Board
* [`POST`](routes.md) /board/device
* [`DELETE`](routes.md) /board/device
* [`POST`](routes.md) /board/login
* [`POST`](routes.md) /board/logout
* [`GET`](routes.md) /board/list


## Authentication

Following **Authorization** field must be set in HTTP request header
Expand Down Expand Up @@ -361,6 +369,40 @@ TODO: 그룹의 정보 \(사진\)을 업데이트할 수 있습니다. 이름도

400 : null id 500

### Board
#### `POST` /board/device { name, description, password } => deviceInfo
자보 보드를 게시할 디바이스를 생성합니다. Admin 패널에서 생성할 수 있습니다.
Admin 권한이 필요합니다. 기존의 디바이스들과 이름이 겹치면 생성되지 않습니다.

유효성 확인
* 관리자이여야 합니다.
* 기존의 디바이스와 겹치지 않는 디바이스 이름이여야 합니다.

#### `DELETE` /board/device { name } => { message }
자보 보드를 게시하는 디바이스를 삭제합니다. Admin 패널에서 삭제할 수 있습니다.

유효성 확인
* 관리자이여야 합니다.
* 유효한 디바이스 이름이여야 합니다.

#### `POST` /board/login { name, password } => { success, message }
자보 보드 디바이스에 로그인합니다. 세션 쿠키를 사용하여 인증합니다.

유효성 확인
* 올바른 디바이스 이름 및 비밀번호인지 확인합니다.

#### `POST` /board/logout => { message }
자보 보드 디바이스에서 로그아웃합니다.

유효성 확인
* 디바이스로 로그인되어있어야 합니다.

#### `GET` /board/list => zaboList
디바이스에서 자보 보드용 자보를 받아옵니다. 디바이스 로깅을 위해 /zabo/list와 분리해서 사용해야 합니다.

유효성 확인
* 디바이스로 로그인되어있어야 합니다.

## English

#### `GET` /auth \(\)`user`
Expand Down
6 changes: 6 additions & 0 deletions src/admin/actions/addDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Components } from "../components";

export const addDeviceAction = {
actionType: "resource",
component: Components.addDeviceComponent,
};
20 changes: 20 additions & 0 deletions src/admin/actions/deleteDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios from "axios";
export const deleteDeviceAction = {
actionType: "record",
component: false,
guard: "Do you really want to delete this device?",
handler: async (req, res, context) => {
const { record } = context;
const deviceName = record.params.name;
const response = await axios.delete("/api/board/device", {
name: deviceName,
});

response.data.message;

return {
record: {},
msg: "Deleting Device: Success",
};
},
};
51 changes: 51 additions & 0 deletions src/admin/components/addDevice.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, {useState} from 'react'
import { H3, Input, Button } from '@adminjs/design-system';
import axios from 'axios';

const addDevice = async (name, description, password) => {
const response = await axios.post('/api/board/device',
{
name,
description,
password
}
);
}

const addDeviceComponent = (props) => {
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [password, setPassword] = useState("");

const handleNameChange = (e) => {
setName(e.target.value);
}

const handleDescriptionChange = (e) => {
setDescription(e.target.value);
}

const handlePasswordChange = (e) => {
setPassword(e.target.value);
}

const handleDeviceSubmit = async() => {
await addDevice(name, description, password);
}

return (
<div>
<H3> Create your zabo boards device</H3>
<br/>
<Input type="text" onChange={handleNameChange} placeholder="name" />
<br/>
<Input type="text" onChange={handleDescriptionChange} placeholder="description" />
<br/>
<Input type="password" onChange={handlePasswordChange} placeholder="password" />
<br/>
<Button size="icon" rounded="True" onClick={handleDeviceSubmit}>Submit</Button>
</div>
)
}

export default addDeviceComponent
1 change: 1 addition & 0 deletions src/admin/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Components = {
"uploadZaboComponent",
"./uploadZabo",
),
addDeviceComponent: componentLoader.add("addDeviceComponent", "./addDevice"),
};

export { componentLoader, Components };
3 changes: 1 addition & 2 deletions src/admin/components/uploadZabo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const uploadZaboComponent = (props) => {
await sortedImageFiles.sort(gridLayoutCompareFunction);

const {width, height} = await imageFileGetWidthHeight(sortedImageFiles[0]);
const ratio = width / height;
let ratio = width / height;
if (ratio > 2) ratio = 2;
else if (ratio < 0.5) ratio = 0.5;
const sources = await Promise.all(sortedImageFiles.map((file) => cropImage(file, ratio)));
Expand All @@ -146,7 +146,6 @@ const uploadZaboComponent = (props) => {
},
});

return
}

return (
Expand Down
4 changes: 4 additions & 0 deletions src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
Statistic,
PreRegister,
Meta,
DeviceLog,
} from "../db";

import { GroupResource } from "./resources/Group";
import { ZaboResource } from "./resources/Zabo";
import { AdminUserResource } from "./resources/AdminUser";
import { DeviceResource } from "./resources/Device";

AdminJS.registerAdapter({
Resource: AdminJSMongoose.Resource,
Expand All @@ -34,7 +36,9 @@ const adminOptions = {
Statistic,
PreRegister,
Meta,
DeviceResource,
ZaboResource,
DeviceLog,
],
componentLoader,
};
Expand Down
11 changes: 11 additions & 0 deletions src/admin/resources/Device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Device } from "../../db/index";
import { addDeviceAction } from "../actions/addDevice";

export const DeviceResource = {
resource: Device,
options: {
actions: {
addDevice: addDeviceAction,
},
},
};
Loading

0 comments on commit 8568ef2

Please sign in to comment.