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

Fix: some method changes

parent 21c5f223
No related branches found
No related tags found
No related merge requests found
import mongoose from 'mongoose'; import mongoose from 'mongoose';
import UserSchema from './User.js'; import UserSchema from '../user/user.js';
const CommentSchema = new mongoose.Schema({ const CommentSchema = new mongoose.Schema({
content: { content: {
......
...@@ -3,8 +3,8 @@ import multer from 'multer'; ...@@ -3,8 +3,8 @@ import multer from 'multer';
import path from 'path' import path from 'path'
import moment from 'moment' import moment from 'moment'
import userService from './data/userService.js'; import userService from '../user/userService.js';
import articleService from './data/articleService.js'; import articleService from './articleService.js';
...@@ -25,11 +25,12 @@ const upload = multer({ ...@@ -25,11 +25,12 @@ const upload = multer({
limits: { fileSize: 5 * 1024 * 1024 } // 5메가로 용량 제한 limits: { fileSize: 5 * 1024 * 1024 } // 5메가로 용량 제한
}); });
router.post("/upload", upload.array("img"), async function(req, res, next) { router.post("/", upload.array("img"), async function (req, res, next) {
if (!req.session.sessionid) { if (!req.session.sessionid) {
// 세션이 없엉 console.log("No session error");
return;
} }
console.log("포스팅 '해줘'"); console.log("POST /article");
const inputTitle = req.body.title const inputTitle = req.body.title
const inputContent = req.body.content const inputContent = req.body.content
...@@ -39,7 +40,6 @@ router.post("/upload", upload.array("img"), async function(req, res, next) { ...@@ -39,7 +40,6 @@ router.post("/upload", upload.array("img"), async function(req, res, next) {
const inputkeyword = req.body.keyword const inputkeyword = req.body.keyword
const inputlat = req.body.latitude const inputlat = req.body.latitude
const inputlng = req.body.longitude const inputlng = req.body.longitude
// const currentTime = moment().format('YYYY-MM-DD HH:mm')
await articleService.createArticle({ await articleService.createArticle({
title: inputTitle, title: inputTitle,
...@@ -55,17 +55,13 @@ router.post("/upload", upload.array("img"), async function(req, res, next) { ...@@ -55,17 +55,13 @@ router.post("/upload", upload.array("img"), async function(req, res, next) {
console.log('saved.') console.log('saved.')
res.send(); res.send();
res.send();
}); });
router.get("/loadarticle", async (req, res) => { router.get("/", async (req, res) => {
console.log(path.join(process.cwd(), '/public')) console.log(path.join(process.cwd(), '/public'))
if(req.session.sessionid){ if (!req.session.sessionid) {
console.log("세션 O") console.log("No session");
}
else {
console.log("세션 X")
} }
const articles = await articleService.findAllArticle(); const articles = await articleService.findAllArticle();
articles.forEach((article) => { articles.forEach((article) => {
...@@ -82,13 +78,9 @@ router.get("/loadarticle", async (req, res) => { ...@@ -82,13 +78,9 @@ router.get("/loadarticle", async (req, res) => {
res.send(JSON.stringify(articles)); res.send(JSON.stringify(articles));
}); });
router.get("/loadarticle/:id", async (req, res) => { router.get("/:id", async (req, res) => {
if (!req.session.sessionid) {
if(req.session.sessionid){ console.log("No session");
console.log("세션 O")
}
else {
console.log("세션 X")
} }
const articles = await articleService.findArticleById(req.params.id); const articles = await articleService.findArticleById(req.params.id);
res.send(JSON.stringify(articles)); res.send(JSON.stringify(articles));
......
import Article from '../models/article.js'; import Article from './article.js';
const articleService = { const articleService = {
async createArticle(articleData) { async createArticle(articleData) {
......
import express from 'express'; import express from 'express';
import moment from 'moment'; import moment from 'moment';
import userService from './data/userService.js'; import userService from '../user/userService.js';
export const router = express.Router(); export const router = express.Router();
...@@ -52,7 +52,7 @@ router.get("/logout", (req, res) => { ...@@ -52,7 +52,7 @@ router.get("/logout", (req, res) => {
} }
}); });
router.get("/check", (req, res) => { router.get("/session", (req, res) => {
if(req.session.sessionid){ if(req.session.sessionid){
res.send(true); res.send(true);
} }
......
...@@ -3,81 +3,6 @@ import mongoose from 'mongoose'; ...@@ -3,81 +3,6 @@ import mongoose from 'mongoose';
dotenv.config(); 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 connectDB = async () => {
const url = process.env.MONGODB_URI; const url = process.env.MONGODB_URI;
try { try {
......
...@@ -6,8 +6,8 @@ import cookieParser from 'cookie-parser'; ...@@ -6,8 +6,8 @@ import cookieParser from 'cookie-parser';
import session from 'express-session'; import session from 'express-session';
import auth from './auth.js'; import auth from './auth/authController.js';
import post from './post.js'; import article from './article/articleController.js';
import connectDB from './db.js'; import connectDB from './db.js';
...@@ -51,4 +51,4 @@ app.listen(PORT, () => { ...@@ -51,4 +51,4 @@ app.listen(PORT, () => {
app.use('/auth', auth); app.use('/auth', auth);
app.use('/post', post); app.use('/article', article);
\ No newline at end of file \ No newline at end of file
File moved
import User from '../models/User.js'; import User from './user.js';
const userService = { const userService = {
async createUser(userData) { async createUser(userData) {
......
...@@ -84,7 +84,7 @@ async function requestLogout() { ...@@ -84,7 +84,7 @@ async function requestLogout() {
async function requestCheckSession() { async function requestCheckSession() {
const response = await axios({ const response = await axios({
url: 'http://localhost:8080/auth/check', // 통신할 웹문서 url: 'http://localhost:8080/auth/session', // 통신할 웹문서
method: 'get', // 통신할 방식 method: 'get', // 통신할 방식
}); });
return response; return response;
......
...@@ -52,7 +52,7 @@ function Main() { ...@@ -52,7 +52,7 @@ function Main() {
async function requestLoadArticle() { async function requestLoadArticle() {
const response = await axios({ const response = await axios({
url: 'http://localhost:8080/post/loadarticle', // 통신할 웹문서 url: 'http://localhost:8080/article', // 통신할 웹문서
method: 'get', // 통신할 방식 method: 'get', // 통신할 방식
}); });
return response; return response;
......
...@@ -81,7 +81,7 @@ function PostRead() { ...@@ -81,7 +81,7 @@ function PostRead() {
async function requestLoadArticleById(id) { async function requestLoadArticleById(id) {
const response = await axios({ const response = await axios({
url: `http://localhost:8080/post/loadarticle/${id}`, // 통신할 웹문서 url: `http://localhost:8080/article/${id}`, // 통신할 웹문서
method: 'get', // 통신할 방식 method: 'get', // 통신할 방식
}); });
return response; return response;
......
...@@ -114,7 +114,7 @@ function PostWrite(){ ...@@ -114,7 +114,7 @@ function PostWrite(){
formData.append("latitude", location.center.lat); formData.append("latitude", location.center.lat);
formData.append("longitude", location.center.lng); formData.append("longitude", location.center.lng);
axios axios
.post("http://localhost:8080/post/upload", formData, .post("http://localhost:8080/article", formData,
{ {
headers: {"Content-Type": "multipart/form-data"} 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