Skip to content
Snippets Groups Projects
Commit 0b61497a authored by YongJae's avatar YongJae
Browse files

Sell 기능-BookSearchPage에서 추가

parent 272dc6e5
No related branches found
No related tags found
1 merge request!16Sell 기능 (일부) 추가
......@@ -19,7 +19,9 @@ mongoose.Promise = global.Promise;
var mongoDB = "mongodb+srv://dragonash:team202@cluster0-sgfno.mongodb.net/test";
var promise = mongoose.connect(mongoDB, {
useMongoClient: true
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
});
//mongoose.connect(mongoDB);
......
var mongoose = require('mongoose');
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var autoInc = require("mongoose-auto-increment");
const BookSchema = mongoose.Schema({
title: {typr :String},
grade: { type: Number },
major: { type: String},
type: { type: String},
src: { type: String},
seller :[{
seller_id: { type: String},
on_transaction : {type: Boolean}
}],
stock: {type: Number}
const BookSchema = new Schema({
_id: { type: Number },
title: { type: String },
grade: { type: Number },
major: { type: String },
type: { type: String },
src: { type: String },
seller: [
{
seller_id: { type: String },
on_transaction: { type: Boolean }
}
],
stock: { type: Number }
});
BookSchema.statics.create = function(Book_info) {
const {
title,
grade,
major,
type,
src,
} = Book_info;
const {
title,
grade,
major,
type,
src,
stock,
seller: []
} = Book_info;
const Book = new this({
title,
grade,
major,
type,
src,
stock,
seller: []
});
// return the Promise
return Book.save();
};
const Book = new this({
title,
grade,
major,
type,
src,
})
// return the Promise
return Book.save()
}
autoInc.initialize(mongoose.connection);
BookSchema.plugin(autoInc.plugin, "Book");
module.exports = mongoose.model('Book', BookSchema);
\ No newline at end of file
module.exports = mongoose.model("Book", BookSchema);
var mongoose = require('mongoose');
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var autoInc = require("mongoose-auto-increment");
const TransactionSchema = mongoose.Schema({
buyerid : {type:String},
sellerid : {type:String},
ontransaction :{type:Boolean}
const TransactionSchema = new Schema({
_id: Number,
buyerid: { type: String },
sellerid: { type: String },
ontransaction: { type: Boolean }
});
autoInc.initialize(mongoose.connection);
TransactionSchema.plugin(autoInc.plugin, "transaction");
module.exports = mongoose.model('transaction', TransactionSchema);
\ No newline at end of file
module.exports = mongoose.model("transaction", TransactionSchema);
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var autoInc = require("mongoose-auto-increment");
var userSchema = new Schema({
_id: Number,
user: String,
name: String,
id: String,
......@@ -11,4 +13,7 @@ var userSchema = new Schema({
create_date: { type: Date, default: Date.now }
});
autoInc.initialize(mongoose.connection);
userSchema.plugin(autoInc.plugin, "user");
module.exports = mongoose.model("user", userSchema);
......@@ -14,9 +14,10 @@
"express-session": "^1.17.0",
"http-errors": "~1.6.3",
"mongoose": "^5.7.12",
"mongoose-auto-increment": "^5.0.1",
"morgan": "~1.9.1",
"nodemailer": "^6.4.0",
"pug": "2.0.0-beta11",
"session-file-store": "^1.3.1",
"nodemailer": "^6.4.0"
"session-file-store": "^1.3.1"
}
}
var express = require('express');
var express = require("express");
var router = express.Router();
var fs = require('fs');
var path = require('path');
var User = require('../models/user');
var Book = require('../models/Book');
var fs = require("fs");
var path = require("path");
var User = require("../models/user");
var Book = require("../models/Book");
router.get('/', function(req, res) {
console.log("Get start")
Book.find({}, function(err, Books){
if(err) res.json({result: false, message: "not found Books"})
res.json(Books);
})
// 책 목록 불러오기
router.get("/", function(req, res) {
console.log("Get start");
Book.find({}, function(err, Books) {
if (err) res.json({ result: false, message: "not found Books" });
res.json(Books);
});
});
// 특정 책 불러오기(id값으로 불러옴)
router.get("/:id", function(req, res) {
Book.findById(req.params.id, function(err, book) {
if (err) {
console.error(err);
return;
}
if (!book) {
res.json({ result: false, message: "Cannot find book" });
}
res.send(book);
});
});
router.post('/', function(req, res) {
console.log("Post start")
const Book_info = req.body;
// 책 추가
router.post("/", function(req, res) {
console.log("Post start");
const Book_info = req.body;
Book.create(Book_info)
Book.create(Book_info)
.then(result => {
if(result) res.json({result:true});
else res.json({result:false});
if (result) res.json({ result: true });
else res.json({ result: false });
})
.catch(function(error) {
console.log(error);
});
});
module.exports = router;
\ No newline at end of file
// 책 판매
router.post("/:id", function(req, res) {
Book.findById(req.params.id, function(err, book) {
if (err) {
console.error(err);
return;
}
console.log(req.body.userId);
book.seller.push({ seller_id: req.body.userId, on_transaction: false });
book.stock++;
book.save();
res.json({ result: true });
});
});
module.exports = router;
......@@ -43,7 +43,7 @@ router.get("/logout", function(req, res) {
if (err) {
console.log(err);
} else {
res.redirect("/"); // 수정해야 할 듯
res.redirect("/");
}
});
} else {
......@@ -59,4 +59,13 @@ router.get("/checkSession", function(req, res) {
}
});
router.get("/getUserId", function(req, res) {
console.log("getUserId start");
var sess = req.session;
console.log(sess.userid);
if (sess.userid) {
res.json(sess.userid);
}
});
module.exports = router;
......@@ -22,29 +22,34 @@
color="#999"
style="float: left; marginLeft: 1%; width: 2%; marginTop:0.1%"
v-on:click="Search"
>검색</md-button>
>검색</md-button
>
<!-- ==================================================================== -->
<div v-if="SearchResult === true">
<div v-for="Book in Books" :key="Book.id">
<div v-for="Book in Books" :key="Book._id">
<md-card
style="width: 50%; margin: 4px;marginTop:100px; display: inline-block; vertical-align: top;"
>
<md-card-header>
<md-card-header-text>
<div class="md-title">
{{Book.title}}
{{ Book.title }}
<br />
<br />
</div>
<div class="md-subhead" style="text-align:left;font-weight: bold;">
# 학년: {{Book.grade}}
<div
class="md-subhead"
style="text-align:left;font-weight: bold;"
>
# 학년: {{ Book.grade }}
<br />
# 전공: {{Book.major}}
# 전공: {{ Book.major }}
<br />
# 세부사항: {{Book.type}}
# 세부사항: {{ Book.type }}
<br />
# 매물: {{ Book.stock }}
<br />
# 매물: {{Book.stock}}
</div>
</md-card-header-text>
<md-card-media md-medium>
......@@ -52,7 +57,11 @@
</md-card-media>
</md-card-header>
<md-card-actions>
<md-button class="md-raised md-accent">Sell</md-button>
<md-button
class="md-raised md-accent"
v-on:click="goSellPage(Book._id)"
>Sell</md-button
>
<md-button class="md-raised md-primary">Buy Now</md-button>
</md-card-actions>
</md-card>
......@@ -60,15 +69,21 @@
</div>
<!-- ============================================= -->
<div>
<md-speed-dial :class="bottomPosition" style="marginRight:20%; marginBottom:8%">
<md-speed-dial
:class="bottomPosition"
style="marginRight:20%; marginBottom:8%"
>
<md-button class="md-fab md-primary" v-on:click="active = true">
<img src="../assets/icon-add.svg" />
</md-button>
</md-speed-dial>
</div>
<!-- =============서포터즈 submit 양식 ================== -->
<!-- ============= 판매도서 submit 양식 ================== -->
<div>
<md-dialog :md-active.sync="active" style="width : 500px; height: 1000px ">
<md-dialog
:md-active.sync="active"
style="width : 500px; height: 1000px "
>
<md-dialog-title>판매도서 등록</md-dialog-title>
<md-field class="select">
<label>책제목</label>
......@@ -87,7 +102,9 @@
<md-input v-model="submit.src"></md-input>
</md-field>
<md-dialog-actions>
<md-button class="md-primary" v-on:click="active = false">Close</md-button>
<md-button class="md-primary" v-on:click="active = false"
>Close</md-button
>
<md-button class="md-primary" v-on:click="Register">Submit</md-button>
</md-dialog-actions>
</md-dialog>
......@@ -96,98 +113,91 @@
</div>
</template>
<script>
import Vue from 'vue'
import VueMaterial from 'vue-material'
import Multiselect from 'vue-multiselect'
import 'vue-material/dist/vue-material.min.css'
import 'vue-material/dist/theme/default.css'
Vue.use(VueMaterial)
import Vue from "vue";
import VueMaterial from "vue-material";
import Multiselect from "vue-multiselect";
import "vue-material/dist/vue-material.min.css";
import "vue-material/dist/theme/default.css";
Vue.use(VueMaterial);
export default {
components: { Multiselect },
name: 'MaterialIcons',
data() {
return {
bottomPosition: 'md-bottom-right',
active : false,
SearchResult : false,
grade: null,
major: null,
type: null,
option1: ['1학년','2학년','3학년','4학년'],
option2: ['소프트웨어학과','미디어학과','경제학과'],
option3: ['전공 필수', '전공 선택', '교양선택','기초과목'],
Books : [
],
submit:{
title : "",
grade: "",
major : "",
src : "",
}
};
components: { Multiselect },
name: "MaterialIcons",
data() {
return {
bottomPosition: "md-bottom-right",
active: false,
SearchResult: false,
grade: null,
major: null,
type: null,
option1: ["1학년", "2학년", "3학년", "4학년"],
option2: ["소프트웨어학과", "미디어학과", "경제학과"],
option3: ["전공 필수", "전공 선택", "교양선택", "기초과목"],
Books: [],
submit: {
title: "",
grade: "",
major: "",
src: "",
stock: 0,
seller: []
}
};
},
created() {
this.$http.get("/api/books").then(response => {
this.Books = response.data;
console.log("Success");
console.log(this.Books);
});
},
methods: {
Search: function() {
if (this.grade !== null && this.major !== null && this.type !== null) {
this.SearchResult = true;
console.log(this.SearchResult);
} else {
alert("검색할 카테고리를 전부 입력해주세요");
}
},
created() {
this
.$http
.get('/api/books')
.then(response => {
this.Books = response.data;
console.log("Success")
console.log(this.Books)
})
},
methods:{
Search: function(){
if(this.grade !== null && this.major !== null && this.type !== null)
{
this.SearchResult = true;
console.log(this.SearchResult);
}
else
{
alert("검색할 카테고리를 전부 입력해주세요")
}
},
Register(){
this.$http
.post("/api/books", this.submit)
.then(res => {
console.log("Sumit Success");
})
.catch(err => {
console.log("Submit failed");
});
this.active = false;
Register() {
this.$http
.post("/api/books", this.submit)
.then(res => {
console.log("Submit Success");
})
.catch(err => {
console.log("Submit failed");
});
this.active = false;
},
goSellPage(bookId) {
this.$router.push({ name: "BookSearchPageSell", params: { id: bookId } });
}
}
}
};
</script>
<style lang='css'>
html,body {
text-align: center;
margin:0;
width:100%;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
justify-content: center;
<style lang="css">
html,
body {
text-align: center;
margin: 0;
width: 100%;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
justify-content: center;
}
.search {
margin-Bottom: 0.5%;
margin-bottom: 0.5%;
}
.select {
text-align: center;
margin-Top: 2%;
margin: 15px;
text-align: center;
margin-top: 2%;
}
.button{
margin-top: 70px;
.button {
margin-top: 70px;
}
</style>
<style src="vue-multiselect/dist/vue-multiselect.min.css">
</style>
\ No newline at end of file
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
<template>
<div>
<md-card
style="width: 50%; margin: 4px; marginTop:100px; display: inline-block; vertical-align: top;"
>
<md-card-header>
<md-card-header-text>
<div class="md-title">
{{ book.title }}
<br />
<br />
</div>
<div class="md-subhead" style="text-align:left; font-weight:bold;">
# 학년: {{ book.grade }}
<br />
# 전공: {{ book.major }}
<br />
# 세부사항: {{ book.type }}
<br />
# 매물: {{ book.stock }}
<br />
</div>
</md-card-header-text>
<md-card-media md-medium>
<img v-bind:src="book.src" />
</md-card-media>
</md-card-header>
</md-card>
<md-card
style="width: 50%; margin: 4px; marginTop:100px; display: inline-block; vertical-align: top;"
>
<md-card-header>
<div class="md-title">
이 책을 판매하시겠습니까?
</div>
</md-card-header>
<md-card-actions>
<md-button class="md-raised md-primary" v-on:click="sellBook"
>판매</md-button
>
</md-card-actions>
</md-card>
</div>
</template>
<script>
import Vue from "vue";
import VueMaterial from "vue-material";
import Multiselect from "vue-multiselect";
import "vue-material/dist/vue-material.min.css";
import "vue-material/dist/theme/default.css";
Vue.use(VueMaterial);
export default {
data() {
return {
book: {},
userId: ""
};
},
created() {
var id = this.$route.params.id;
this.$http.get(`/api/books/${id}`).then(response => {
this.book = response.data;
});
// this.$http.get("/api/login/getUserId").then(response => {
// console.log("getUserIDstart");
// this.userId = response.data;
// });
},
methods: {
getId() {
this.$http.get("/api/login/getUserId").then(response => {
console.log("rd" + response.data);
this.userId = response.data;
});
},
sellBook() {
var id = this.$route.params.id;
this.getId();
console.log("user:" + this.userId);
this.$http
.post(`/api/books/${id}`, {
userId: this.userId
})
.then(
response => {
alert("판매 대기열에 등록하였습니다.");
//this.$router.push("home");
},
error => {
alert(error.response.data.error);
}
)
.catch(error => {
alert(error);
});
}
}
};
</script>
<template>
<div id="login">
<md-button class="md-primary" v-on:click="active = true">Login</md-button>
<md-dialog :md-active.sync="active" style="width: 500px; height: 1000px">
<md-dialog :md-active.sync="active" style="width: 500px; height: 500px">
<md-dialog-title>Login</md-dialog-title>
<md-field class="select">
<label>ID</label>
......@@ -47,7 +47,6 @@ export default {
response => {
//로그인 성공
alert("success login");
//this.$router.push("Logout");
this.active = false;
location.reload();
},
......
......@@ -33,7 +33,7 @@
</div>
</template>
<style>
<style scoped>
.select {
margin: 15px;
display: inline-flex;
......
......@@ -8,6 +8,8 @@ import BookSearchPage from "@/components/BookSearchPage";
import Login from "@/components/login/Login";
import Logout from "@/components/login/Logout";
import SignUp from "@/components/login/SignUp";
import Buy from "@/components/Buy";
import Sell from "@/components/Sell";
export default new Router({
mode: "history",
......@@ -47,6 +49,26 @@ export default new Router({
path: "/signUp",
name: "SignUp",
component: SignUp
},
{
path: "/BookSearchPage/buy/:id",
name: "BookSearchPageBuy",
component: Buy
},
{
path: "/home/buy/:id",
name: "HomeBuy",
component: Buy
},
{
path: "/BookSearchPage/sell/:id",
name: "BookSearchPageSell",
component: Sell
},
{
path: "/home/sell/:id",
name: "HomeSell",
component: Sell
}
]
});
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