Skip to content
Snippets Groups Projects
Commit 04a6ac30 authored by Hyun Woo Jeong's avatar Hyun Woo Jeong
Browse files

more info on articles

parent 3a55bdde
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ const ArticleSchema = new mongoose.Schema({ ...@@ -55,7 +55,7 @@ const ArticleSchema = new mongoose.Schema({
ref: 'User', ref: 'User',
}], }],
createdAt: { createdAt: {
type: Date, type: String,
default: Date.now, default: Date.now,
}, },
......
import express from 'express'; import express from 'express';
import multer from 'multer'; import multer from 'multer';
import path from 'path' import path from 'path'
import moment from 'moment'
import userService from './data/userService.js'; import userService from './data/userService.js';
import articleService from './data/articleService.js'; import articleService from './data/articleService.js';
const __dirname = path.resolve(); const __dirname = path.resolve();
export const router = express.Router(); export const router = express.Router();
...@@ -28,7 +31,6 @@ router.post("/upload", upload.array("img"), async function(req, res, next) { ...@@ -28,7 +31,6 @@ router.post("/upload", upload.array("img"), async function(req, res, next) {
} }
console.log("포스팅 '해줘'"); console.log("포스팅 '해줘'");
const inputTitle = req.body.title const inputTitle = req.body.title
const inputContent = req.body.content const inputContent = req.body.content
const inputImage = req.files.map(el => el.path); const inputImage = req.files.map(el => el.path);
...@@ -37,6 +39,7 @@ router.post("/upload", upload.array("img"), async function(req, res, next) { ...@@ -37,6 +39,7 @@ 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:ss')
await articleService.createArticle({ await articleService.createArticle({
title: inputTitle, title: inputTitle,
...@@ -47,7 +50,8 @@ router.post("/upload", upload.array("img"), async function(req, res, next) { ...@@ -47,7 +50,8 @@ router.post("/upload", upload.array("img"), async function(req, res, next) {
latitude: inputlat, latitude: inputlat,
longitude: inputlng, longitude: inputlng,
comments: [], comments: [],
likes: [] likes: [],
createdAt: currentTime
}); });
console.log('saved.') console.log('saved.')
...@@ -74,23 +78,9 @@ router.get("/loadarticle", async (req, res) => { ...@@ -74,23 +78,9 @@ router.get("/loadarticle", async (req, res) => {
catch(err){ catch(err){
console.log(err) console.log(err)
} }
}); });
}); });
const retval = {
}
// console.log(articles)
console.log(articles)
res.send(JSON.stringify(articles) ); res.send(JSON.stringify(articles) );
}); });
/*
router.get('/preview', async (req, res, next)=>{
const imgUrl = "http://localhost:3000/images/"
result = imgUrl+"저장된 이미지명" //imgUrl+"kitty.png"
res.send(result);
}
출처: https://avengersrhydon1121.tistory.com/234 [익명의 개발노트:티스토리]
*/
export default router; export default router;
import React, {useEffect, useState} from "react"; import React, {useEffect, useState} from "react";
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
function Article(prop) { function Article({data}) {
const [
_id, title, content, images, author,
keyword, latitude, longitude,
comments, likes, createdAt] = data;
console.log(prop)
let listItem = [] let listItem = []
listItem = prop.images.map((el)=>{ listItem = images.map((el)=>{
// http://localhost:8080/uploads/21701487062905.png // http://localhost:8080/uploads/21701487062905.png
return( return(
<img <img
...@@ -15,14 +20,17 @@ function Article(prop) { ...@@ -15,14 +20,17 @@ function Article(prop) {
style={{ width: "100px", height: "100px"}}/> style={{ width: "100px", height: "100px"}}/>
)}); )});
console.log(typeof createdAt)
return ( return (
<div> <div>
<h1>{prop.title}</h1> <h1>{title}</h1>
<h2>{prop.author}</h2>
<p>{prop.content}</p> <h2>{keyword}</h2>
<h3>{author.nickname} {createdAt}</h3>
<p>{content}</p>
<p>{listItem}</p> <p>{listItem}</p>
{/* 게시글의 내용을 렌더링합니다. */} <p>댓글: {comments.length} // 조와요: {likes.length}</p>
</div> </div>
); );
} }
......
...@@ -18,19 +18,14 @@ function Button({history, children}){ ...@@ -18,19 +18,14 @@ function Button({history, children}){
} }
function Main() { function Main() {
const userContext = useContext(UserContext); const userContext = useContext(UserContext);
const [articleList, setArticleList] = useState([]) const [articleList, setArticleList] = useState([])
let listItem = []; let listItem = [];
listItem = articleList.map((article)=>{ listItem = articleList.map((article)=>{
return( return(
<Article <Article
title={article.title} data={Object.values(article)}
author = {article.author.nickname}
content={article.content}
images={article.imageUrls}
></Article> ></Article>
) )
} }
) )
...@@ -54,7 +49,6 @@ function Main() { ...@@ -54,7 +49,6 @@ 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/post/loadarticle', // 통신할 웹문서
...@@ -64,25 +58,3 @@ async function requestLoadArticle() { ...@@ -64,25 +58,3 @@ async function requestLoadArticle() {
} }
export default Main; export default Main;
/*
{
_id: new ObjectId('65675ee46aab64d2ed605e3c'),
title: 'ㅋ',
content: 'ㅋㅋ',
imageUrls: [],
author: {
_id: new ObjectId('6566403f224df4126bfb3e50'),
user_id: 'grasscraft0714@gmail.com',
nickname: 'ᄅᄅᄒ',
email: 'grasscraft0714@gmail.com',
google: [Object],
__v: 0
},
comments: [],
likes: [],
createdAt: 2023-11-29T15:55:16.525Z,
__v: 0
}
*/
import { Map, MapMarker } from "react-kakao-maps-sdk"; import { Map, MapMarker } from "react-kakao-maps-sdk";
import React, { useState, useEffect, useContext } from 'react'; import React, { useState, useEffect, useContext } from 'react';
import {Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom'; import {Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom';
import SearchMap from '../components/SearchMapByKeyword.js'
import { UserContext } from '../Context.js'; import { UserContext } from '../Context.js';
const {kakao} = window; const {kakao} = window;
//카카오 지도 API를 이용한 검색(예정) //카카오 지도 API를 이용한 검색(예정)
/*
function SearchMap(props){ function SearchMap(props){
// 아주대학교를 기본 위치로 설정 // 아주대학교를 기본 위치로 설정
const [state, setState] = useState({ const [state, setState] = useState({
...@@ -34,23 +34,10 @@ function SearchMap(props){ ...@@ -34,23 +34,10 @@ function SearchMap(props){
geocoder.addressSearch(`${searchAddress}`, callback); geocoder.addressSearch(`${searchAddress}`, callback);
} }
return (
<div className="UserInput">
<input onChange={handleInput}/>
<button onClick={SearchStart}>검색!</button>
<Map // 지도를 표시할 Container
center={state.center}
isPanto={state.isPanto}
style={{
// 지도의 크기
width: "100%",
height: "450px",
}}
level={3}>
</Map>
</div>
)
} }
*/
function Search(props) { function Search(props) {
...@@ -59,6 +46,12 @@ function Search(props) { ...@@ -59,6 +46,12 @@ function Search(props) {
function MoveTo(link){ function MoveTo(link){
navigate(link) navigate(link)
} }
const [location, setLocation] = useState({
keyword: "",
center: { lat: null, lng: null }
});
useEffect(() => { useEffect(() => {
const session = userContext.CheckSession() const session = userContext.CheckSession()
.then((response) => { .then((response) => {
...@@ -76,7 +69,7 @@ function Search(props) { ...@@ -76,7 +69,7 @@ function Search(props) {
return ( return (
<div className="search"> <div className="search">
<h1>검색페이지입니다.</h1> <h1>검색페이지입니다.</h1>
<SearchMap/> <SearchMap loc={location} setLoc={setLocation}></SearchMap>
</div> </div>
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment