Commit fefd6e45 by Bright Sukumpanumet

Add Search function

Add API list
Remove userId from constructor
parent 1dbfbfbf
ITEM
View an item : GET .../item/{id} e.g. .../item/1
View all items : GET .../item/list
Add an item : POST .../item/add @RequestBody Item
Delete an item : DELETE .../item/{id}
EDIT an item : PUT .../item/update @RequestBody Item
Search items : GET .../item/search/{q}
BID
Add bid : POST .../bid @RequestBody Bid
(let me know if you want to change to ..../item/{id}/bid
SHOPPING CART
(shoppingcart ID is the same as user ID. e.g. user 1 has shoppingcart/1/
View cart : GET .../shoppingcart/{id}
Add item to cart : POST .../shoppingcart/{id}/add_item @RequestBody Item
Checkout : POST .../shoppingcart/{id}/checkout @RequestBody Checkout
(Checkout class contains just a list of item { "items" : [item, item item]}, let me know if you want to change this)
Remove item - I disable it for now because we don't user winning the bid to remove item
\ No newline at end of file
...@@ -35,15 +35,15 @@ public class Application { ...@@ -35,15 +35,15 @@ public class Application {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
// @Bean @Bean
// CommandLineRunner initData(UserDB userDB) { CommandLineRunner initData(UserDB userDB) {
// return args -> { return args -> {
// userDB.save(new User("111", "wawa", "rex", "wawa", "rex@gmail.com", true)); userDB.save(new User("wawa", "rex", "wawa", "rex@gmail.com", true));
// userDB.save(new User("222", "wawa", "haoh", "wawa", "hao@gmail.com", true)); userDB.save(new User("wawa", "haoh", "wawa", "hao@gmail.com", true));
// userDB.save(new User("333", "wawa", "nella", "wawa", "nella@gmail.com", true)); userDB.save(new User("wawa", "nella", "wawa", "nella@gmail.com", true));
// userDB.save(new User("444", "wawa", "bright", "wawa", "bright@gmail.com", true)); userDB.save(new User("wawa", "bright", "wawa", "bright@gmail.com", true));
// }; };
// } }
// @Bean // @Bean
// public WebMvcConfigurer corsConfigurer() { // public WebMvcConfigurer corsConfigurer() {
......
...@@ -36,11 +36,11 @@ public class TimeTracker ...@@ -36,11 +36,11 @@ public class TimeTracker
Duration durationStart = Duration.between(startTime, currentTime); Duration durationStart = Duration.between(startTime, currentTime);
ScheduledExecutorService startTimer = Executors.newSingleThreadScheduledExecutor(); ScheduledExecutorService startTimer = Executors.newSingleThreadScheduledExecutor();
startTimer.schedule(() -> timeStart(), durationStart.getSeconds(), TimeUnit.SECONDS); startTimer.schedule(this::timeStart, durationStart.getSeconds(), TimeUnit.SECONDS);
Duration durationEnd = Duration.between(startTime, endTime); Duration durationEnd = Duration.between(startTime, endTime);
ScheduledExecutorService endTimer = Executors.newSingleThreadScheduledExecutor(); ScheduledExecutorService endTimer = Executors.newSingleThreadScheduledExecutor();
endTimer.schedule(() -> timeEnd(), durationEnd.getSeconds(), TimeUnit.SECONDS); endTimer.schedule(this::timeEnd, durationEnd.getSeconds(), TimeUnit.SECONDS);
} }
private void timeStart() private void timeStart()
......
package edu.uchicago.mpcs.topics.auction;
/**
* Created by Bright on 2018-11-30.
*/
public class Watchlist
{
}
...@@ -3,6 +3,7 @@ package edu.uchicago.mpcs.topics.controller; ...@@ -3,6 +3,7 @@ package edu.uchicago.mpcs.topics.controller;
import edu.uchicago.mpcs.topics.auction.Item; import edu.uchicago.mpcs.topics.auction.Item;
import edu.uchicago.mpcs.topics.auction.Status; import edu.uchicago.mpcs.topics.auction.Status;
import edu.uchicago.mpcs.topics.db.ItemRepository; import edu.uchicago.mpcs.topics.db.ItemRepository;
import edu.uchicago.mpcs.topics.db.SearchRepository;
import edu.uchicago.mpcs.topics.service.ItemService; import edu.uchicago.mpcs.topics.service.ItemService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -19,11 +20,13 @@ public class ItemController ...@@ -19,11 +20,13 @@ public class ItemController
{ {
private ItemService itemService; private ItemService itemService;
private ItemRepository itemRepository; private ItemRepository itemRepository;
private SearchRepository searchRepository;
public ItemController(ItemService itemService, ItemRepository itemRepository) public ItemController(ItemService itemService, ItemRepository itemRepository, SearchRepository searchRepository)
{ {
this.itemService = itemService; this.itemService = itemService;
this.itemRepository = itemRepository; this.itemRepository = itemRepository;
this.searchRepository = searchRepository;
} }
@GetMapping @GetMapping
...@@ -63,9 +66,9 @@ public class ItemController ...@@ -63,9 +66,9 @@ public class ItemController
return itemRepository.save(item); return itemRepository.save(item);
} }
@PostMapping("/flag") @GetMapping("/search/{q}")
public Item flagItem(@RequestBody Item item) public List<Item> searchItem(@PathVariable String q)
{ {
return itemRepository.save(item); return searchRepository.findAllByDescriptionContains(q);
} }
} }
\ No newline at end of file
package edu.uchicago.mpcs.topics.controller;
import edu.uchicago.mpcs.topics.auction.ItemCategory;
//import edu.uchicago.mpcs.topics.auction.Listing;
import org.hibernate.query.Query;
import java.util.List;
public interface SearchController {
// List<Listing> search(Query query);
// List<Listing> search(ItemCategory itemCategory);
}
//package edu.uchicago.mpcs.topics.controller;
//
//import edu.uchicago.mpcs.topics.auction.ItemCategory;
//import org.springframework.data.jpa.repository.Query;
//
//
//import java.util.List;
//
//public interface SearchController {
// List<Listing> search(Query query);
// List<Listing> search(ItemCategory itemCategory);
//}
...@@ -3,6 +3,7 @@ package edu.uchicago.mpcs.topics.db; ...@@ -3,6 +3,7 @@ package edu.uchicago.mpcs.topics.db;
import edu.uchicago.mpcs.topics.auction.Item; import edu.uchicago.mpcs.topics.auction.Item;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import javax.persistence.Id; import javax.persistence.Id;
import javax.swing.text.html.HTMLDocument;
/** /**
* Created by Bright on 2018-11-17. * Created by Bright on 2018-11-17.
......
package edu.uchicago.mpcs.topics.db;
import edu.uchicago.mpcs.topics.auction.Item;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* Created by Bright on 2018-11-17.
*/
public interface SearchRepository extends CrudRepository<Item, String>
{
List<Item> findAllByDescriptionContains(String keyword);
}
...@@ -10,7 +10,7 @@ import javax.persistence.Entity; ...@@ -10,7 +10,7 @@ import javax.persistence.Entity;
@ Entity @ Entity
public class Admin extends User { public class Admin extends User {
public Admin(Long userId, String password, String firstName, String lastName, String email, boolean isAdmin) { public Admin(String password, String firstName, String lastName, String email, boolean isAdmin) {
super(userId, password, firstName, lastName, email, true); super(password, firstName, lastName, email, true);
} }
} }
...@@ -9,7 +9,7 @@ import javax.persistence.Entity; ...@@ -9,7 +9,7 @@ import javax.persistence.Entity;
@Entity @Entity
public class Buyer extends User { public class Buyer extends User {
public Buyer(Long userId, String password, String firstName, String lastName, String email, boolean isAdmin) { public Buyer(String password, String firstName, String lastName, String email, boolean isAdmin) {
super(userId, password, firstName, lastName, email, false); super(password, firstName, lastName, email, false);
} }
} }
...@@ -8,7 +8,7 @@ import javax.persistence.Entity; ...@@ -8,7 +8,7 @@ import javax.persistence.Entity;
@Entity @Entity
public class Seller extends User { public class Seller extends User {
public Seller(Long userId, String password, String firstName, String lastName, String email, boolean isAdmin) { public Seller(String password, String firstName, String lastName, String email, boolean isAdmin) {
super(userId, password, firstName, lastName, email, false); super(password, firstName, lastName, email, false);
} }
} }
...@@ -41,7 +41,7 @@ public class User { ...@@ -41,7 +41,7 @@ public class User {
public User() {} public User() {}
public User(Long userId, String password, String firstName, String lastName, String email, boolean isAdmin) public User(String password, String firstName, String lastName, String email, boolean isAdmin)
{ {
this.userId = userId; this.userId = userId;
this.password = password; this.password = password;
......
spring.data.rest.base-path=/api spring.data.rest.base-path=/api
spring.h2.console.enabled=true spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto = update #spring.jpa.hibernate.ddl-auto = update
spring.datasource.url=jdbc:h2:file:./target/h2db;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE #spring.datasource.url=jdbc:h2:file:./target/h2db;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
spring.datasource.driver-class-name=org.h2.Driver #spring.datasource.driver-class-name=org.h2.Driver
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment