최은석
......@@ -20,4 +20,103 @@
* 카카오톡의 반응 기능이나 인스타의 좋아요 처럼 게시물에 이모티콘을 사용자가 표시하는 기능
```한 사용자가 여러번 남기는 것을 막아야 해서 로그인 기능 고려 필요```
* 게시물 작성을 유도하기 위해 포인트 적립을 통해 랭킹 기능 고려
* 작성된 글을 보기 쉽도록 게시글을 검색하는 기능
\ No newline at end of file
* 작성된 글을 보기 쉽도록 게시글을 검색하는 기능
## BACK
### /api/getList
#### GET호출
> response
> ```
> ["게시물 id1", "게시물 id2", "게시물 id3"]
>```
>> 오늘 게시물들의 아이디 표시
-------------
### /api/getList/:date
#### GET호출
> response
> ```
> ["게시물 id1", "게시물 id2", "게시물 id3"]
>```
>> 특정 날자의 게시물들의 아이디 표시
-------------
### /api/get
#### GET호출
> request(body)
> ```
> {
> "idArray": ["게시물 id1", "게시물 id2", "게시물 id3"]
> }
> ```
> response
> ```
> [
> {
> "id": "게시물 id1",
> "title": "제목1",
> "content": "내용1"
> },
> {
> "id": "게시물 id2",
> "title": "제목2",
> "content": "내용2"
> },
> {
> "id": "게시물 id3",
> "title": "제목3",
> "content": "이 것은 긴 내용이..."
> }
> ]
> ```
>> 특정 id(여러개)의 게시물 내용 요약 불러오기
-------------
### /api/get/:id
#### GET호출
> response
> ```
> {
> "title": "제목",
> "content": "내용"
> }
>```
>> 특정 id의 게시물 불러오기
-------------
### /api/isPassEqual
#### POST호출
> request(body)
> ```
> {
> "id":"게시물 id",
> "password":"사용자가 입력한 암호"
> }
> ```
> response
> ```
> success
> ```
> or
> ```
> failed
> ```
>
>> 암호가 같으면 success, 아니면 failed
-------------
### /api/postSave
#### POST호출
> request(body)
> ```
> {
> "title":"제목",
> "content":"게시물 내용",
> "password":"암호"
> }
> ```
>> 오늘 게시물 작성
>>> response 수정예정
>>>>>>> ea6cadae0f258eb9d8abc6e597913cf5bda4b9fd
......
......@@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
......
This diff is collapsed. Click to expand it.
{
"scripts": {
"server": "cd server && nodemon server",
"client": "cd client && npm start",
"client": "cd client && npm start --port",
"start": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\""
},
"dependencies": {
"axios": "^0.27.2",
"body-parser": "^1.20.0",
"concurrently": "^7.2.1",
"express": "^4.18.1",
"http-proxy-middleware": "^2.0.6",
"mongoose": "^6.3.4",
"nodemon": "^2.0.16"
}
}
......
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose')
mongoose.connect('mongodb+srv://choieunseok:uA3mhjPcB3DwsuuD@cluster0.2gsua4u.mongodb.net/?retryWrites=true&w=majority');
const db = mongoose.connection
db.on('error', console.error)
db.once('open', () => {
console.log('Connected to mongodb Server')
});
const dayPostList = mongoose.Schema({
date: 'string',
idArray: [{ type: String }]
});
const dayPostListModel = mongoose.model('dayPostList', dayPostList);
const post = mongoose.Schema({
date: 'string',
title: 'string',
content: 'string',
password: 'string'
});
const postModel = mongoose.model('post', post);
// router.get('/api', (req, res) => {
// res.send({ test: "hi" });
// });
function getCurrentDate(originDate) {
var date;
if(originDate == null) date = new Date();
else date = new Date(originDate);
var year = date.getFullYear().toString();
var month = date.getMonth() + 1;
month = month < 10 ? '0' + month.toString() : month.toString();
var day = date.getDate();
day = day < 10 ? '0' + day.toString() : day.toString();
return year + '-'+ month + '-'+ day ;
}
router.get('/api/getList', async(req, res) => {
const today = getCurrentDate();
var testDayPostList = await dayPostListModel.findOne({ date: today });
if (testDayPostList == null) testDayPostList = new dayPostListModel({ date: today, idArray: [] });
res.send(testDayPostList.idArray);
});
router.get('/api/getList/:date', async(req, res) => {
const today = getCurrentDate(req.params.date);
var testDayPostList = await dayPostListModel.findOne({ date: today });
if (testDayPostList == null) testDayPostList = new dayPostListModel({ date: today, idArray: [] });
res.send(testDayPostList.idArray);
});
router.get('/api/get', async(req, res) => {
const idArray = req.body.idArray;
var resultArray = [];
for (const id of idArray){
const onePost = await postModel.findById(id);
var tempJSON = {};
tempJSON.id = onePost.id;
tempJSON.title = onePost.title;
tempJSON.content = onePost.content;
tempJSON.content = tempJSON.content.replace(/(?:\r\n|\r|\n)/g, '');
const sliceLength = 10;
if(tempJSON.content.length > sliceLength) tempJSON.content = tempJSON.content.slice(0,sliceLength) + "...";
resultArray.push(tempJSON);
}
res.send(resultArray);
});
router.get('/api/get/:id', async(req, res) => {
const currentPost = await postModel.findById(req.params.id);
res.send({ title: currentPost.title, content: currentPost.content });
});
router.post('/api/isPassEqual', async(req, res) => {
const currentPost = await postModel.findById(req.body.id);
if (currentPost.password == req.body.password) res.send("success");
else res.send("failed");
});
router.post('/api/postSave', async (req, res) => {
var isFirst = false;
const today = getCurrentDate();
var testDayPostList = await dayPostListModel.findOne({ date: today });
if (testDayPostList == null) {
testDayPostList = new dayPostListModel({ date: today, idArray: [] });
isFirst = true;
}
var postListArr = testDayPostList.idArray;
var newPost = new postModel({ date: today, title: req.body.title, content: req.body.content, password: req.body.password });
var newPostData = await newPost.save();
postListArr.push(newPostData._id.toString());
if (isFirst) await testDayPostList.save();
else await dayPostListModel.updateOne({ date: today }, { idArray: postListArr });
res.send(newPostData);
});
// 게시물 저장에 성공 실패 메시지만 표시, 게시물 수정, 삭제 추가예정 ---------------------------------------------------------------------------------------------------------------------------------------
// router.get('/api/testSave', async (req, res) => {
// var isFirst = false;
// var testDayPostList = await dayPostListModel.findOne({ date: '2022-05-30' });
// if (testDayPostList == null) {
// testDayPostList = new dayPostListModel({ date: '2022-05-30', idArray: [] });
// isFirst = true;
// }
// var postListArr = testDayPostList.idArray;
// var newPost = new postModel({ date: '2022-05-30', title: '테스트 제목', content: '테스트 내용', password: 'password' });
// var newPostData = await newPost.save();
// postListArr.push(newPostData._id.toString());
// if (isFirst) await testDayPostList.save();
// else await dayPostListModel.updateOne({ date: '2022-05-30' }, { idArray: postListArr });
// res.send("test");
// });
module.exports = router;
const express = require('express');
const router = express.Router();
router.get('/api', (req, res)=>{
res.send({ test: "hi"});
});
module.exports = router;
\ No newline at end of file
const express = require('express');
const app = express();
const test = require('.//Router/test');
const api = require('./Router/api');
let bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/', test);
app.use('/', api);
const port=23023;
app.listen(port, ()=>{console.log(`Listening on port ${port}`)});
\ No newline at end of file
const port = 23023;
app.listen(port, () => { console.log(`Listening on port ${port}`) });
\ No newline at end of file
......