Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Hao-Hsiang Song
/
topics-auction
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1dbfbfbf
authored
Nov 30, 2018
by
Rex Zhou
Browse files
Options
Browse Files
Download
Plain Diff
userid long type
parents
6fb2e418
97373c42
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
105 additions
and
41 deletions
src/main/java/edu/uchicago/mpcs/topics/auction/Item.java
src/main/java/edu/uchicago/mpcs/topics/auction/Status.java
src/main/java/edu/uchicago/mpcs/topics/auction/TimeTracker.java
src/main/java/edu/uchicago/mpcs/topics/controller/ShoppingCartController.java
src/main/java/edu/uchicago/mpcs/topics/controller/itemCategoryController.java
src/main/java/edu/uchicago/mpcs/topics/service/BidService.java
src/main/java/edu/uchicago/mpcs/topics/service/ItemService.java
src/main/java/edu/uchicago/mpcs/topics/service/ShoppingCartService.java
src/main/resources/application.properties
src/main/java/edu/uchicago/mpcs/topics/auction/Item.java
View file @
1dbfbfbf
...
...
@@ -2,6 +2,8 @@ package edu.uchicago.mpcs.topics.auction;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
edu.uchicago.mpcs.topics.user.User
;
import
org.apache.tomcat.jni.Local
;
import
javax.persistence.*
;
import
java.util.Date
;
...
...
@@ -28,16 +30,18 @@ public class Item
private
Double
shippingCost
;
private
Boolean
canBuyNow
;
private
Date
startTime
;
//Start the auction when the current time matches the start time defined by the user
private
Date
endTime
;
//Allowing auction window to be set by the bidder, and begin countdown to the end of the bidding window once auction begins
private
String
startTime
;
//Start the auction when the current time matches the start time defined by the user
private
String
endTime
;
//Allowing auction window to be set by the bidder, and begin countdown to the end of the bidding window once auction begins
@Column
(
length
=
2000
)
private
String
photoUrl
;
private
Long
us
erId
;
//seller
private
Long
sell
erId
;
//seller
private
Status
status
;
private
Long
currentBidderID
;
@ManyToMany
(
mappedBy
=
"items"
)
@JsonIgnore
private
Set
<
ShoppingCart
>
shopping_carts
=
new
HashSet
<>();
//must have the same name as the table
...
...
@@ -47,7 +51,8 @@ public class Item
}
public
Item
(
String
title
,
String
description
,
Long
categoryId
,
double
currentPrice
,
double
buyNowPrice
,
String
photoUrl
,
Long
userId
,
Boolean
canBuyNow
)
double
buyNowPrice
,
String
photoUrl
,
Long
sellerId
,
Boolean
canBuyNow
,
String
startTime
,
String
endTime
)
{
this
.
title
=
title
;
this
.
description
=
description
;
...
...
@@ -55,8 +60,10 @@ public class Item
this
.
currentPrice
=
currentPrice
;
this
.
buyNowPrice
=
buyNowPrice
;
this
.
photoUrl
=
photoUrl
;
this
.
userId
=
us
erId
;
this
.
sellerId
=
sell
erId
;
this
.
canBuyNow
=
canBuyNow
;
this
.
startTime
=
startTime
;
this
.
endTime
=
endTime
;
}
public
Long
getItemId
()
...
...
@@ -130,14 +137,14 @@ public class Item
this
.
photoUrl
=
photoUrl
;
}
public
Long
get
Us
erId
()
public
Long
get
Sell
erId
()
{
return
us
erId
;
return
sell
erId
;
}
public
void
set
UserId
(
Long
us
erId
)
public
void
set
SellerId
(
Long
sell
erId
)
{
this
.
userId
=
us
erId
;
this
.
sellerId
=
sell
erId
;
}
@JsonIgnore
...
...
@@ -193,23 +200,33 @@ public class Item
this
.
canBuyNow
=
canBuyNow
;
}
public
Date
getStartTime
()
public
String
getStartTime
()
{
return
startTime
;
}
public
void
setStartTime
(
Date
startTime
)
public
void
setStartTime
(
String
startTime
)
{
this
.
startTime
=
startTime
;
}
public
Date
getEndTime
()
public
String
getEndTime
()
{
return
endTime
;
}
public
void
setEndTime
(
Date
endTime
)
public
void
setEndTime
(
String
endTime
)
{
this
.
endTime
=
endTime
;
}
public
Long
getCurrentBidderID
()
{
return
currentBidderID
;
}
public
void
setCurrentBidderID
(
Long
currentBidderID
)
{
this
.
currentBidderID
=
currentBidderID
;
}
}
src/main/java/edu/uchicago/mpcs/topics/auction/Status.java
View file @
1dbfbfbf
...
...
@@ -5,5 +5,5 @@ package edu.uchicago.mpcs.topics.auction;
*/
public
enum
Status
{
ACTIVE
,
INACTIVE
,
FAILED
,
INAPPROPRIATE
,
COUNTERFEIT
,
SUSPENDED
,
DELETED
,
HASBID
,
SOLD
ACTIVE
,
INACTIVE
,
FAILED
,
INAPPROPRIATE
,
COUNTERFEIT
,
SUSPENDED
,
DELETED
,
HASBID
,
SOLD
,
ENDED
}
src/main/java/edu/uchicago/mpcs/topics/auction/TimeTracker.java
View file @
1dbfbfbf
package
edu
.
uchicago
.
mpcs
.
topics
.
auction
;
import
java.util.Date
;
import
java.util.Timer
;
import
edu.uchicago.mpcs.topics.db.ItemRepository
;
import
edu.uchicago.mpcs.topics.db.ShoppingCartRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
public
class
TimeTracker
{
private
Timer
timer
;
private
long
timeWindow
;
private
Date
start
;
import
java.time.Duration
;
import
java.time.LocalDateTime
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
public
Timer
getTimer
()
{
return
timer
;
}
public
class
TimeTracker
{
private
Long
itemId
;
public
void
setTimer
(
Timer
timer
)
{
this
.
timer
=
timer
;
}
@Autowired
private
ItemRepository
itemRepository
;
public
long
getTimeWindow
()
{
return
timeWindow
;
}
@Autowired
private
ShoppingCartRepository
shoppingCartRepository
;
//Please use format 2018-11-30T01:37:17
public
TimeTracker
(
Item
item
)
{
this
.
itemId
=
item
.
getItemId
();
LocalDateTime
startTime
=
LocalDateTime
.
parse
(
item
.
getStartTime
());
LocalDateTime
endTime
=
LocalDateTime
.
parse
(
item
.
getEndTime
());
public
void
setTimeWindow
(
long
timeWindow
)
{
this
.
timeWindow
=
timeWindow
;
LocalDateTime
currentTime
=
LocalDateTime
.
now
();
Duration
durationStart
=
Duration
.
between
(
startTime
,
currentTime
);
ScheduledExecutorService
startTimer
=
Executors
.
newSingleThreadScheduledExecutor
();
startTimer
.
schedule
(()
->
timeStart
(),
durationStart
.
getSeconds
(),
TimeUnit
.
SECONDS
);
Duration
durationEnd
=
Duration
.
between
(
startTime
,
endTime
);
ScheduledExecutorService
endTimer
=
Executors
.
newSingleThreadScheduledExecutor
();
endTimer
.
schedule
(()
->
timeEnd
(),
durationEnd
.
getSeconds
(),
TimeUnit
.
SECONDS
);
}
public
Date
getStart
()
{
return
start
;
private
void
timeStart
()
{
Item
itemToUpdate
=
itemRepository
.
findById
(
this
.
itemId
).
orElse
(
null
);
itemToUpdate
.
setStatus
(
Status
.
ACTIVE
);
itemRepository
.
save
(
itemToUpdate
);
}
public
void
setStart
(
Date
start
)
{
this
.
start
=
start
;
private
void
timeEnd
()
{
//set status to ENDED
Item
itemToUpdate
=
itemRepository
.
findById
(
this
.
itemId
).
orElse
(
null
);
itemToUpdate
.
setStatus
(
Status
.
ENDED
);
itemRepository
.
save
(
itemToUpdate
);
//add the item to user shopping cart
ShoppingCart
shoppingCart
=
shoppingCartRepository
.
findById
(
itemToUpdate
.
getCurrentBidderID
()).
orElse
(
null
);
shoppingCartRepository
.
save
(
shoppingCart
.
addItem
(
itemToUpdate
));
}
}
src/main/java/edu/uchicago/mpcs/topics/controller/ShoppingCartController.java
View file @
1dbfbfbf
...
...
@@ -7,6 +7,7 @@ import edu.uchicago.mpcs.topics.db.ShoppingCartRepository;
import
edu.uchicago.mpcs.topics.service.CheckoutService
;
import
edu.uchicago.mpcs.topics.service.ShoppingCartService
;
import
edu.uchicago.mpcs.topics.auction.ShoppingCart
;
import
edu.uchicago.mpcs.topics.user.User
;
import
org.springframework.web.bind.annotation.*
;
/**
...
...
src/main/java/edu/uchicago/mpcs/topics/controller/itemCategoryController.java
View file @
1dbfbfbf
...
...
@@ -18,7 +18,7 @@ public class itemCategoryController
{
//repository
ItemCategoryRepository
itemCategoryRepository
;
private
ItemCategoryRepository
itemCategoryRepository
;
public
itemCategoryController
(
ItemCategoryRepository
itemCategoryRepository
)
{
...
...
src/main/java/edu/uchicago/mpcs/topics/service/BidService.java
View file @
1dbfbfbf
...
...
@@ -32,10 +32,15 @@ public class BidService
{
itemToUpdate
.
setItemId
(
bid
.
getItemId
());
itemToUpdate
.
setCurrentPrice
(
bid
.
getAmount
());
//Assign highest bidder
itemToUpdate
.
setCurrentBidderID
(
bid
.
getUserId
());
itemRepository
.
save
(
itemToUpdate
);
bid
.
setStatus
(
Status
.
ACTIVE
);
//set highestBidder
return
bidRepository
.
save
(
bid
);
}
else
...
...
src/main/java/edu/uchicago/mpcs/topics/service/ItemService.java
View file @
1dbfbfbf
...
...
@@ -2,6 +2,7 @@ package edu.uchicago.mpcs.topics.service;
import
edu.uchicago.mpcs.topics.auction.Item
;
import
edu.uchicago.mpcs.topics.auction.Status
;
import
edu.uchicago.mpcs.topics.auction.TimeTracker
;
import
edu.uchicago.mpcs.topics.db.ItemRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -30,9 +31,13 @@ public class ItemService
public
Item
addItem
(
Item
item
)
{
Item
savedItem
=
itemRepository
.
save
(
item
);
//start timer
return
itemRepository
.
save
(
item
);
TimeTracker
timeTracker
=
new
TimeTracker
(
savedItem
);
return
savedItem
;
}
public
Item
deleteItem
(
Long
id
)
...
...
src/main/java/edu/uchicago/mpcs/topics/service/ShoppingCartService.java
View file @
1dbfbfbf
...
...
@@ -5,6 +5,7 @@ import edu.uchicago.mpcs.topics.auction.Status;
import
edu.uchicago.mpcs.topics.db.ItemRepository
;
import
edu.uchicago.mpcs.topics.db.ShoppingCartRepository
;
import
edu.uchicago.mpcs.topics.auction.ShoppingCart
;
import
edu.uchicago.mpcs.topics.user.User
;
import
org.springframework.stereotype.Service
;
/**
...
...
src/main/resources/application.properties
View file @
1dbfbfbf
spring.data.rest.base-path
=
/api
spring.h2.console.enabled
=
true
spring.jpa.hibernate.ddl-auto
=
update
spring.datasource.url
=
jdbc:h2:file:./target/h2db;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
spring.datasource.driver-class-name
=
org.h2.Driver
\ No newline at end of file
#spring.jpa.hibernate.ddl-auto = update
#spring.datasource.url=jdbc:h2:file:./target/h2db;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
#
spring.datasource.driver-class-name
=
org.h2.Driver
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment