Add flyway database migration tool. Read diva news from database

This commit is contained in:
samnyan
2020-01-17 01:03:14 +09:00
parent a9a9ae4bbc
commit 3d99839fef
15 changed files with 7229 additions and 9 deletions

View File

@@ -8,10 +8,13 @@ import icu.samnyan.aqua.sega.diva.dao.gamedata.*;
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
import icu.samnyan.aqua.sega.diva.model.common.Edition;
import icu.samnyan.aqua.sega.diva.model.gamedata.*;
import icu.samnyan.aqua.sega.general.dao.PropertyEntryRepository;
import icu.samnyan.aqua.sega.general.model.PropertyEntry;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
@@ -25,13 +28,15 @@ public class ApiDivaManageController {
private final DivaCustomizeRepository customizeRepository;
private final FestaRepository festaRepository;
private final ContestRepository contestRepository;
private final PropertyEntryRepository propertyEntryRepository;
public ApiDivaManageController(PvEntryRepository pvEntryRepository, DivaModuleRepository moduleRepository, DivaCustomizeRepository customizeRepository, FestaRepository festaRepository, ContestRepository contestRepository) {
public ApiDivaManageController(PvEntryRepository pvEntryRepository, DivaModuleRepository moduleRepository, DivaCustomizeRepository customizeRepository, FestaRepository festaRepository, ContestRepository contestRepository, PropertyEntryRepository propertyEntryRepository) {
this.pvEntryRepository = pvEntryRepository;
this.moduleRepository = moduleRepository;
this.customizeRepository = customizeRepository;
this.festaRepository = festaRepository;
this.contestRepository = contestRepository;
this.propertyEntryRepository = propertyEntryRepository;
}
@PostMapping("pvList")
@@ -101,6 +106,28 @@ public class ApiDivaManageController {
return new OkResponse("Deleted " + id);
}
@GetMapping("news")
public Optional<PropertyEntry> getNews() {
return propertyEntryRepository.findByPropertyKey("diva_news");
}
@PutMapping("news")
public PropertyEntry updateNews(@RequestBody PropertyEntry property) {
PropertyEntry entry = propertyEntryRepository.findByPropertyKey("diva_news").orElseGet(() -> new PropertyEntry("diva_news", property.getPropertyValue()));
return propertyEntryRepository.save(entry);
}
@GetMapping("warning")
public Optional<PropertyEntry> getWarning() {
return propertyEntryRepository.findByPropertyKey("diva_warning");
}
@PutMapping("warning")
public PropertyEntry updateWarning(@RequestBody PropertyEntry property) {
PropertyEntry entry = propertyEntryRepository.findByPropertyKey("diva_warning").orElseGet(() -> new PropertyEntry("diva_warning", property.getPropertyValue()));
return propertyEntryRepository.save(entry);
}
@GetMapping("module")
public List<DivaModule> getModule() {
return moduleRepository.findAll();

View File

@@ -46,6 +46,16 @@ public class RegisterHandler implements BaseHandler {
logger.info("Request: " + logMapper.write(requestMap));
if (((String) requestMap.get("luid")).equals("0c1ea200000000000000")) {
ctx.close();
return;
}
if (((String) requestMap.get("luid")).equals("0c1ea200000000000000")) {
ctx.close();
return;
}
Card card = new Card();
card.setLuid((String) requestMap.get("luid"));
card.setExtId(ThreadLocalRandom.current().nextLong(99999999));

View File

@@ -4,6 +4,8 @@ import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.operation.PingResponse;
import icu.samnyan.aqua.sega.diva.util.DivaMapper;
import icu.samnyan.aqua.sega.general.dao.PropertyEntryRepository;
import icu.samnyan.aqua.sega.general.model.PropertyEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -16,16 +18,24 @@ public class PingHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PingHandler.class);
public PingHandler(DivaMapper mapper) {
private final PropertyEntryRepository propertyEntryRepository;
public PingHandler(DivaMapper mapper, PropertyEntryRepository propertyEntryRepository) {
super(mapper);
this.propertyEntryRepository = propertyEntryRepository;
}
public String handle(BaseRequest request) {
PropertyEntry news = propertyEntryRepository.findByPropertyKey("diva_news").orElseGet(() -> new PropertyEntry("diva_news", "Server Running No other news"));
PropertyEntry warning = propertyEntryRepository.findByPropertyKey("diva_warning").orElseGet(() -> new PropertyEntry("diva_warning", "Network Service Running"));
PingResponse response = new PingResponse(
request.getCmd(),
request.getReq_id(),
"ok"
"ok",
news.getPropertyValue(),
warning.getPropertyValue()
);
String resp = this.build(mapper.toMap(response));

View File

@@ -11,8 +11,8 @@ import lombok.Setter;
@Getter
@Setter
public class PingResponse extends BaseResponse {
private String ping_b_msg = URIEncoder.encode("Server testing No other news");
private String ping_m_msg = URIEncoder.encode("Nothing special Server testing No other news");
private String ping_b_msg = URIEncoder.encode("Server Running No other news");
private String ping_m_msg = URIEncoder.encode("Network Service Running");
private String atnd_lut;
private String fi_lut;
private String ci_lut;
@@ -53,4 +53,10 @@ public class PingResponse extends BaseResponse {
public PingResponse(String cmd, String req_id, String stat) {
super(cmd, req_id, stat);
}
public PingResponse(String cmd, String req_id, String stat, String ping_b_msg, String ping_m_msg) {
super(cmd, req_id, stat);
this.ping_b_msg = ping_b_msg;
this.ping_m_msg = ping_m_msg;
}
}

View File

@@ -0,0 +1,15 @@
package icu.samnyan.aqua.sega.general.dao;
import icu.samnyan.aqua.sega.general.model.PropertyEntry;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface PropertyEntryRepository extends JpaRepository<PropertyEntry, Long> {
Optional<PropertyEntry> findByPropertyKey(String key);
}

View File

@@ -0,0 +1,33 @@
package icu.samnyan.aqua.sega.general.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Entity(name = "ServerPropertyEntry")
@Table(name = "property")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PropertyEntry implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(unique = true)
private String propertyKey;
private String propertyValue;
public PropertyEntry(String propertyKey, String propertyValue) {
this.propertyKey = propertyKey;
this.propertyValue = propertyValue;
}
}