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({
ref: 'User',
}],
createdAt: {
type: Date,
type: String,
default: Date.now,
},
......
import express from 'express';
import multer from 'multer';
import path from 'path'
import moment from 'moment'
import userService from './data/userService.js';
import articleService from './data/articleService.js';
const __dirname = path.resolve();
export const router = express.Router();
......@@ -28,7 +31,6 @@ router.post("/upload", upload.array("img"), async function(req, res, next) {
}
console.log("포스팅 '해줘'");
const inputTitle = req.body.title
const inputContent = req.body.content
const inputImage = req.files.map(el => el.path);
......@@ -37,6 +39,7 @@ router.post("/upload", upload.array("img"), async function(req, res, next) {
const inputkeyword = req.body.keyword
const inputlat = req.body.latitude
const inputlng = req.body.longitude
const currentTime = moment().format('YYYY-MM-DD HH:mm:ss')
await articleService.createArticle({
title: inputTitle,
......@@ -47,7 +50,8 @@ router.post("/upload", upload.array("img"), async function(req, res, next) {
latitude: inputlat,
longitude: inputlng,
comments: [],
likes: []
likes: [],
createdAt: currentTime
});
console.log('saved.')
......@@ -74,23 +78,9 @@ router.get("/loadarticle", async (req, res) => {
catch(err){
console.log(err)
}
});
});
const retval = {
}
// console.log(articles)
console.log(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;
import React, {useEffect, useState} from "react";
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 = []
listItem = prop.images.map((el)=>{
listItem = images.map((el)=>{
// http://localhost:8080/uploads/21701487062905.png
return(
<img
......@@ -15,14 +20,17 @@ function Article(prop) {
style={{ width: "100px", height: "100px"}}/>
)});
console.log(typeof createdAt)
return (
<div>
<h1>{prop.title}</h1>
<h2>{prop.author}</h2>
<p>{prop.content}</p>
<h1>{title}</h1>
<h2>{keyword}</h2>
<h3>{author.nickname} {createdAt}</h3>
<p>{content}</p>
<p>{listItem}</p>
{/* 게시글의 내용을 렌더링합니다. */}
<p>댓글: {comments.length} // 조와요: {likes.length}</p>
</div>
);
}
......
......@@ -18,19 +18,14 @@ function Button({history, children}){
}
function Main() {
const userContext = useContext(UserContext);
const [articleList, setArticleList] = useState([])
let listItem = [];
listItem = articleList.map((article)=>{
return(
<Article
title={article.title}
author = {article.author.nickname}
content={article.content}
images={article.imageUrls}
data={Object.values(article)}
></Article>
)
}
)
......@@ -54,7 +49,6 @@ function Main() {
;
}
async function requestLoadArticle() {
const response = await axios({
url: 'http://localhost:8080/post/loadarticle', // 통신할 웹문서
......@@ -64,25 +58,3 @@ async function requestLoadArticle() {
}
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 React, { useState, useEffect, useContext } from 'react';
import {Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom';
import SearchMap from '../components/SearchMapByKeyword.js'
import { UserContext } from '../Context.js';
const {kakao} = window;
//카카오 지도 API를 이용한 검색(예정)
/*
function SearchMap(props){
// 아주대학교를 기본 위치로 설정
const [state, setState] = useState({
......@@ -34,23 +34,10 @@ function SearchMap(props){
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) {
......@@ -59,6 +46,12 @@ function Search(props) {
function MoveTo(link){
navigate(link)
}
const [location, setLocation] = useState({
keyword: "",
center: { lat: null, lng: null }
});
useEffect(() => {
const session = userContext.CheckSession()
.then((response) => {
......@@ -76,7 +69,7 @@ function Search(props) {
return (
<div className="search">
<h1>검색페이지입니다.</h1>
<SearchMap/>
<SearchMap loc={location} setLoc={setLocation}></SearchMap>
</div>
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment