Skip to content

bookmaru/MARU-SERVER_API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 

Repository files navigation

MARU SERVER

๋‰ด๋…ธ๋ฉ€ ์‹œ๋Œ€์— ์–ธ์ œ, ์–ด๋””์„œ๋‚˜ ์ธ๋ฌธํ•™์  ์†Œ์–‘์„ ๊ธฐ๋ฅผ ์ˆ˜ ์žˆ๊ณ  ์ง„์†”ํ•œ ์†Œํ†ต์„ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„, ๋งˆ๋ฃจ์ž…๋‹ˆ๋‹ค.

MARU๋Š” ๋Œ€ํ•™์ƒ ์—ฐํ•ฉ IT ๋ฒค์ฒ˜์ฐฝ์—… ๋™์•„๋ฆฌ SOPT ๋‚ด์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ ํ”„๋กœ์ ํŠธ๋ฅผ ํ•จ๊ป˜ํ•œ ๋ฉค๋ฒ„๋“ค๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

ํŒ€ ๋‹จ์œ„์˜ ํ˜‘์—…์„ ๊ฐ™์ด ๊ฒฝํ—˜ํ•˜๊ณ  ๋‹ค์–‘ํ•œ ๊ด€์ ๋“ค์„ ๊ณต์œ ํ•œ ์ €ํฌ๋Š” โ€œ๋งˆ๋ฃจโ€๋ฅผ ๊ฐœ๋ฐœํ•˜๋ฉด์„œ ๋‹ค์‹œ ํ•œ ๋ฒˆ ํŒ€ ๋‹จ์œ„์˜ ์—ญ๋Ÿ‰์„ ๋ฐฐ์–‘ํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.



๐Ÿ˜Š About MARU

API Specification

Project Period : 2020.08~2020.09

Member : ์ •ํšจ์›, ์ตœ์ •๊ท , ์†์˜ˆ์ง€


๐Ÿ’ฅ Main Function

์†Œ์ผ“ํ†ต์‹ ์„ ์ด์šฉํ•œ ํ† ๋ก  - ์ •ํšจ์›

// 'connection' ์ด๋ฒคํŠธ ๋ฐœ์ƒ
io.on('connection', (socket) => {

  // ํด๋ผ์ด์–ธํŠธ ์ ‘์† ๋Š์„ ์‹œ on('disconnect') ๋ฐœ์ƒ
  socket.on('disconnect', () => {
    console.log('user disconnected');
  });
  // room ๋‚˜๊ฐ€๊ธฐ : socket.leave
  socket.on('leaveRoom', (roomIdx, name) => {
    socket.leave(room[roomIdx], () => {
      io.to(room[roomIdx]).emit('leaveRoom', roomIdx, name);
    });
  });
  // ํ† ๋ก ์—์„œ ๋ฒ—์–ด๋‚œ ์‹œ๊ฐ„ ์ฒดํฌ
  socket.on('leave', (name, roomIdx) => {
    var date=new Date();
    let disconnectTime = moment(date).format('YYYY-MM-DD HH:mm:ss');

    //๋””๋น„ ํ†ต์‹  ๋ถ€๋ถ„
  });

  // ํŠน์ • room ์—๊ฒŒ ์ด๋ฒคํŠธ ๋ณด๋‚ผ ์‹œ : io.to('room์ด๋ฆ„').emit()
    socket.on('joinRoom', (roomIdx, name) => {
    socket.join(room[roomIdx], () => {
      room.push('room'+roomIdx);
      io.to(room[roomIdx]).emit('joinRoom', roomIdx,name);
    });
  });

//ํด๋ผ : socket.emit('chat message') , ์„œ๋ฒ„ : socket.on('chat message') ๋งค๊ฐœ๋ณ€์ˆ˜ : name, msg, roomIdx
  socket.on('chat message', (name, msg, roomIdx) => {
    a=roomIdx;
    var date = new Date(); 
    let chatTime = moment(date).format('YYYY-MM-DD HH:mm:ss');

    //๋””๋น„ ํ†ต์‹  ๋ถ€๋ถ„
    io.to(room[a]).emit('chat message', name, msg);
  });
  });
});

KAKAO API๋ฅผ ์ด์šฉํ•œ ์ฑ… ๊ฒ€์ƒ‰ - ์ตœ์ •๊ท 

const options = {
 kakaoTest: async(title) => {
   return {
     url: `https://dapi.kakao.com/v3/search/book?target=title`,
     method: 'GET',
     headers: {
       'Authorization': '',
     },
     qs: {
       query : title,
     },
     encoding: 'UTF-8',
   }
 }
}
module.exports = options;
request(kakao, function (err, response, body) {
if (!err && response.statusCode == 200) {
 const book = JSON.parse(body).documents;
 
 // ๊ฒ€์ƒ‰ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์„ ๋•Œ
 if (book.length === 0) {
   res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, resMessage.NO_SEARCH));
   return;
 }

 // ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์กด์žฌํ•  ๋•Œ
 bookList = [];
 
 for (let item of book) {
   bookList.push({
     authors : item.authors[0],
     title : item.title,
     thumbnail : item.thumbnail
   })
 }

 res.status(statusCode.OK).send(util.success(statusCode.OK, resMessage.SUCCESS_SEARCH, bookList))
}

Firebase๋ฅผ ์ด์šฉํ•œ ์•Œ๋ฆผ ๊ตฌํ˜„ - ์†์˜ˆ์ง€

try {
    const deviceTokens = await alarmModel.getDeviceToken(roomIdx, nickName);
    const registrationTokens = []; //๋””๋ฐ”์ด์Šค ๋“ฑ๋ก

    for (let i = 0; i < deviceTokens.length; ++i) {
        if (deviceTokens[i].deviceToken == null) {
            res.status(statusCode.DB_ERROR).send(util.fail(statusCode.DB_ERROR, resMessage.INTERNAL_SERVER_ERROR));
            return;
        }
        registrationTokens.push(deviceTokens[i].deviceToken);
    }

    if (!admin.apps.length) {
        admin.initializeApp({
            credential: admin.credential.cert(firebaseConfig),
            databaseURL: ""
        });
    }
    var options = {
        priority: 'high',
        timeToLive: 60 * 60 * 24 * 2
    };

    //payload
    var payload = {
        notification: {
            title: title,
            body: nickName + " : " + message,
        },
    };

๐Ÿ’ป package.json

"dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "dotenv": "^8.2.0",
    "ejs": "^3.1.5",
    "express": "~4.16.1",
    "fcm-node": "^1.5.2",
    "firebase-admin": "^9.2.0",
    "http-errors": "^1.6.3",
    "jsonwebtoken": "^8.5.1",
    "moment": "^2.27.0",
    "moment-timezone": "^0.5.31",
    "morgan": "~1.9.1",
    "nodemon": "^2.0.4",
    "pbkdf2": "^3.1.1",
    "promise-mysql": "^4.1.3",
    "rand-token": "^1.0.1",
    "request": "^2.88.2",
    "serve-favicon": "^2.5.0",
    "socket.io": "^2.3.0"
  }

๐ŸŒŸ RULE

  • Coding Convention
  • Git Convention

๐Ÿ’ฌ Code Convention

โ—naming

1. **๋ณ€์ˆ˜๋ช…, ํŒŒ์ผ๋ช…** : ์นด๋ฉœ์ผ€์ด์Šค  (`inputBox`)
2. **ํด๋”๋ช…** : ์†Œ๋ฌธ์ž (`inputbox`)
3. **ํด๋ž˜์Šค๋ช…** : ์ฒซ๊ธ€์ž ๋Œ€๋ฌธ์ž (`InputBox`)
  • var ๋ณด๋‹ค๋Š” let, const ์ง€ํ–ฅ
  • ๋น„๋™๊ธฐ
    • promise์˜ then๋ณด๋‹ค๋Š” async/await ์‚ฌ์šฉ

๐Ÿ‘‰ Git Convention

branch

  • master
    • develop
    • feature_jg
    • feature_yz
    • feature_hw

Commit Message

CREATE - ๊ธฐ๋Šฅ ๊ตฌํ˜„
UPDATE - ์ฝ”๋“œ ์ˆ˜์ •
MERGE - ์ฝ”๋“œ ๋ณ‘ํ•ฉ
FIX - ๋ฒ„๊ทธ ์ˆ˜์ •
RELEASE - ๋ฒ„์ „ ๋ฐฐํฌ
DELETE - ๊ธฐ๋Šฅ ์‚ญ์ œ
DOCS - ๋ฌธ์„œ ํŽธ์ง‘

About

๐Ÿ“šBOOK-MARU๐Ÿ“š

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published