Skip to content

Commit

Permalink
Added bid create method, played around with css and added an image to…
Browse files Browse the repository at this point in the history
… img folder
  • Loading branch information
DSRoden committed Aug 31, 2014
1 parent d6224bd commit d4fecdb
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 33 deletions.
10 changes: 10 additions & 0 deletions app/controllers/bids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

var Bid = require('../models/bid');

exports.create = function(req, res){
req.body.upForBidOwnerId = res.locals.user._id;
Bid.create(req.body, req.params.itemOfferedId, function(){
res.redirect('/marketplace');
});
};
15 changes: 14 additions & 1 deletion app/models/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
var Mongo = require('mongodb'),
async = require('async');

function Bid(){
function Bid(o){
this.itemUpForBidId = o.itemUpForBidId;
this.itemOfferedId = o.itemOfferedId;
this.upForBidOwnerId = o.upForBidOwnerId;
this.offerOwnerId = o.offerOwnerId;
this.isOpen = true;
}

Object.defineProperty(Bid, 'collection', {
get: function(){return global.mongodb.collection('bids');}
});

Bid.create = function(data,itemOfferedId, cb){
var offeredItemId = Mongo.ObjectID(itemOfferedId),
i = new Bid(data);
Bid.collection.save(i, function(){
require('./item').collection.update({_id: offeredItemId},{$set: {isBiddable: false}},cb);
});
};

Bid.countItemBids = function(itemId, cb){
Bid.collection.count({itemUpForBidId:itemId, isOpen:true}, cb);
};
Expand Down
2 changes: 2 additions & 0 deletions app/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var morgan = require('morgan'),
debug = require('../lib/debug'),
home = require('../controllers/home'),
items = require('../controllers/items'),
bids = require('../controllers/bids'),
users = require('../controllers/users');

module.exports = function(app, express){
Expand Down Expand Up @@ -42,6 +43,7 @@ module.exports = function(app, express){
app.get('/trade/:itemId', items.showTrade);
app.put('/trade', items.trade);
app.get('/bid/:itemId', items.itemBidPage);
app.post('/bidding/:itemOfferedId', bids.create);

console.log('Express: Routes Loaded');
};
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 60 additions & 1 deletion app/static/css/style.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@bidCards: #120F30;
@bidButton: #ebebeb;

body{

.homePage {
height: 1080px;
}

.profile-photo {
Expand All @@ -17,3 +21,58 @@ body{
#marketplace-map {
height: 400px;
}

#bid {
margin: 10px;
position: relative;
display: inline-block;
vertical-align: top;
border: 1px solid @bidButton;
width: 200px;
height: 375px;
background-color: @bidCards ;

}

.bid-photo{
height: 200px;
background-size: cover;
/*background-repeat: no-repeat;*/
}

.bid-name {
font-size: 24px;
padding: 10px;
}

.bid-location {
padding: 10px;
font-size: 18px;
background-color: #1B1742;
}

.bid-description {
padding: 10px;
font-size: 18px;
background-color: #231F4D;
margin: 0px;
}

#bidButton {
position: absolute;
bottom: 0px;
right: 0px;
width: 197px;
background-color: @bidButton;
border: 0px solid @bidButton;
color: #260026;
border-radius: 0%;
}

#bidButton:hover {
background-color: white;
}




Binary file added app/static/img/wine_seller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions app/views/home/index.jade
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
extends ../shared/template
block content
h2 Home
.panel.panel-default
.panel-body

.homePage(style='background-image: url("/img/wine_seller.png");')
block scripts
script(src='/js/user/home.js')

39 changes: 14 additions & 25 deletions app/views/items/show-bid.jade
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,20 @@ block content
td= item.location
td= item.description
.row
.col-xs-6
table.table
thead My Wines
tr
th Photo
th Name
th Location
th Description
th Trade
tbody
each biddable in biddableItems
tr
td.biddable-photo(style='background-image:url(#{biddable.photo})')
td: a(href='/bid/#{item._id}')= biddable.name
td= biddable.location
td= biddable.description
td
.radio
label
input(type='radio' name='bid' value='#{biddable._id}')
.row
.col-xs-6
form(role='form', method='post', action='/marketplace')
button.btn.btn-success(type='submit') MAKE BID

.col-xs-12
#bids
each bidItem in biddableItems
#bid
form(role='form', method='post', action='/bidding/#{bidItem._id}')
.bid-photo(style='background-image:url("#{bidItem.photo}");')
.bid-name= bidItem.name
.bid-location= bidItem.location
.bid-description= bidItem.description
input(type='hidden', name='itemUpForBidId', value=item._id)
input(type='hidden', name='itemOfferedId', value=bidItem._id)
input(type='hidden', name='offerOwnerId', value=bidItem.ownerId)
input(type='hidden', name='upForBidOwnerId', value=item.ownerId)
button#bidButton.btn.btn-success(type='submit') Bid It
block scripts
script(src='/js/user/items-index.js')

45 changes: 45 additions & 0 deletions test/acceptance/bids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* global describe, before, beforeEach, it */

'use strict';

process.env.DB = 'wine-seller-test';

var expect = require('chai').expect,
cp = require('child_process'),
app = require('../../app/index'),
cookie = null,
request = require('supertest');

describe('users', function(){
before(function(done){
request(app).get('/').end(done);
});

beforeEach(function(done){
cp.execFile(__dirname + '/../scripts/clean-db.sh', [process.env.DB], {cwd:__dirname + '/../scripts'}, function(err, stdout, stderr){
request(app)
.post('/login')
.send('email=nodeapptest%2Bbob%40gmail.com&password=1234')
.end(function(err, res){
cookie = res.headers['set-cookie'][0];
done();
});
});
});

describe('post /bid', function(){
it('should redirect to marketplace page', function(done){
request(app)
.post('/bidding/a00000000000000000000001')
.set('cookie', cookie)
.send('itemUpForBidId=a00000000000000000000006&itemOfferedId=a00000000000000000000001&offerOwnerId=000000000000000000000001&upForBidOwnerId=000000000000000000000002')
.end(function(err, res){
expect(res.status).to.equal(302);
expect(res.headers.location).to.equal('/marketplace');
done();
});
});
});

});

17 changes: 17 additions & 0 deletions test/acceptance/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/node/bin/node', '/usr/local/node/bin/npm', 'test' ]
2 info using npm@1.4.14
3 info using node@v0.10.29
4 error Error: ENOENT, open '/home/nss/apps/code/wine-seller/test/acceptance/package.json'
5 error If you need help, you may report this *entire* log,
5 error including the npm and node versions, at:
5 error <http://github.com/npm/npm/issues>
6 error System Linux 3.13.0-24-generic
7 error command "/usr/local/node/bin/node" "/usr/local/node/bin/npm" "test"
8 error cwd /home/nss/apps/code/wine-seller/test/acceptance
9 error node -v v0.10.29
10 error npm -v 1.4.14
11 error path /home/nss/apps/code/wine-seller/test/acceptance/package.json
12 error code ENOENT
13 error errno 34
14 verbose exit [ 34, true ]
33 changes: 32 additions & 1 deletion test/unit/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ var expect = require('chai').expect,
Mongo = require('mongodb'),
dbConnect = require('../../app/lib/mongodb'),
cp = require('child_process'),
db = 'wine-seller-test';
db = 'wine-seller-test',

itemUpForBidId = Mongo.ObjectID(),
itemOfferedId = Mongo.ObjectID(),
upForBidOwnerId = Mongo.ObjectID(),
offerOwnerId = Mongo.ObjectID();

describe('Bid', function(){
before(function(done){
Expand All @@ -24,6 +29,32 @@ describe('Bid', function(){
});
});

describe('constructor', function(){
it('should create a new Bid object', function(){
var data = {itemUpForBidId: itemUpForBidId, itemOfferedId: itemOfferedId, upForBidOwnerId:upForBidOwnerId, offerOwnerId: offerOwnerId},
i = new Bid(data);
expect(i).to.be.instanceof(Bid);
expect(i.itemUpForBidId).to.be.instanceof(Mongo.ObjectID);
expect(i.itemOfferedId).to.be.instanceof(Mongo.ObjectID);
expect(i.upForBidOwnerId).to.be.instanceof(Mongo.ObjectID);
expect(i.offerOwnerId).to.be.instanceof(Mongo.ObjectID);
expect(i.isOpen).to.be.true;
});
});

describe('.create', function(){
it('should save a new Bid in the database and change offered item isBiddable to false', function(done){
var data = {itemUpForBidId: itemUpForBidId, itemOfferedId: itemOfferedId, upForBidOwnerId:upForBidOwnerId, offerOwnerId: offerOwnerId},
i = new Bid(data);
Bid.create(i, 'a00000000000000000000005', function(){
Item.findById('a00000000000000000000005', function(err, changedItem){
expect(changedItem.isBiddable).to.be.false;
done();
});
});
});
});

describe('.accept', function(){
it('should close auction and change ownership of items', function(done){
var userId = Mongo.ObjectID('000000000000000000000001');
Expand Down

0 comments on commit d4fecdb

Please sign in to comment.