diff --git a/src/dataservice/src/main/java/io/daocloud/dataservice/MockDataCommandLineRunner.java b/src/dataservice/src/main/java/io/daocloud/dataservice/MockDataCommandLineRunner.java index b32008970b..68ed9432b6 100644 --- a/src/dataservice/src/main/java/io/daocloud/dataservice/MockDataCommandLineRunner.java +++ b/src/dataservice/src/main/java/io/daocloud/dataservice/MockDataCommandLineRunner.java @@ -1,7 +1,7 @@ package io.daocloud.dataservice; -import io.daocloud.dataservice.entity.Advertise; -import io.daocloud.dataservice.repository.AdvertiseRepository; +import io.daocloud.dataservice.entity.Ad; +import io.daocloud.dataservice.repository.AdRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; @@ -14,55 +14,55 @@ class MockDataCommandLineRunner implements CommandLineRunner { Logger logger = LoggerFactory.getLogger(MockDataCommandLineRunner.class); - private final AdvertiseRepository advertiseRepository; + private final AdRepository adRepository; - public MockDataCommandLineRunner(final AdvertiseRepository advertiseRepository) { - this.advertiseRepository = advertiseRepository; + public MockDataCommandLineRunner(final AdRepository adRepository) { + this.adRepository = adRepository; } @Override public void run(String... args) throws Exception { - Advertise ad = new Advertise(); + Ad ad = new Ad(); ad.setAdKey("binoculars"); ad.setRedirectURL("/product/2ZYFJ3GM2N"); ad.setContent("Roof Binoculars for sale. 50% off."); - advertiseRepository.save(ad); + adRepository.save(ad); - ad = new Advertise(); + ad = new Ad(); ad.setAdKey("telescopes"); ad.setRedirectURL("/product/66VCHSJNUP"); ad.setContent("Starsense Explorer Refractor Telescope for sale. 20% off."); - advertiseRepository.save(ad); + adRepository.save(ad); - ad = new Advertise(); + ad = new Ad(); ad.setAdKey("accessories"); ad.setRedirectURL("/product/0PUK6V6EV0"); ad.setContent("Solar System Color Imager for sale. 30% off."); - advertiseRepository.save(ad); + adRepository.save(ad); - ad = new Advertise(); + ad = new Ad(); ad.setAdKey("accessories"); ad.setRedirectURL("/product/6E92ZMYYFZ"); ad.setContent("Solar Filter for sale. Buy two, get third one for free"); - advertiseRepository.save(ad); + adRepository.save(ad); - ad = new Advertise(); + ad = new Ad(); ad.setAdKey("accessories"); ad.setRedirectURL("/product/L9ECAV7KIM"); ad.setContent("Lens Cleaning Kit for sale. Buy one, get second one for free"); - advertiseRepository.save(ad); + adRepository.save(ad); - ad = new Advertise(); + ad = new Ad(); ad.setAdKey("assembly"); ad.setRedirectURL("/product/9SIQT8TOJO"); ad.setContent("Optical Tube Assembly for sale. 10% off."); - advertiseRepository.save(ad); + adRepository.save(ad); - ad = new Advertise(); + ad = new Ad(); ad.setAdKey("travel"); ad.setRedirectURL("/product/1YMWWN1N4O"); ad.setContent("Eclipsmart Travel Refractor Telescope for sale. Buy one, get second kit for free"); - advertiseRepository.save(ad); + adRepository.save(ad); logger.info("init data success."); } diff --git a/src/dataservice/src/main/java/io/daocloud/dataservice/controller/AdvertiseController.java b/src/dataservice/src/main/java/io/daocloud/dataservice/controller/DataserviceController.java similarity index 61% rename from src/dataservice/src/main/java/io/daocloud/dataservice/controller/AdvertiseController.java rename to src/dataservice/src/main/java/io/daocloud/dataservice/controller/DataserviceController.java index 43e015d496..1bf98dde44 100644 --- a/src/dataservice/src/main/java/io/daocloud/dataservice/controller/AdvertiseController.java +++ b/src/dataservice/src/main/java/io/daocloud/dataservice/controller/DataserviceController.java @@ -1,7 +1,7 @@ package io.daocloud.dataservice.controller; -import io.daocloud.dataservice.entity.Advertise; -import io.daocloud.dataservice.repository.AdvertiseRepository; +import io.daocloud.dataservice.entity.Ad; +import io.daocloud.dataservice.repository.AdRepository; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Controller; @@ -14,44 +14,44 @@ @Controller // This means that this class is a Controller @RequestMapping(path = "/ad") // This means URL's start with /ad (after Application path) -public class AdvertiseController { +public class DataserviceController { - private static final Logger logger = LogManager.getLogger(AdvertiseController.class); - private AdvertiseRepository advertiseRepository; + private static final Logger logger = LogManager.getLogger(DataserviceController.class); + private AdRepository adRepository; - public AdvertiseController(final AdvertiseRepository advertiseRepository) { - this.advertiseRepository = advertiseRepository; + public DataserviceController(final AdRepository adRepository) { + this.adRepository = adRepository; } @PostMapping(path = "/add") // Map ONLY POST Requests public @ResponseBody String addNewUser(@RequestParam String redirectURL, @RequestParam String content) { - Advertise n = new Advertise(); + Ad n = new Ad(); n.setRedirectURL(redirectURL); n.setContent(content); - advertiseRepository.save(n); + adRepository.save(n); return "Saved"; } @GetMapping(path = "/all") @ResponseBody - public Iterable getAllAds() { + public Iterable getAllAds() { // This returns a JSON or XML with the users - return advertiseRepository.findAll(); + return adRepository.findAll(); } @GetMapping(path = "/id/{id}") @ResponseBody - public Advertise getAdById(@PathVariable("id") int id) { + public Ad getAdById(@PathVariable("id") int id) { // This returns a JSON or XML with the users - return advertiseRepository.findById(id).orElse(new Advertise()); + return adRepository.findById(id).orElse(new Ad()); } @GetMapping(path = "/ad-key/{adKey}") @ResponseBody - public Iterable findAdvertiseByAdKey(@PathVariable("adKey") String adKey){ + public Iterable findAdvertiseByAdKey(@PathVariable("adKey") String adKey){ // This returns a JSON or XML with the users logger.info("received ad request (context_words=" + adKey + ")"); - return advertiseRepository.findByAdKey(adKey); + return adRepository.findByAdKey(adKey); } } diff --git a/src/dataservice/src/main/java/io/daocloud/dataservice/entity/Advertise.java b/src/dataservice/src/main/java/io/daocloud/dataservice/entity/Ad.java similarity index 97% rename from src/dataservice/src/main/java/io/daocloud/dataservice/entity/Advertise.java rename to src/dataservice/src/main/java/io/daocloud/dataservice/entity/Ad.java index f707c55ef8..82ed11429c 100644 --- a/src/dataservice/src/main/java/io/daocloud/dataservice/entity/Advertise.java +++ b/src/dataservice/src/main/java/io/daocloud/dataservice/entity/Ad.java @@ -6,7 +6,7 @@ import javax.persistence.Id; @Entity // This tells Hibernate to make a table out of this class -public class Advertise { +public class Ad { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; diff --git a/src/dataservice/src/main/java/io/daocloud/dataservice/repository/AdvertiseRepository.java b/src/dataservice/src/main/java/io/daocloud/dataservice/repository/AdRepository.java similarity index 58% rename from src/dataservice/src/main/java/io/daocloud/dataservice/repository/AdvertiseRepository.java rename to src/dataservice/src/main/java/io/daocloud/dataservice/repository/AdRepository.java index c80df0f508..f60f22ecd4 100644 --- a/src/dataservice/src/main/java/io/daocloud/dataservice/repository/AdvertiseRepository.java +++ b/src/dataservice/src/main/java/io/daocloud/dataservice/repository/AdRepository.java @@ -1,11 +1,11 @@ package io.daocloud.dataservice.repository; -import io.daocloud.dataservice.entity.Advertise; +import io.daocloud.dataservice.entity.Ad; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; // This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository // CRUD refers Create, Read, Update, Delete -public interface AdvertiseRepository extends CrudRepository { - Iterable findByAdKey(@Param("adKey") String adKey); +public interface AdRepository extends CrudRepository { + Iterable findByAdKey(@Param("adKey") String adKey); }