Skip to content

Commit d24eb67

Browse files
committed
contacts 작성페이지 제작
1 parent 70b10ee commit d24eb67

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ autoIncrement.initialize(connect);
2020

2121

2222
var admin = require('./routes/admin');
23+
//contacts
24+
var contacts = require('./routes/contacts');
2325

2426
var app = express();
2527
var port = 3000;
@@ -40,6 +42,7 @@ app.get('/', function (req, res) {//get방식으로 보내기
4042
});
4143

4244
app.use('/admin', admin);
45+
app.use('/contacts', contacts);
4346

4447
app.listen(port, function () { //서버에 띄어주는
4548
console.log('Express listening on port', port);

models/contactsModel.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var mongoose = require('mongoose');
2+
var Schema = mongoose.Schema;
3+
var autoIncrement = require('mongoose-auto-increment');
4+
5+
//생성될 필드명을 정한다.
6+
var ContactsSchema = new Schema({
7+
id: String, //id
8+
phoneNumber: Number, //연락처
9+
joined_at: Date //회원가입일
10+
});
11+
12+
//db로 보내기
13+
module.exports = mongoose.model('contacts',ContactsSchema);

routes/contacts.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var express = require('express');
2+
var contacts = require('./contacts');
3+
var router = express.Router();
4+
var ContactsModel = require('../models/ContactsModel');
5+
6+
router.get('/',function(req,res){
7+
res.send("contacts app router");
8+
});
9+
10+
//contacts/이후의 url을 적는다.
11+
router.get('/list',function(req,res){
12+
ContactsModel.find(function(err,contacts){
13+
res.render('contacts/',
14+
{contacts : contacts}
15+
);
16+
});
17+
});
18+
19+
router.get('/write',function(req,res){
20+
res.render('contacts/form',{contacts:""});
21+
});
22+
23+
router.post('/write',function(req,res){
24+
var contacts = new ContactsModel({
25+
id : req.body.id,
26+
phoneNumber : req.body.phoneNumber,
27+
joined_at : req.body.joined_at
28+
});
29+
contacts.save(function(err){
30+
res.redirect('/contacts');
31+
});
32+
});
33+
34+
module.exports = router;

views/contacts/form.ejs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<% include ../header.ejs %>
2+
<form action="" method="post">
3+
<table class="table table-bordered">
4+
<tr>
5+
<th>id</th>
6+
<td><input type="text" name="id" class="form-control" value="<%=contacts.id%>"/></td>
7+
</tr>
8+
<tr>
9+
<th>연락처</th>
10+
<td><input type="Number" name="phoneNumber" class="form-control" value="<%=contacts.phoneNumber%>"/></td>
11+
</tr>
12+
<tr>
13+
<th>가입일</th>
14+
<td><input type="text" name="joined_at" class="form-control" value="<%=contacts.joined_at%>"/></td>
15+
</tr>
16+
</table>
17+
<button class="btn btn-primary">작성하기</button>
18+
</form>
19+
20+
<% include ../footer.ejs %>

views/contacts/list.ejs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<% include ../header.ejs %>
2+
3+
<table class="table table-bordered table-hover">
4+
<tr>
5+
<th>id</th>
6+
<th>연락처</th>
7+
<th>가입일</th>
8+
</tr>
9+
<% products.forEach( function(product){ %>
10+
<tr>
11+
<td>
12+
아이디입니다.
13+
</td>
14+
<td>
15+
연락처입니다.
16+
</td>
17+
<td>
18+
가입일 입니다.
19+
</td>
20+
</tr>
21+
<% }); %>
22+
</table>
23+
24+
<a href="/contacts/write" class="btn btn-default">작성하기</a>
25+
26+
<% include ../footer.ejs %>

0 commit comments

Comments
 (0)