Skip to content
Snippets Groups Projects
Commit 2c0709d0 authored by Gwangbin's avatar Gwangbin
Browse files

Fix: some method changes

parent 21c5f223
Branches
No related tags found
No related merge requests found
import mongoose from 'mongoose';
import UserSchema from './User.js';
import UserSchema from '../user/user.js';
const CommentSchema = new mongoose.Schema({
content: {
......
......@@ -3,8 +3,8 @@ import multer from 'multer';
import path from 'path'
import moment from 'moment'
import userService from './data/userService.js';
import articleService from './data/articleService.js';
import userService from '../user/userService.js';
import articleService from './articleService.js';
......@@ -13,68 +13,64 @@ const __dirname = path.resolve();
export const router = express.Router();
const upload = multer({
storage: multer.diskStorage({ // 저장한공간 정보 : 하드디스크에 저장
destination(req, file, done) { // 저장 위치
done(null, 'public/uploads/'); // uploads라는 폴더 안에 저장
},
filename(req, file, done) { // 파일명을 어떤 이름으로 올릴지
const ext = path.extname(file.originalname); // 파일의 확장자
done(null, path.basename(file.originalname, ext) + Date.now() + ext); // 파일이름 + 날짜 + 확장자 이름으로 저장
}
}),
limits: { fileSize: 5 * 1024 * 1024 } // 5메가로 용량 제한
});
storage: multer.diskStorage({ // 저장한공간 정보 : 하드디스크에 저장
destination(req, file, done) { // 저장 위치
done(null, 'public/uploads/'); // uploads라는 폴더 안에 저장
},
filename(req, file, done) { // 파일명을 어떤 이름으로 올릴지
const ext = path.extname(file.originalname); // 파일의 확장자
done(null, path.basename(file.originalname, ext) + Date.now() + ext); // 파일이름 + 날짜 + 확장자 이름으로 저장
}
}),
limits: { fileSize: 5 * 1024 * 1024 } // 5메가로 용량 제한
});
router.post("/upload", upload.array("img"), async function(req, res, next) {
if(!req.session.sessionid){
// 세션이 없엉
}
console.log("포스팅 '해줘'");
router.post("/", upload.array("img"), async function (req, res, next) {
if (!req.session.sessionid) {
console.log("No session error");
return;
}
console.log("POST /article");
const inputTitle = req.body.title
const inputContent = req.body.content
const inputImage = req.files.map(el => el.path);
const useremail = req.session.sessionid.email
const author = await userService.findUserByEmail(useremail);
const useremail = req.session.sessionid.email
const author = await userService.findUserByEmail(useremail);
const inputkeyword = req.body.keyword
const inputlat = req.body.latitude
const inputlng = req.body.longitude
// const currentTime = moment().format('YYYY-MM-DD HH:mm')
await articleService.createArticle({
title: inputTitle,
content: inputContent,
imageUrls: inputImage,
author: author,
title: inputTitle,
content: inputContent,
imageUrls: inputImage,
author: author,
keyword: inputkeyword,
latitude: inputlat,
longitude: inputlng,
comments: [],
likes: [],
});
console.log('saved.')
res.send();
res.send();
comments: [],
likes: [],
});
console.log('saved.')
res.send();
});
router.get("/loadarticle", async (req, res) => {
router.get("/", async (req, res) => {
console.log(path.join(process.cwd(), '/public'))
if(req.session.sessionid){
console.log("세션 O")
}
else {
console.log("세션 X")
if (!req.session.sessionid) {
console.log("No session");
}
const articles = await articleService.findAllArticle();
articles.forEach((article) => {
article.imageUrls.forEach(
(urls) => {
try{
try {
//res.sendFile(path.join(__dirname, urls));
}
catch(err){
catch (err) {
console.log(err)
}
});
......@@ -82,13 +78,9 @@ router.get("/loadarticle", async (req, res) => {
res.send(JSON.stringify(articles));
});
router.get("/loadarticle/:id", async (req, res) => {
if(req.session.sessionid){
console.log("세션 O")
}
else {
console.log("세션 X")
router.get("/:id", async (req, res) => {
if (!req.session.sessionid) {
console.log("No session");
}
const articles = await articleService.findArticleById(req.params.id);
res.send(JSON.stringify(articles));
......
import Article from '../models/article.js';
import Article from './article.js';
const articleService = {
async createArticle(articleData) {
......
import express from 'express';
import moment from 'moment';
import userService from './data/userService.js';
import userService from '../user/userService.js';
export const router = express.Router();
......@@ -52,7 +52,7 @@ router.get("/logout", (req, res) => {
}
});
router.get("/check", (req, res) => {
router.get("/session", (req, res) => {
if(req.session.sessionid){
res.send(true);
}
......
......@@ -3,81 +3,6 @@ import mongoose from 'mongoose';
dotenv.config();
// const GoogleProviderSchema = new mongoose.Schema({
// id: {
// type: String,
// required: true,
// //unique: true,
// },
// profileUrl: {
// type: String,
// },
// });
// const UserSchema = new mongoose.Schema({
// nickname: {
// type: String,
// },
// email: {
// type: String,
// //unique: true,
// },
// google: {
// type: GoogleProviderSchema,
// }
// });
// const UserModel = mongoose.model("User", UserSchema);
// const CommentSchema = new mongoose.Schema({
// content: {
// type: String,
// required: true,
// },
// author: {
// type: UserSchema,
// required: true,
// },
// createdAt: {
// type: Date,
// default: Date.now,
// },
// });
// CommentSchema.index( { commentId: 1 } , { sparse: true } )
// const ArticleSchema = new mongoose.Schema({
// title: {
// type: String,
// required: true,
// },
// content: {
// type: String,
// required: true,
// },
// imageUrls: {
// type: [String],
// },
// author: {
// type: UserSchema,
// required: true,
// },
// comments: {
// type: [CommentSchema],
// unique: false,
// },
// likes: {
// type: [UserSchema],
// },
// createdAt: {
// type: Date,
// default: Date.now,
// },
// });
// ArticleSchema.index({articleId:1}, { sparse: true })
// const ArticleModel = mongoose.model("Article", ArticleSchema);
const connectDB = async () => {
const url = process.env.MONGODB_URI;
try {
......
......@@ -6,8 +6,8 @@ import cookieParser from 'cookie-parser';
import session from 'express-session';
import auth from './auth.js';
import post from './post.js';
import auth from './auth/authController.js';
import article from './article/articleController.js';
import connectDB from './db.js';
......@@ -51,4 +51,4 @@ app.listen(PORT, () => {
app.use('/auth', auth);
app.use('/post', post);
\ No newline at end of file
app.use('/article', article);
\ No newline at end of file
File moved
import User from '../models/User.js';
import User from './user.js';
const userService = {
async createUser(userData) {
......
......@@ -84,7 +84,7 @@ async function requestLogout() {
async function requestCheckSession() {
const response = await axios({
url: 'http://localhost:8080/auth/check', // 통신할 웹문서
url: 'http://localhost:8080/auth/session', // 통신할 웹문서
method: 'get', // 통신할 방식
});
return response;
......
......@@ -52,7 +52,7 @@ function Main() {
async function requestLoadArticle() {
const response = await axios({
url: 'http://localhost:8080/post/loadarticle', // 통신할 웹문서
url: 'http://localhost:8080/article', // 통신할 웹문서
method: 'get', // 통신할 방식
});
return response;
......
......@@ -81,7 +81,7 @@ function PostRead() {
async function requestLoadArticleById(id) {
const response = await axios({
url: `http://localhost:8080/post/loadarticle/${id}`, // 통신할 웹문서
url: `http://localhost:8080/article/${id}`, // 통신할 웹문서
method: 'get', // 통신할 방식
});
return response;
......
......@@ -114,7 +114,7 @@ function PostWrite(){
formData.append("latitude", location.center.lat);
formData.append("longitude", location.center.lng);
axios
.post("http://localhost:8080/post/upload", formData,
.post("http://localhost:8080/article", formData,
{
headers: {"Content-Type": "multipart/form-data"}
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment