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
1842595e
authored
Nov 30, 2018
by
Bright Sukumpanumet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bugs
parent
ac38eaea
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
63 additions
and
53 deletions
src/main/java/edu/uchicago/mpcs/topics/auction/Bid.java
src/main/java/edu/uchicago/mpcs/topics/auction/ItemCategory.java
src/main/java/edu/uchicago/mpcs/topics/auction/Watchlist.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/java/edu/uchicago/mpcs/topics/auction/TimeTracker.java → src/main/java/edu/uchicago/mpcs/topics/service/TimerService.java
target/classes/edu/uchicago/mpcs/topics/auction/Bid.class
target/classes/edu/uchicago/mpcs/topics/auction/Item.class
target/classes/edu/uchicago/mpcs/topics/auction/TimeTracker.class
target/classes/edu/uchicago/mpcs/topics/service/ItemService.class
src/main/java/edu/uchicago/mpcs/topics/auction/Bid.java
View file @
1842595e
...
...
@@ -11,7 +11,7 @@ import java.util.Date;
public
class
Bid
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Long
bidId
;
@NotNull
...
...
@@ -32,6 +32,7 @@ public class Bid
this
.
amount
=
amount
;
this
.
itemId
=
itemId
;
this
.
time
=
time
;
this
.
status
=
Status
.
ACTIVE
;
}
public
Long
getBidId
()
...
...
src/main/java/edu/uchicago/mpcs/topics/auction/ItemCategory.java
View file @
1842595e
...
...
@@ -16,6 +16,8 @@ public class ItemCategory
private
String
itemCategoryName
;
public
ItemCategory
(){}
public
ItemCategory
(
String
itemCategoryName
)
{
this
.
itemCategoryName
=
itemCategoryName
;
...
...
@@ -33,6 +35,6 @@ public class ItemCategory
public
void
setItemCategoryName
(
String
itemCategoryName
)
{
itemCategoryName
=
itemCategoryName
;
this
.
itemCategoryName
=
itemCategoryName
;
}
}
src/main/java/edu/uchicago/mpcs/topics/auction/Watchlist.java
deleted
100644 → 0
View file @
ac38eaea
package
edu
.
uchicago
.
mpcs
.
topics
.
auction
;
/**
* Created by Bright on 2018-11-30.
*/
public
class
Watchlist
{
}
src/main/java/edu/uchicago/mpcs/topics/controller/ShoppingCartController.java
View file @
1842595e
...
...
@@ -49,11 +49,10 @@ public class ShoppingCartController
return
shoppingCartService
.
removeItem
(
shoppingCartRepository
.
findById
(
id
).
orElse
(
null
),
item
);
}
@P
os
tMapping
(
"/{id}/checkout"
)
public
Checkout
checkout
(
@PathVariable
Long
id
,
@RequestBody
Checkout
checkout
)
@P
u
tMapping
(
"/{id}/checkout"
)
public
ShoppingCart
checkout
(
@PathVariable
Long
id
)
{
// save checkout (checkout) to db
shoppingCartService
.
checkout
(
shoppingCartRepository
.
findById
(
id
).
orElse
(
null
));
return
checkoutService
.
checkout
(
checkout
);
return
shoppingCartService
.
checkout
(
shoppingCartRepository
.
findById
(
id
).
orElse
(
null
));
}
}
src/main/java/edu/uchicago/mpcs/topics/controller/itemCategoryController.java
View file @
1842595e
...
...
@@ -44,12 +44,4 @@ public class itemCategoryController
return
itemCategoryRepository
.
save
(
itemCategory
);
}
//remove category ...disable remove category because of possible consequences
// @DeleteMapping("/{id}")
// public void removeItemCategory(@PathVariable Long id)
// {
// itemCategoryRepository.deleteById(id);
// }
}
src/main/java/edu/uchicago/mpcs/topics/service/BidService.java
View file @
1842595e
...
...
@@ -17,10 +17,14 @@ import java.util.Optional;
@Service
public
class
BidService
{
@Autowired
private
BidRepository
bidRepository
;
@Autowired
private
ItemRepository
itemRepository
;
private
final
BidRepository
bidRepository
;
private
final
ItemRepository
itemRepository
;
public
BidService
(
BidRepository
bidRepository
,
ItemRepository
itemRepository
)
{
this
.
bidRepository
=
bidRepository
;
this
.
itemRepository
=
itemRepository
;
}
public
Bid
addBid
(
Bid
bid
)
{
...
...
@@ -35,10 +39,9 @@ public class BidService
//Assign highest bidder
itemToUpdate
.
setCurrentBidderID
(
bid
.
getUserId
());
itemToUpdate
.
setStatus
(
Status
.
HASBID
);
itemRepository
.
save
(
itemToUpdate
);
bid
.
setStatus
(
Status
.
ACTIVE
);
//set highestBidder
return
bidRepository
.
save
(
bid
);
...
...
src/main/java/edu/uchicago/mpcs/topics/service/ItemService.java
View file @
1842595e
...
...
@@ -2,7 +2,6 @@ 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
;
...
...
@@ -10,7 +9,6 @@ import org.springframework.stereotype.Service;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
/**
* Created by Bright on 2018-11-17.
...
...
@@ -19,8 +17,15 @@ import java.util.UUID;
@Service
public
class
ItemService
{
private
final
ItemRepository
itemRepository
;
private
TimerService
timerService
;
@Autowired
private
ItemRepository
itemRepository
;
public
ItemService
(
ItemRepository
itemRepository
,
TimerService
timerService
)
{
this
.
itemRepository
=
itemRepository
;
this
.
timerService
=
timerService
;
}
public
List
<
Item
>
getAllItems
()
{
...
...
@@ -35,9 +40,7 @@ public class ItemService
//start timer
new
TimeTracker
(
savedItem
);
return
savedItem
;
return
timerService
.
trackTime
(
savedItem
);
}
public
Item
deleteItem
(
Long
id
)
...
...
src/main/java/edu/uchicago/mpcs/topics/service/ShoppingCartService.java
View file @
1842595e
...
...
@@ -40,7 +40,7 @@ public class ShoppingCartService
return
shoppingCartRepository
.
save
(
shoppingCart
);
}
public
void
checkout
(
ShoppingCart
shoppingCart
)
public
ShoppingCart
checkout
(
ShoppingCart
shoppingCart
)
{
//for each item in checkout, delete item from shopping cart
for
(
Item
item
:
shoppingCart
.
getItems
())
...
...
@@ -51,6 +51,8 @@ public class ShoppingCartService
//for each item in checkout, change Status to SOLD
shoppingCart
.
removeAllItems
();
return
shoppingCartRepository
.
save
(
shoppingCart
);
}
}
\ No newline at end of file
src/main/java/edu/uchicago/mpcs/topics/
auction/TimeTracker
.java
→
src/main/java/edu/uchicago/mpcs/topics/
service/TimerService
.java
View file @
1842595e
package
edu
.
uchicago
.
mpcs
.
topics
.
auction
;
package
edu
.
uchicago
.
mpcs
.
topics
.
service
;
import
edu.uchicago.mpcs.topics.auction.Item
;
import
edu.uchicago.mpcs.topics.auction.ShoppingCart
;
import
edu.uchicago.mpcs.topics.auction.Status
;
import
edu.uchicago.mpcs.topics.db.ItemRepository
;
import
edu.uchicago.mpcs.topics.db.ShoppingCartRepository
;
import
org.apache.tomcat.jni.Local
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.time.Duration
;
import
java.time.LocalDateTime
;
...
...
@@ -10,14 +15,13 @@ import java.util.concurrent.Executors;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
public
class
TimeTracker
@Service
public
class
TimerService
{
private
Long
itemId
;
@Autowired
private
ItemRepository
itemRepository
;
@Autowired
private
ShoppingCartRepository
shoppingCartRepository
;
...
...
@@ -25,35 +29,40 @@ public class TimeTracker
//Please use format 2018-11-30T01:37:17
public
TimeTracker
(
Item
item
)
public
TimerService
(
ItemRepository
itemRepository
,
ShoppingCartRepository
shoppingCartRepository
)
{
this
.
itemRepository
=
itemRepository
;
this
.
shoppingCartRepository
=
shoppingCartRepository
;
}
public
Item
trackTime
(
Item
item
)
{
this
.
itemId
=
item
.
getItemId
();
// System.out.println(this.itemId);
LocalDateTime
currentTime
=
LocalDateTime
.
now
();
LocalDateTime
startTime
=
LocalDateTime
.
now
();
LocalDateTime
startTime
=
LocalDateTime
.
parse
(
item
.
getStartTime
());
if
(
item
.
getStartTime
()
!=
null
)
{
setStatus
(
Status
.
INACTIVE
);
startTime
=
LocalDateTime
.
parse
(
item
.
getStartTime
());
Duration
durationStart
=
Duration
.
between
(
startTime
,
currentTime
);
Duration
durationStart
=
Duration
.
between
(
currentTime
,
startTime
);
ScheduledExecutorService
startTimer
=
Executors
.
newSingleThreadScheduledExecutor
();
startTimer
.
schedule
(
this
::
timeStart
,
durationStart
.
getSeconds
(),
TimeUnit
.
SECONDS
);
// System.out.println(durationStart.getSeconds());
}
if
(
item
.
getEndTime
()
!=
null
)
{
LocalDateTime
endTime
=
LocalDateTime
.
parse
(
item
.
getEndTime
());
Duration
durationEnd
=
Duration
.
between
(
startTime
,
end
Time
);
Duration
durationEnd
=
Duration
.
between
(
endTime
,
current
Time
);
ScheduledExecutorService
endTimer
=
Executors
.
newSingleThreadScheduledExecutor
();
endTimer
.
schedule
(
this
::
timeEnd
,
durationEnd
.
getSeconds
(),
TimeUnit
.
SECONDS
);
}
return
itemRepository
.
findById
(
this
.
itemId
).
orElse
(
null
);
}
private
Item
setStatus
(
Status
status
)
...
...
@@ -75,10 +84,17 @@ public class TimeTracker
private
void
timeEnd
()
{
//set status to ENDED
Item
itemToAdd
=
this
.
setStatus
(
Status
.
ENDED
);
//add the item to user shopping cart
ShoppingCart
shoppingCart
=
shoppingCartRepository
.
findById
(
itemToAdd
.
getCurrentBidderID
()).
orElse
(
null
);
shoppingCartRepository
.
save
(
shoppingCart
.
addItem
(
itemToAdd
));
Item
itemToUpdate
=
itemRepository
.
findById
(
this
.
itemId
).
orElse
(
null
);
if
(
itemToUpdate
.
getStatus
()
==
Status
.
HASBID
)
{
//add the item to user shopping cart
ShoppingCart
shoppingCart
=
shoppingCartRepository
.
findById
(
itemToUpdate
.
getCurrentBidderID
()).
orElse
(
null
);
shoppingCartRepository
.
save
(
shoppingCart
.
addItem
(
itemToUpdate
));
}
itemToUpdate
.
setStatus
(
Status
.
ENDED
);
itemRepository
.
save
(
itemToUpdate
);
}
}
target/classes/edu/uchicago/mpcs/topics/auction/Bid.class
View file @
1842595e
No preview for this file type
target/classes/edu/uchicago/mpcs/topics/auction/Item.class
View file @
1842595e
No preview for this file type
target/classes/edu/uchicago/mpcs/topics/auction/TimeTracker.class
deleted
100644 → 0
View file @
ac38eaea
File deleted
target/classes/edu/uchicago/mpcs/topics/service/ItemService.class
View file @
1842595e
No preview for this file type
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