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
4951df1d
authored
Nov 18, 2018
by
Bright Sukumpanumet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Bid ItemCategory and related. Use JPA and Apache Derby for now.
parent
720f5987
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
183 additions
and
149 deletions
pom.xml
src/main/java/edu/uchicago/mpcs/topics/MoviesCreateTable.java
src/main/java/edu/uchicago/mpcs/topics/MoviesLoadData.java
src/main/java/edu/uchicago/mpcs/topics/auction/Bid.java
src/main/java/edu/uchicago/mpcs/topics/auction/Item.java
src/main/java/edu/uchicago/mpcs/topics/auction/ItemCategory.java
src/main/java/edu/uchicago/mpcs/topics/controller/BidController.java
src/main/java/edu/uchicago/mpcs/topics/controller/ItemController.java
src/main/java/edu/uchicago/mpcs/topics/db/BidRepository.java
src/main/java/edu/uchicago/mpcs/topics/db/ItemRepository.java
src/main/java/edu/uchicago/mpcs/topics/service/BidService.java
src/main/java/edu/uchicago/mpcs/topics/service/ItemService.java
pom.xml
View file @
4951df1d
...
...
@@ -65,6 +65,15 @@
<artifactId>
DynamoDBLocal
</artifactId>
<version>
RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.derby
</groupId>
<artifactId>
derby
</artifactId>
<scope>
runtime
</scope>
</dependency>
</dependencies>
<repositories>
<repository>
...
...
src/main/java/edu/uchicago/mpcs/topics/MoviesCreateTable.java
deleted
100644 → 0
View file @
720f5987
package
edu
.
uchicago
.
mpcs
.
topics
;
/**
* Created by Bright on 2018-11-17.
*/
import
java.util.Arrays
;
//import com.amazonaws.client.builder.AwsClientBuilder;
import
com.amazonaws.regions.Regions
;
import
com.amazonaws.services.dynamodbv2.AmazonDynamoDB
;
import
com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
;
import
com.amazonaws.services.dynamodbv2.document.DynamoDB
;
import
com.amazonaws.services.dynamodbv2.document.Table
;
import
com.amazonaws.services.dynamodbv2.model.AttributeDefinition
;
import
com.amazonaws.services.dynamodbv2.model.KeySchemaElement
;
import
com.amazonaws.services.dynamodbv2.model.KeyType
;
import
com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput
;
import
com.amazonaws.services.dynamodbv2.model.ScalarAttributeType
;
public
class
MoviesCreateTable
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
AmazonDynamoDB
client
=
AmazonDynamoDBClientBuilder
.
standard
()
.
withRegion
(
Regions
.
US_WEST_2
).
build
();
DynamoDB
dynamoDB
=
new
DynamoDB
(
client
);
String
tableName
=
"Movies"
;
try
{
System
.
out
.
println
(
"Attempting to create table; please wait..."
);
Table
table
=
dynamoDB
.
createTable
(
tableName
,
Arrays
.
asList
(
new
KeySchemaElement
(
"year"
,
KeyType
.
HASH
),
// Partition
// key
new
KeySchemaElement
(
"title"
,
KeyType
.
RANGE
)),
// Sort key
Arrays
.
asList
(
new
AttributeDefinition
(
"year"
,
ScalarAttributeType
.
N
),
new
AttributeDefinition
(
"title"
,
ScalarAttributeType
.
S
)),
new
ProvisionedThroughput
(
10L
,
10L
));
table
.
waitForActive
();
System
.
out
.
println
(
"Success. Table status: "
+
table
.
getDescription
().
getTableStatus
());
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"Unable to create table: "
);
System
.
err
.
println
(
e
.
getMessage
());
}
}
}
\ No newline at end of file
src/main/java/edu/uchicago/mpcs/topics/MoviesLoadData.java
deleted
100644 → 0
View file @
720f5987
package
edu
.
uchicago
.
mpcs
.
topics
;
/**
* Created by Bright on 2018-11-17.
*/
import
java.io.File
;
import
java.util.Iterator
;
import
com.amazonaws.client.builder.AwsClientBuilder
;
import
com.amazonaws.regions.Regions
;
import
com.amazonaws.services.dynamodbv2.AmazonDynamoDB
;
import
com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
;
import
com.amazonaws.services.dynamodbv2.document.DynamoDB
;
import
com.amazonaws.services.dynamodbv2.document.Item
;
import
com.amazonaws.services.dynamodbv2.document.Table
;
import
com.fasterxml.jackson.core.JsonFactory
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
public
class
MoviesLoadData
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
AmazonDynamoDB
client
=
AmazonDynamoDBClientBuilder
.
standard
()
.
withRegion
(
Regions
.
US_WEST_2
).
build
();
DynamoDB
dynamoDB
=
new
DynamoDB
(
client
);
Table
table
=
dynamoDB
.
getTable
(
"Movies"
);
JsonParser
parser
=
new
JsonFactory
().
createParser
(
new
File
(
"moviedata.json"
));
JsonNode
rootNode
=
new
ObjectMapper
().
readTree
(
parser
);
Iterator
<
JsonNode
>
iter
=
rootNode
.
iterator
();
ObjectNode
currentNode
;
while
(
iter
.
hasNext
())
{
currentNode
=
(
ObjectNode
)
iter
.
next
();
int
year
=
currentNode
.
path
(
"year"
).
asInt
();
String
title
=
currentNode
.
path
(
"title"
).
asText
();
try
{
table
.
putItem
(
new
Item
().
withPrimaryKey
(
"year"
,
year
,
"title"
,
title
).
withJSON
(
"info"
,
currentNode
.
path
(
"info"
).
toString
()));
System
.
out
.
println
(
"PutItem succeeded: "
+
year
+
" "
+
title
);
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"Unable to add movie: "
+
year
+
" "
+
title
);
System
.
err
.
println
(
e
.
getMessage
());
break
;
}
}
parser
.
close
();
}
}
\ No newline at end of file
src/main/java/edu/uchicago/mpcs/topics/auction/Bid.java
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
auction
;
import
edu.uchicago.mpcs.topics.user.Buyer
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
java.util.Date
;
public
class
Bid
{
private
String
id
;
private
Listing
listing
;
private
double
price
;
private
Buyer
buyer
;
@Entity
public
class
Bid
{
@Id
private
String
userId
;
private
long
amount
;
private
String
itemId
;
private
Date
time
;
public
String
getId
()
{
return
id
;
public
Bid
(
String
userId
,
long
amount
,
String
itemId
,
Date
time
)
{
this
.
userId
=
userId
;
this
.
amount
=
amount
;
this
.
itemId
=
itemId
;
this
.
time
=
time
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
public
String
getUserId
()
{
return
userId
;
}
public
Listing
getListing
()
{
return
listing
;
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
void
setListing
(
Listing
listing
)
{
this
.
listing
=
listing
;
public
long
getAmount
()
{
return
amount
;
}
public
double
getPrice
()
{
return
price
;
public
void
setAmount
(
long
amount
)
{
this
.
amount
=
amount
;
}
public
void
setPrice
(
double
price
)
{
this
.
price
=
price
;
public
String
getItemId
()
{
return
itemId
;
}
public
Buyer
getBuyer
()
{
return
buyer
;
public
void
setItemId
(
String
itemId
)
{
this
.
itemId
=
itemId
;
}
public
void
setBuyer
(
Buyer
buyer
)
{
this
.
buyer
=
buyer
;
public
Date
getTime
()
{
return
time
;
}
public
void
setTime
(
Date
time
)
{
this
.
time
=
time
;
}
}
src/main/java/edu/uchicago/mpcs/topics/auction/Item.java
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
auction
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
public
class
Item
{
@Entity
public
class
Item
{
@Id
private
String
itemId
;
private
String
title
;
private
String
description
;
...
...
src/main/java/edu/uchicago/mpcs/topics/auction/ItemCategory.java
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
auction
;
public
class
ItemCategory
{
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
@Entity
public
class
ItemCategory
{
@Id
private
String
ItemCategoryId
;
public
ItemCategory
(
String
itemCategoryId
)
{
ItemCategoryId
=
itemCategoryId
;
}
public
String
getItemCategoryId
()
{
return
ItemCategoryId
;
}
public
void
setItemCategoryId
(
String
itemCategoryId
)
{
ItemCategoryId
=
itemCategoryId
;
}
}
src/main/java/edu/uchicago/mpcs/topics/controller/BidController.java
0 → 100644
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
controller
;
import
edu.uchicago.mpcs.topics.auction.Bid
;
import
edu.uchicago.mpcs.topics.service.BidService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* Created by Bright on 2018-11-18.
*/
@RestController
@RequestMapping
(
"/bid"
)
public
class
BidController
{
@Autowired
private
BidService
bidService
;
@PostMapping
public
void
addItem
(
@RequestBody
Bid
bid
)
{
bidService
.
addBid
(
bid
);
}
}
\ No newline at end of file
src/main/java/edu/uchicago/mpcs/topics/controller/ItemController.java
View file @
4951df1d
...
...
@@ -30,9 +30,15 @@ public class ItemController
itemService
.
addItem
(
item
);
}
// @DeleteMapping("/remove")
// public void removeItem(@RequestBody )
//
// @RequestMapping("/update")
@DeleteMapping
(
"/remove"
)
public
void
removeItem
(
@RequestBody
Item
item
)
//or change to item ID
{
itemService
.
deleteItem
(
item
.
getItemId
());
}
}
@PutMapping
(
"/update"
)
public
void
updateItem
(
@RequestBody
Item
item
)
{
itemService
.
updateItem
(
item
);
}
}
\ No newline at end of file
src/main/java/edu/uchicago/mpcs/topics/db/BidRepository.java
0 → 100644
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
db
;
import
edu.uchicago.mpcs.topics.auction.Bid
;
import
org.springframework.data.repository.CrudRepository
;
/**
* Created by Bright on 2018-11-18.
*/
public
interface
BidRepository
extends
CrudRepository
<
Bid
,
String
>
{
}
src/main/java/edu/uchicago/mpcs/topics/db/ItemRepository.java
0 → 100644
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
db
;
import
edu.uchicago.mpcs.topics.auction.Item
;
import
org.springframework.data.repository.CrudRepository
;
/**
* Created by Bright on 2018-11-17.
*/
public
interface
ItemRepository
extends
CrudRepository
<
Item
,
String
>
{
}
src/main/java/edu/uchicago/mpcs/topics/service/BidService.java
0 → 100644
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
service
;
import
edu.uchicago.mpcs.topics.auction.Bid
;
import
edu.uchicago.mpcs.topics.db.BidRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* Created by Bright on 2018-11-18.
*/
@Service
public
class
BidService
{
@Autowired
private
BidRepository
bidRepository
;
public
void
addBid
(
Bid
bid
)
{
bidRepository
.
save
(
bid
);
}
}
src/main/java/edu/uchicago/mpcs/topics/service/ItemService.java
View file @
4951df1d
package
edu
.
uchicago
.
mpcs
.
topics
.
service
;
import
edu.uchicago.mpcs.topics.auction.Item
;
import
edu.uchicago.mpcs.topics.db.ItemRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
...
...
@@ -14,29 +16,34 @@ import java.util.List;
@Service
public
class
ItemService
{
private
List
<
Item
>
items
=
new
ArrayList
<>(
Arrays
.
asList
(
new
Item
(
"1"
,
"Sun glasses"
,
"Red sun glasses"
,
"1"
,
500
,
1000
,
""
,
""
),
new
Item
(
"2"
,
"Mouse"
,
"clicky"
,
"1"
,
100
,
1300
,
""
,
""
)
));
@Autowired
private
ItemRepository
itemRepository
;
//adding example items
// private List<Item> items = new ArrayList<>(Arrays.asList(
// new Item("1", "Sun glasses", "Red sun glasses", "1", 500, 1000, "",""),
// new Item("2", "Mouse", "clickkkkz", "1", 100, 1300, "","")
// ));
public
List
<
Item
>
getAllItems
()
{
List
<
Item
>
items
=
new
ArrayList
<>();
itemRepository
.
findAll
().
forEach
(
items:
:
add
);
return
items
;
}
public
void
addItem
(
Item
item
)
{
item
s
.
add
(
item
);
item
Repository
.
save
(
item
);
}
public
void
deleteItem
(
String
id
)
{
itemRepository
.
deleteById
(
id
);
}
public
void
updateItem
(
String
id
)
public
void
updateItem
(
Item
item
)
{
itemRepository
.
save
(
item
);
}
}
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