diff --git a/src/main/java/swg/controller/ClockController.java b/src/main/java/swg/controller/ClockController.java new file mode 100644 index 0000000..6f8dfcb --- /dev/null +++ b/src/main/java/swg/controller/ClockController.java @@ -0,0 +1,22 @@ +package swg.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import swg.entity.Clock; +import swg.service.ClockService; + +@CrossOrigin +@RestController +@RequestMapping("/api/clock") +public class ClockController { + @Autowired + ClockService clockService; + + @RequestMapping(value = "/lastSave", method = RequestMethod.GET) + public Clock getLastSaveTime() { + return clockService.getLastSaveTime().get(0); + } +} \ No newline at end of file diff --git a/src/main/java/swg/controller/MarketController.java b/src/main/java/swg/controller/MarketController.java new file mode 100644 index 0000000..ecfc5a9 --- /dev/null +++ b/src/main/java/swg/controller/MarketController.java @@ -0,0 +1,24 @@ +package swg.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import swg.entity.MarketAuction; +import swg.service.MarketAuctionService; + +import java.util.List; + +@CrossOrigin +@RestController +@RequestMapping("/api/market") +public class MarketController { + @Autowired + MarketAuctionService marketAuctionService; + + @RequestMapping(value = "/auctions", method = RequestMethod.GET) + public List getAllAuctions() { + return marketAuctionService.getAllActiveAuctions(); + } +} \ No newline at end of file diff --git a/src/main/java/swg/controller/ResourceTypeController.java b/src/main/java/swg/controller/ResourceTypeController.java index e735757..c3ce1d7 100644 --- a/src/main/java/swg/controller/ResourceTypeController.java +++ b/src/main/java/swg/controller/ResourceTypeController.java @@ -5,8 +5,8 @@ import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import swg.entity.ActiveResource; import swg.entity.ResourceType; +import swg.service.ClockService; import swg.service.ResourceTypeService; import java.util.List; @@ -17,6 +17,7 @@ import java.util.List; public class ResourceTypeController { @Autowired ResourceTypeService resourceTypeService; + ClockService clockService; @RequestMapping(value = "/historical/all", method = RequestMethod.GET) public List getAllResources() { @@ -24,7 +25,7 @@ public class ResourceTypeController { } @RequestMapping(value = "/current", method = RequestMethod.GET) - public List getSpawnedResources() { + public List getSpawnedResources() { return resourceTypeService.getSpawnedResources(); } } \ No newline at end of file diff --git a/src/main/java/swg/dao/ClockDao.java b/src/main/java/swg/dao/ClockDao.java new file mode 100644 index 0000000..562a0c7 --- /dev/null +++ b/src/main/java/swg/dao/ClockDao.java @@ -0,0 +1,9 @@ +package swg.dao; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import swg.entity.Clock; + +@Repository +public interface ClockDao extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/swg/dao/MarketAuctionDao.java b/src/main/java/swg/dao/MarketAuctionDao.java new file mode 100644 index 0000000..7a88834 --- /dev/null +++ b/src/main/java/swg/dao/MarketAuctionDao.java @@ -0,0 +1,12 @@ +package swg.dao; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import swg.entity.MarketAuction; + +import java.util.List; + +@Repository +public interface MarketAuctionDao extends JpaRepository { + public List findByActiveTrue(); +} \ No newline at end of file diff --git a/src/main/java/swg/dao/ResourceTypeDao.java b/src/main/java/swg/dao/ResourceTypeDao.java index 616981b..a8220d2 100644 --- a/src/main/java/swg/dao/ResourceTypeDao.java +++ b/src/main/java/swg/dao/ResourceTypeDao.java @@ -3,13 +3,12 @@ package swg.dao; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import swg.entity.ActiveResource; import swg.entity.ResourceType; import java.util.List; @Repository public interface ResourceTypeDao extends JpaRepository { - @Query(value = "SELECT * FROM active_resources_data", nativeQuery = true) - public List findAllSpawned(); + @Query(value = "SELECT resource_id, resource_name, resource_class, attributes, fractal_seeds, depleted_timestamp FROM resource_types, clock WHERE depleted_timestamp >= last_save_time", nativeQuery = true) + public List findAllSpawned(); } \ No newline at end of file diff --git a/src/main/java/swg/entity/ActiveResource.java b/src/main/java/swg/entity/ActiveResource.java deleted file mode 100644 index b6b186e..0000000 --- a/src/main/java/swg/entity/ActiveResource.java +++ /dev/null @@ -1,9 +0,0 @@ -package swg.entity; - -public interface ActiveResource { - Long getResource_id(); - String getResource_name(); - String getResource_class(); - String getAttribute_name(); - String getAttribute_value(); -} diff --git a/src/main/java/swg/entity/Clock.java b/src/main/java/swg/entity/Clock.java new file mode 100644 index 0000000..6af540d --- /dev/null +++ b/src/main/java/swg/entity/Clock.java @@ -0,0 +1,34 @@ +package swg.entity; + +import javax.persistence.*; +import java.sql.Timestamp; + +@Entity +@Table(name = "CLOCK") +public class Clock { + @Column(name = "LAST_SAVE_TIME", length = 38) + @Id + private Long lastSaveTime; + + @Column(name = "LAST_SAVE_TIMESTAMP") + private Timestamp lastSaveTimestamp; + + protected Clock() { + } + + public Long getLastSaveTime() { + return lastSaveTime; + } + + public void setLastSaveTime(Long lastSaveTime) { + this.lastSaveTime = lastSaveTime; + } + + public Timestamp getLastSaveTimestamp() { + return lastSaveTimestamp; + } + + public void setLastSaveTimestamp(Timestamp lastSaveTimestamp) { + this.lastSaveTimestamp = lastSaveTimestamp; + } +} diff --git a/src/main/java/swg/entity/MarketAuction.java b/src/main/java/swg/entity/MarketAuction.java new file mode 100644 index 0000000..c801db0 --- /dev/null +++ b/src/main/java/swg/entity/MarketAuction.java @@ -0,0 +1,177 @@ +package swg.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "MARKET_AUCTIONS") +public class MarketAuction { + @Column(name = "ITEM_ID") + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long itemId; + + @Column(name = "LOCATION_ID", nullable = true, length = 20) + private Long locationId; + + @Column(name = "CREATOR_ID", nullable = true, length = 20) + private Long creatorId; + + @Column(name = "OWNER_ID", nullable = true, length = 20) + private Long ownerId; + + @Column(name = "MIN_BID", nullable = true, length = 20) + private Long minimumBid; + + @Column(name = "BUY_NOW_PRICE", nullable = true, length = 20) + private Long buyNowPrice; + + @Column(name = "AUCTION_TIMER", nullable = true, length = 20) + private Long auctionTimer; + + @Column(name = "USER_DESCRIPTION", nullable = true, length = 4000) + private String userDescription; + + @Column(name = "ITEM_NAME", nullable = true, length = 4000) + private String itemName; + + @Column(name = "OOB", nullable = true, length = 4000) + private String oob; + + @Column(name = "CATEGORY", nullable = true, length = 20) + private Long category; + + @Column(name = "ITEM_TIMER", nullable = true, length = 20) + private Long itemTimer; + + @Column(name = "ACTIVE", nullable = true) + private Boolean active; + + @Column(name = "ITEM_SIZE", length = 20) + private Long itemSize; + + @Column(name = "OBJECT_TEMPLATE_ID", nullable = true, length = 38) + private Long objectTemplateId; + + protected MarketAuction() { + } + + public Long getItemId() { + return itemId; + } + + public void setItemId(Long itemId) { + this.itemId = itemId; + } + + public Long getLocationId() { + return locationId; + } + + public void setLocationId(Long locationId) { + this.locationId = locationId; + } + + public Long getCreatorId() { + return creatorId; + } + + public void setCreatorId(Long creatorId) { + this.creatorId = creatorId; + } + + public Long getOwnerId() { + return ownerId; + } + + public void setOwnerId(Long ownerId) { + this.ownerId = ownerId; + } + + public Long getMinimumBid() { + return minimumBid; + } + + public void setMinimumBid(Long minimumBid) { + this.minimumBid = minimumBid; + } + + public Long getBuyNowPrice() { + return buyNowPrice; + } + + public void setBuyNowPrice(Long buyNowPrice) { + this.buyNowPrice = buyNowPrice; + } + + public Long getAuctionTimer() { + return auctionTimer; + } + + public void setAuctionTimer(Long auctionTimer) { + this.auctionTimer = auctionTimer; + } + + public String getUserDescription() { + return userDescription; + } + + public void setUserDescription(String userDescription) { + this.userDescription = userDescription; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public String getOob() { + return oob; + } + + public void setOob(String oob) { + this.oob = oob; + } + + public Long getCategory() { + return category; + } + + public void setCategory(Long category) { + this.category = category; + } + + public Long getItemTimer() { + return itemTimer; + } + + public void setItemTimer(Long itemTimer) { + this.itemTimer = itemTimer; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + + public Long getItemSize() { + return itemSize; + } + + public void setItemSize(Long itemSize) { + this.itemSize = itemSize; + } + + public Long getObjectTemplateId() { + return objectTemplateId; + } + + public void setObjectTemplateId(Long objectTemplateId) { + this.objectTemplateId = objectTemplateId; + } +} diff --git a/src/main/java/swg/entity/ResourceType.java b/src/main/java/swg/entity/ResourceType.java index 47dfb27..a0e6263 100644 --- a/src/main/java/swg/entity/ResourceType.java +++ b/src/main/java/swg/entity/ResourceType.java @@ -22,7 +22,7 @@ public class ResourceType { @Column(name = "FRACTAL_SEEDS", nullable = true, length = 1024) private String fractalSeeds; - @Column(name = "DEPLETED_TIMESTAMP", nullable = true, length = 38) + @Column(name = "DEPLETED_TIMESTAMP", length = 38) private Long depletedTimestamp; protected ResourceType() { diff --git a/src/main/java/swg/service/ClockService.java b/src/main/java/swg/service/ClockService.java new file mode 100644 index 0000000..531258d --- /dev/null +++ b/src/main/java/swg/service/ClockService.java @@ -0,0 +1,18 @@ +package swg.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import swg.dao.ClockDao; +import swg.entity.Clock; + +import java.util.List; + +@Service +public class ClockService { + @Autowired + ClockDao clockDao; + + public List getLastSaveTime() { + return this.clockDao.findAll(); + } +} \ No newline at end of file diff --git a/src/main/java/swg/service/MarketAuctionService.java b/src/main/java/swg/service/MarketAuctionService.java new file mode 100644 index 0000000..5f94871 --- /dev/null +++ b/src/main/java/swg/service/MarketAuctionService.java @@ -0,0 +1,21 @@ +package swg.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import swg.dao.MarketAuctionDao; +import swg.entity.MarketAuction; + +import java.util.List; + +@Service +public class MarketAuctionService { + @Autowired + MarketAuctionDao marketAuctionDao; + + public List getAllAuctions() { + return marketAuctionDao.findAll(); + } + public List getAllActiveAuctions() { + return marketAuctionDao.findByActiveTrue(); + } +} \ No newline at end of file diff --git a/src/main/java/swg/service/ResourceTypeService.java b/src/main/java/swg/service/ResourceTypeService.java index 4a1508b..4e51cd6 100644 --- a/src/main/java/swg/service/ResourceTypeService.java +++ b/src/main/java/swg/service/ResourceTypeService.java @@ -2,7 +2,6 @@ package swg.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import swg.entity.ActiveResource; import swg.dao.ResourceTypeDao; import swg.entity.ResourceType; @@ -16,7 +15,7 @@ public class ResourceTypeService { public List getAllResources() { return this.resourceTypeDao.findAll(); } - public List getSpawnedResources() { + public List getSpawnedResources() { return this.resourceTypeDao.findAllSpawned(); } } \ No newline at end of file