1
0
mirror of https://github.com/cekis/swg-api synced 2026-01-16 19:05:10 -05:00

Added Resources and Commodities

This commit is contained in:
Cekis
2021-05-05 22:20:14 -07:00
parent 015f821137
commit 08c7037fe0
13 changed files with 324 additions and 17 deletions

View File

@@ -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);
}
}

View File

@@ -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<MarketAuction> getAllAuctions() {
return marketAuctionService.getAllActiveAuctions();
}
}

View File

@@ -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<ResourceType> getAllResources() {
@@ -24,7 +25,7 @@ public class ResourceTypeController {
}
@RequestMapping(value = "/current", method = RequestMethod.GET)
public List<ActiveResource> getSpawnedResources() {
public List<ResourceType> getSpawnedResources() {
return resourceTypeService.getSpawnedResources();
}
}

View File

@@ -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<Clock, Integer> {
}

View File

@@ -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<MarketAuction, Integer> {
public List<MarketAuction> findByActiveTrue();
}

View File

@@ -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<ResourceType, Integer> {
@Query(value = "SELECT * FROM active_resources_data", nativeQuery = true)
public List<ActiveResource> 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<ResourceType> findAllSpawned();
}

View File

@@ -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();
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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() {

View File

@@ -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<Clock> getLastSaveTime() {
return this.clockDao.findAll();
}
}

View File

@@ -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<MarketAuction> getAllAuctions() {
return marketAuctionDao.findAll();
}
public List<MarketAuction> getAllActiveAuctions() {
return marketAuctionDao.findByActiveTrue();
}
}

View File

@@ -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<ResourceType> getAllResources() {
return this.resourceTypeDao.findAll();
}
public List<ActiveResource> getSpawnedResources() {
public List<ResourceType> getSpawnedResources() {
return this.resourceTypeDao.findAllSpawned();
}
}