Skip to content

Commit

Permalink
rename source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Frapschen committed Aug 10, 2023
1 parent b0dba6b commit 81aa915
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Advertise> getAllAds() {
public Iterable<Ad> 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<Advertise> findAdvertiseByAdKey(@PathVariable("adKey") String adKey){
public Iterable<Ad> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Advertise, Integer> {
Iterable<Advertise> findByAdKey(@Param("adKey") String adKey);
public interface AdRepository extends CrudRepository<Ad, Integer> {
Iterable<Ad> findByAdKey(@Param("adKey") String adKey);
}

0 comments on commit 81aa915

Please sign in to comment.