Skip to content

Commit

Permalink
Merge pull request #189 from boostcamp-2020/dev
Browse files Browse the repository at this point in the history
5주차 코드 프리징
  • Loading branch information
rockpell committed Dec 17, 2020
2 parents 2aa3fce + b13ba39 commit aafc5bd
Show file tree
Hide file tree
Showing 204 changed files with 2,888 additions and 1,743 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: deploy

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: master

jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- name: Deploy backend server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.BACKEND_HOST }}
username: ${{ secrets.BACKEND_USERNAME }}
password: ${{ secrets.BACKEND_PASSWORD }}
script: |
bash deploy-backend.sh
- name: Deploy frontend server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.FRONTEND_HOST }}
username: ${{ secrets.FRONTEND_USERNAME }}
password: ${{ secrets.FRONTEND_PASSWORD }}
script: |
bash deploy-frontend.sh
34 changes: 30 additions & 4 deletions backend/chatServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { config as dotenv } from 'dotenv'
import express from 'express'
import { createServer } from 'http'
import createChatServer from 'socket.io'
import { createChatMessage } from './service/chat'
import { createChatMessage, createReplyMessage } from './service/chat'
import { addReaction, removeReaction } from './service/reaction'
dotenv()

Expand All @@ -28,18 +28,43 @@ namespace.on('connection', socket => {
)
})
socket.on('new message', async data => {
const { contents, channelId } = data
const { contents, channelId, file } = data
const { data: result } = await createChatMessage({
creator: workspaceUserInfoId,
channelId,
contents,
file,
})
namespace.in(channelId).emit('new message', {
message: { ...data, _id: result._id, createdAt: result.createdAt },
message: {
...data,
_id: result._id,
createdAt: result.createdAt,
reactions: [],
},
})
})
socket.on('new reply', async data => {
const { contents, channelId, parentId, file } = data
const { data: result } = await createReplyMessage({
creator: workspaceUserInfoId,
channelId,
contents,
parentId,
file,
})
namespace.in(channelId).emit('new reply', {
message: {
...data,
_id: result._id,
createdAt: result.createdAt,
chatId: parentId,
reactions: [],
},
})
})
socket.on('update reaction', async data => {
const { emoji, chatId, userInfo, channelId, type } = data
const { emoji, chatId, userInfo, channelId, type, parentId } = data
//1 = add, 0 = remove
const result =
type === 1
Expand All @@ -61,6 +86,7 @@ namespace.on('connection', socket => {
workspaceUserInfoId: userInfo._id,
displayName: userInfo.displayName,
type: result ? type : false,
parentId: parentId,
},
})
})
Expand Down
34 changes: 34 additions & 0 deletions backend/controller/channel/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const getChannelList = asyncWrapper(async (req, res) => {
return res.status(code).json({ success, result })
})

const getChannelBrowserData = asyncWrapper(async (req, res) => {
const { workspaceUserInfoId, workspaceId } = req.query
const { code, success, result } = await service.getChannelBrowserData({
workspaceUserInfoId,
workspaceId,
})
return res.status(code).json({ success, result })
})

