use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method addOne.
@Transactional
@PreAuthorize("hasRole('BASIC')")
@PostMapping(value = "/api/sakuras", produces = MEDIA_TYPE)
public String addOne(@JsonArg String key, @JsonArg String title, @JsonArg(defaults = "true") boolean enabled, @JsonArg(defaults = "PublicList") ViewType viewType) {
if (key.isEmpty()) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[创建列表失败][列表索引不能为空]");
}
return errorMessage("列表索引不能为空");
}
if (title.isEmpty()) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[创建列表失败][列表标题不能为空]");
}
return errorMessage("列表标题不能为空");
}
if (dao.lookup(Sakura.class, "key", key) != null) {
if (LOGGER.isInfoEnabled()) {
infoRequest("[创建列表失败][该列表索引已存在][Key={}]", key);
}
return errorMessage("该列表索引已存在");
}
Sakura sakura = new Sakura(key, title, enabled, viewType);
dao.save(sakura);
JSONObject result = sakura.toJSON();
if (LOGGER.isInfoEnabled()) {
infoRequest("[创建列表成功][列表信息={}]", result);
}
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method findDiscs.
@Transactional
@GetMapping(value = "/api/sakuras/key/{key}/discs", produces = MEDIA_TYPE)
public String findDiscs(@PathVariable String key, @RequestParam(defaultValue = DISC_COLUMNS) String discColumns, @RequestParam(name = "public", defaultValue = "true") boolean isPublic) {
Sakura sakura = dao.lookup(Sakura.class, "key", key);
if (sakura == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[获取列表碟片失败][指定的列表索引不存在][key={}]", key);
}
return errorMessage("指定的列表索引不存在");
}
JSONObject result = sakura.toJSON();
JSONArray discs = new JSONArray();
sakura.getDiscs().stream().filter(disc -> !isPublic || disc.getUpdateType() != UpdateType.None).forEach(disc -> discs.put(disc.toJSON(getColumns(discColumns))));
result.put("discs", discs);
if (LOGGER.isDebugEnabled()) {
debugRequest("[获取列表碟片成功][列表标题={}][碟片数量={}]", sakura.getTitle(), sakura.getDiscs().size());
}
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method setOne.
@Transactional
@PreAuthorize("hasRole('BASIC')")
@PutMapping(value = "/api/sakuras/{id}", produces = MEDIA_TYPE)
public String setOne(@PathVariable("id") Long id, @JsonArg("$.key") String key, @JsonArg("$.title") String title, @JsonArg("$.viewType") ViewType viewType, @JsonArg("$.enabled") boolean enabled) {
if (key.isEmpty()) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[编辑列表失败][列表索引不能为空]");
}
return errorMessage("列表索引不能为空");
}
if (title.isEmpty()) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[编辑列表失败][列表标题不能为空]");
}
return errorMessage("列表标题不能为空");
}
Sakura sakura = dao.get(Sakura.class, id);
if (sakura == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[编辑列表失败][指定的列表Id不存在][id={}]", id);
}
return errorMessage("指定的列表Id不存在");
}
JSONObject before = sakura.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[编辑列表开始][修改前={}]", before);
}
sakura.setKey(key);
sakura.setTitle(title);
sakura.setViewType(viewType);
sakura.setEnabled(enabled);
JSONObject result = sakura.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[编辑列表成功][修改后={}]", result);
}
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method findOne.
@Transactional
@GetMapping(value = "/api/sakuras/key/{key}", produces = MEDIA_TYPE)
public String findOne(@PathVariable String key) {
Sakura sakura = dao.lookup(Sakura.class, "key", key);
if (sakura == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[获取列表失败][指定的列表索引不存在][key={}]", key);
}
return errorMessage("指定的列表索引不存在");
}
JSONObject result = sakura.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[获取列表成功][列表信息={}]", sakura.toJSON());
}
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method pushDiscs.
@Transactional
@PreAuthorize("hasRole('BASIC')")
@PostMapping(value = "/api/sakuras/{id}/discs/{discId}", produces = MEDIA_TYPE)
public String pushDiscs(@PathVariable("id") Long id, @PathVariable("discId") Long discId, @RequestParam(name = "discColumns", defaultValue = DISC_COLUMNS) String discColumns) {
Sakura sakura = dao.get(Sakura.class, id);
if (sakura == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[添加碟片到列表失败][指定的列表Id不存在][Id={}]", id);
}
return errorMessage("指定的列表Id不存在");
}
Disc disc = dao.get(Disc.class, discId);
if (disc == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[添加碟片到列表失败][指定的碟片Id不存在][Id={}]", discId);
}
return errorMessage("指定的碟片Id不存在");
}
if (sakura.getDiscs().stream().anyMatch(d -> d.getId().equals(discId))) {
if (LOGGER.isInfoEnabled()) {
infoRequest("[添加碟片到列表失败][指定的碟片已存在于列表][ASIN={}][列表={}]", disc.getAsin(), sakura.getTitle());
}
return errorMessage("指定的碟片已存在于列表");
}
sakura.getDiscs().add(disc);
if (LOGGER.isInfoEnabled()) {
infoRequest("[添加碟片到列表成功][ASIN={}][列表={}]", disc.getAsin(), sakura.getTitle());
}
return objectResult(disc.toJSON(getColumns(discColumns)));
}
Aggregations