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
319e3660
authored
Nov 30, 2018
by
Rex Zhou
Browse files
Options
Browse Files
Download
Plain Diff
user services
parents
6e241132
daa0dcbb
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
106 additions
and
32 deletions
src/main/java/edu/uchicago/mpcs/topics/auction/Order.java → src/main/java/edu/uchicago/mpcs/topics/auction/Checkout.java
src/main/java/edu/uchicago/mpcs/topics/auction/Item.java
src/main/java/edu/uchicago/mpcs/topics/auction/ShoppingCart.java
src/main/java/edu/uchicago/mpcs/topics/auction/Status.java
src/main/java/edu/uchicago/mpcs/topics/controller/ShoppingCartController.java
src/main/java/edu/uchicago/mpcs/topics/db/OrderRepository.java → src/main/java/edu/uchicago/mpcs/topics/db/CheckoutRepository.java
src/main/java/edu/uchicago/mpcs/topics/service/OrderService.java → src/main/java/edu/uchicago/mpcs/topics/service/CheckoutService.java
src/main/java/edu/uchicago/mpcs/topics/service/ItemService.java
src/main/java/edu/uchicago/mpcs/topics/service/ShoppingCartService.java
target/classes/edu/uchicago/mpcs/topics/auction/Item.class
target/classes/edu/uchicago/mpcs/topics/auction/Order.class
target/classes/edu/uchicago/mpcs/topics/controller/ShoppingCartController.class
target/classes/edu/uchicago/mpcs/topics/db/OrderRepository.class
target/classes/edu/uchicago/mpcs/topics/service/OrderService.class
target/h2db.trace.db
src/main/java/edu/uchicago/mpcs/topics/auction/
Order
.java
→
src/main/java/edu/uchicago/mpcs/topics/auction/
Checkout
.java
View file @
319e3660
...
...
@@ -8,25 +8,25 @@ import java.util.Set;
* Created by Bright on 2018-11-27.
*/
@Entity
public
class
Order
public
class
Checkout
{
@Id
private
Long
order
Id
;
private
Long
checkout
Id
;
@ManyToMany
(
cascade
=
{
CascadeType
.
PERSIST
})
@JoinTable
(
name
=
"
order
_item"
,
joinColumns
=
@JoinColumn
(
name
=
"
order_id"
,
referencedColumnName
=
"order
Id"
),
@JoinTable
(
name
=
"
checkout
_item"
,
joinColumns
=
@JoinColumn
(
name
=
"
checkout_id"
,
referencedColumnName
=
"checkout
Id"
),
inverseJoinColumns
=
@JoinColumn
(
name
=
"item_id"
,
referencedColumnName
=
"itemId"
))
private
Set
<
Item
>
items
=
new
HashSet
<>();
public
Order
()
public
Checkout
()
{}
public
Order
(
Long
order
Id
)
public
Checkout
(
Long
checkout
Id
)
{
this
.
orderId
=
order
Id
;
this
.
checkoutId
=
checkout
Id
;
}
public
Set
<
Item
>
getItems
()
...
...
src/main/java/edu/uchicago/mpcs/topics/auction/Item.java
View file @
319e3660
...
...
@@ -24,6 +24,9 @@ public class Item
private
Long
categoryId
;
private
double
currentPrice
;
private
double
buyNowPrice
;
private
Long
quantity
;
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
...
...
@@ -43,7 +46,8 @@ public class Item
{
}
public
Item
(
String
title
,
String
description
,
Long
categoryId
,
double
currentPrice
,
double
buyNowPrice
,
String
photoUrl
,
Long
userId
)
public
Item
(
String
title
,
String
description
,
Long
categoryId
,
double
currentPrice
,
double
buyNowPrice
,
String
photoUrl
,
Long
userId
,
Boolean
canBuyNow
)
{
this
.
title
=
title
;
this
.
description
=
description
;
...
...
@@ -52,6 +56,7 @@ public class Item
this
.
buyNowPrice
=
buyNowPrice
;
this
.
photoUrl
=
photoUrl
;
this
.
userId
=
userId
;
this
.
canBuyNow
=
canBuyNow
;
}
public
Long
getItemId
()
...
...
@@ -157,4 +162,54 @@ public class Item
{
this
.
status
=
status
;
}
public
Long
getQuantity
()
{
return
quantity
;
}
public
void
setQuantity
(
Long
quantity
)
{
this
.
quantity
=
quantity
;
}
public
Double
getShippingCost
()
{
return
shippingCost
;
}
public
void
setShippingCost
(
Double
shippingCost
)
{
this
.
shippingCost
=
shippingCost
;
}
public
Boolean
getCanBuyNow
()
{
return
canBuyNow
;
}
public
void
setCanBuyNow
(
Boolean
canBuyNow
)
{
this
.
canBuyNow
=
canBuyNow
;
}
public
Date
getStartTime
()
{
return
startTime
;
}
public
void
setStartTime
(
Date
startTime
)
{
this
.
startTime
=
startTime
;
}
public
Date
getEndTime
()
{
return
endTime
;
}
public
void
setEndTime
(
Date
endTime
)
{
this
.
endTime
=
endTime
;
}
}
src/main/java/edu/uchicago/mpcs/topics/auction/ShoppingCart.java
View file @
319e3660
...
...
@@ -45,6 +45,7 @@ public class ShoppingCart
{
for
(
Item
item
:
items
)
{
this
.
items
.
remove
(
item
);
item
.
getShopping_carts
().
remove
(
this
);
}
...
...
src/main/java/edu/uchicago/mpcs/topics/auction/Status.java
View file @
319e3660
...
...
@@ -5,5 +5,5 @@ package edu.uchicago.mpcs.topics.auction;
*/
public
enum
Status
{
ACTIVE
,
INACTIVE
,
FAILED
,
INAPPROPRIATE
,
COUNTERFEIT
,
SUSPENDED
,
DELETED
,
HASBID
ACTIVE
,
INACTIVE
,
FAILED
,
INAPPROPRIATE
,
COUNTERFEIT
,
SUSPENDED
,
DELETED
,
HASBID
,
SOLD
}
src/main/java/edu/uchicago/mpcs/topics/controller/ShoppingCartController.java
View file @
319e3660
package
edu
.
uchicago
.
mpcs
.
topics
.
controller
;
import
edu.uchicago.mpcs.topics.auction.Item
;
import
edu.uchicago.mpcs.topics.auction.
Order
;
import
edu.uchicago.mpcs.topics.db.
Order
Repository
;
import
edu.uchicago.mpcs.topics.auction.
Checkout
;
import
edu.uchicago.mpcs.topics.db.
Checkout
Repository
;
import
edu.uchicago.mpcs.topics.db.ShoppingCartRepository
;
import
edu.uchicago.mpcs.topics.service.
Order
Service
;
import
edu.uchicago.mpcs.topics.service.
Checkout
Service
;
import
edu.uchicago.mpcs.topics.service.ShoppingCartService
;
import
edu.uchicago.mpcs.topics.auction.ShoppingCart
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -19,8 +19,8 @@ public class ShoppingCartController
{
private
ShoppingCartService
shoppingCartService
;
private
ShoppingCartRepository
shoppingCartRepository
;
private
OrderService
order
Service
;
private
OrderRepository
order
Repository
;
private
CheckoutService
checkout
Service
;
private
CheckoutRepository
checkout
Repository
;
public
ShoppingCartController
(
ShoppingCartService
shoppingCartService
,
ShoppingCartRepository
shoppingCartRepository
)
{
...
...
@@ -49,10 +49,10 @@ public class ShoppingCartController
}
@PostMapping
(
"/{id}/checkout"
)
public
Order
checkout
(
@PathVariable
Long
id
,
@RequestBody
Order
order
)
public
Checkout
checkout
(
@PathVariable
Long
id
,
@RequestBody
Checkout
checkout
)
{
// save
order
(checkout) to db
// save
checkout
(checkout) to db
shoppingCartService
.
checkout
(
shoppingCartRepository
.
findById
(
id
).
orElse
(
null
));
return
orderService
.
checkout
(
order
);
return
checkoutService
.
checkout
(
checkout
);
}
}
src/main/java/edu/uchicago/mpcs/topics/db/
Order
Repository.java
→
src/main/java/edu/uchicago/mpcs/topics/db/
Checkout
Repository.java
View file @
319e3660
package
edu
.
uchicago
.
mpcs
.
topics
.
db
;
import
edu.uchicago.mpcs.topics.auction.
Order
;
import
edu.uchicago.mpcs.topics.auction.
Checkout
;
import
org.springframework.data.repository.CrudRepository
;
/**
* Created by Bright on 2018-11-29.
*/
public
interface
OrderRepository
extends
CrudRepository
<
Order
,
Long
>
public
interface
CheckoutRepository
extends
CrudRepository
<
Checkout
,
Long
>
{
}
src/main/java/edu/uchicago/mpcs/topics/service/
Order
Service.java
→
src/main/java/edu/uchicago/mpcs/topics/service/
Checkout
Service.java
View file @
319e3660
package
edu
.
uchicago
.
mpcs
.
topics
.
service
;
import
edu.uchicago.mpcs.topics.auction.Item
;
import
edu.uchicago.mpcs.topics.auction.
Order
;
import
edu.uchicago.mpcs.topics.auction.
Checkout
;
import
edu.uchicago.mpcs.topics.auction.Status
;
import
edu.uchicago.mpcs.topics.db.ItemRepository
;
import
edu.uchicago.mpcs.topics.db.
Order
Repository
;
import
edu.uchicago.mpcs.topics.db.
Checkout
Repository
;
import
org.springframework.stereotype.Service
;
/**
...
...
@@ -12,26 +12,26 @@ import org.springframework.stereotype.Service;
*/
@Service
public
class
Order
Service
public
class
Checkout
Service
{
private
OrderRepository
order
Repository
;
private
CheckoutRepository
checkout
Repository
;
private
ItemRepository
itemRepository
;
public
OrderService
(
OrderRepository
order
Repository
,
ItemRepository
itemRepository
)
public
CheckoutService
(
CheckoutRepository
checkout
Repository
,
ItemRepository
itemRepository
)
{
this
.
orderRepository
=
order
Repository
;
this
.
checkoutRepository
=
checkout
Repository
;
}
//create an
order
public
Order
checkout
(
Order
order
)
//create an
checkout
public
Checkout
checkout
(
Checkout
checkout
)
{
//set item status as DELETED
for
(
Item
item
:
order
.
getItems
())
for
(
Item
item
:
checkout
.
getItems
())
{
item
.
setStatus
(
Status
.
DELETED
);
itemRepository
.
save
(
item
);
}
return
orderRepository
.
save
(
order
);
return
checkoutRepository
.
save
(
checkout
);
}
}
src/main/java/edu/uchicago/mpcs/topics/service/ItemService.java
View file @
319e3660
...
...
@@ -30,6 +30,8 @@ public class ItemService
public
Item
addItem
(
Item
item
)
{
//start timer
return
itemRepository
.
save
(
item
);
}
...
...
src/main/java/edu/uchicago/mpcs/topics/service/ShoppingCartService.java
View file @
319e3660
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.db.ItemRepository
;
import
edu.uchicago.mpcs.topics.db.ShoppingCartRepository
;
import
edu.uchicago.mpcs.topics.auction.ShoppingCart
;
...
...
@@ -38,10 +39,17 @@ public class ShoppingCartService
return
shoppingCartRepository
.
save
(
shoppingCart
);
}
public
ShoppingCart
checkout
(
ShoppingCart
shoppingCart
)
public
void
checkout
(
ShoppingCart
shoppingCart
)
{
//for each item in order delete item from shopping cart
return
shoppingCart
.
removeAllItems
();
//for each item in checkout, delete item from shopping cart
for
(
Item
item
:
shoppingCart
.
getItems
())
{
item
.
setStatus
(
Status
.
SOLD
);
itemRepository
.
save
(
item
);
}
//for each item in checkout, change Status to SOLD
shoppingCart
.
removeAllItems
();
}
}
\ No newline at end of file
target/classes/edu/uchicago/mpcs/topics/auction/Item.class
View file @
319e3660
No preview for this file type
target/classes/edu/uchicago/mpcs/topics/auction/Order.class
deleted
100644 → 0
View file @
6e241132
File deleted
target/classes/edu/uchicago/mpcs/topics/controller/ShoppingCartController.class
View file @
319e3660
No preview for this file type
target/classes/edu/uchicago/mpcs/topics/db/OrderRepository.class
deleted
100644 → 0
View file @
6e241132
File deleted
target/classes/edu/uchicago/mpcs/topics/service/OrderService.class
deleted
100644 → 0
View file @
6e241132
File deleted
target/h2db.trace.db
View file @
319e3660
...
...
@@ -306,6 +306,7 @@ create table order (order_id bigint not null, primary key (order_id)) [42001-197
2018-11-29 22:31:50 jdbc[3]: exception
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "ALTER TABLE ORDER_ITEM ADD CONSTRAINT FKT6WV8M7ESHKSP5KP8W4B2D1DM FOREIGN KEY (ORDER_ID) REFERENCES ORDER[*] "; expected "identifier"; SQL statement:
alter table order_item add constraint FKt6wv8m7eshksp5kp8w4b2d1dm foreign key (order_id) references order [42001-197]
<<<<<<< HEAD
2018-11-29 22:34:10 jdbc[3]: exception
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE ORDER[*] (ORDER_ID BIGINT NOT NULL, PRIMARY KEY (ORDER_ID)) "; expected "identifier"; SQL statement:
create table order (order_id bigint not null, primary key (order_id)) [42001-197]
...
...
@@ -430,5 +431,11 @@ alter table order_item add constraint FKt6wv8m7eshksp5kp8w4b2d1dm foreign key (o
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE ORDER[*] (ORDER_ID BIGINT NOT NULL, PRIMARY KEY (ORDER_ID)) "; expected "identifier"; SQL statement:
create table order (order_id bigint not null, primary key (order_id)) [42001-197]
2018-11-30 01:22:55 jdbc[3]: exception
=======
2018-11-29 23:25:00 jdbc[3]: exception
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE ORDER[*] (ORDER_ID BIGINT NOT NULL, PRIMARY KEY (ORDER_ID)) "; expected "identifier"; SQL statement:
create table order (order_id bigint not null, primary key (order_id)) [42001-197]
2018-11-29 23:25:00 jdbc[3]: exception
>>>>>>> daa0dcbbc727e502a532efb87adada5664278475
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "ALTER TABLE ORDER_ITEM ADD CONSTRAINT FKT6WV8M7ESHKSP5KP8W4B2D1DM FOREIGN KEY (ORDER_ID) REFERENCES ORDER[*] "; expected "identifier"; SQL statement:
alter table order_item add constraint FKt6wv8m7eshksp5kp8w4b2d1dm foreign key (order_id) references order [42001-197]
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