const getChannelHeaderInfo = asyncWrapper(async (req, res) => {
const channelId = req.params.channelId
const workspaceUserInfoId = req.query.workspaceUserInfoId
Expand Down Expand Up @@ -57,6 +66,20 @@ const createChannel = asyncWrapper(async (req, res) => {
return res.status(code).json({ success, data })
})

const leaveChannel = asyncWrapper(async (req, res) => {
const { code, success } = await service.leaveChannel({
...req.body,
})
return res.status(code).json({ success })
})

const joinChannel = asyncWrapper(async (req, res) => {
const { code, success } = await service.joinChannel({
...req.body,
})
return res.status(code).json({ success })
})

const checkDuplicate = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.checkDuplicate({
title: req.query.title,
Expand All @@ -65,12 +88,23 @@ const checkDuplicate = asyncWrapper(async (req, res) => {
return res.status(code).json({ success, data })
})

const findChannelIdByName = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.findChannelIdByName({
...req.query,
})
return res.status(code).json({ success, data })
})

module.exports = {
getChannelList,
getChannelBrowserData,
getChannelHeaderInfo,
inviteUser,
muteChannel,
updateChannelSection,
createChannel,
checkDuplicate,
leaveChannel,
joinChannel,
findChannelIdByName,
}
9 changes: 9 additions & 0 deletions backend/controller/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ const { Auth } = require('../../middleware/auth')
/* GET /api/channle get channel list */
router.get('/', controller.getChannelList)

/* get /api/channle/browser update channel section */
router.get('/browser', controller.getChannelBrowserData)

router.get('/check-duplicate-name', controller.checkDuplicate)

router.post('/', Auth, controller.createChannel)

router.post('/leave', Auth, controller.leaveChannel)

router.post('/join', Auth, controller.joinChannel)

/* GET /api/channle/{channelId}/info get channel header info */
router.get('/:channelId/info', controller.getChannelHeaderInfo)

router.get('/info', controller.findChannelIdByName)

/* POST /api/channle/invite invite user to channel */
router.post('/invite', controller.inviteUser)

Expand Down
7 changes: 0 additions & 7 deletions backend/controller/file/file.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { asyncWrapper } from '../../util'
import service from '../../service/file'

exports.getFileURL = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.getFileURL({
...req.query,
})
return res.status(code).json({ success, data })
})

exports.uploadFile = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.uploadFile({
file: req.file,
Expand Down
1 change: 0 additions & 1 deletion backend/controller/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const multer = require('multer')
const storage = multer.memoryStorage()
const uploader = multer({ storage: storage })

router.get('/', Auth, controller.getFileURL)
router.post('/', Auth, uploader.single('file'), controller.uploadFile)
router.delete('/', Auth, controller.deleteFile)

Expand Down
5 changes: 3 additions & 2 deletions backend/controller/workspace/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import express from 'express'
const { Auth } = require('../../middleware/auth')
const { Auth, InviteAuth } = require('../../middleware/auth')
const router = express.Router()
const controller = require('./workspace')

router.get('/', Auth, controller.getWorkspaces)
router.post('/', Auth, controller.createWorkspace)
router.post('/invite', Auth, controller.invite)
router.get('/invite/:code', Auth, controller.invited)
router.get('/invite/:code', InviteAuth, controller.invited)
router.get('/check-duplicate-name', Auth, controller.checkDuplicateName)
router.get('/info/:workspaceId', Auth, controller.getWorkspaceUserInfo)
router.get('/info', Auth, controller.getWorkspaceUserInfoByInfoId)

module.exports = router
15 changes: 11 additions & 4 deletions backend/controller/workspace/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ exports.invite = (req, res) => {
}

exports.invited = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.invited({
const { success, data } = await service.invited({
...req.params,
userId: req.user.id,
})
const workspaceRedirectURL = `${process.env.FRONTEND_HOST}/workspace/${data.workspaceId}/${data.default_channel}`
if (success) {
return res.status(code).redirect(workspaceRedirectURL)
const workspaceRedirectURL = `${process.env.FRONTEND_HOST}/workspace/${data.workspaceId}/${data.default_channel}`
return res.redirect(workspaceRedirectURL)
}
return res.status(code).redirect(process.env.FRONTEND_HOST)
return res.redirect(process.env.FRONTEND_HOST)
})

exports.checkDuplicateName = asyncWrapper(async (req, res) => {
Expand All @@ -50,3 +50,10 @@ exports.getWorkspaceUserInfo = asyncWrapper(async (req, res) => {
})
return res.status(code).json({ success, data })
})

exports.getWorkspaceUserInfoByInfoId = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.getWorkspaceUserInfoByInfoId({
...req.query,
})
return res.status(code).json({ success, data })
})
Loading

0 comments on commit aafc5bd

Please sign in to comment.