mirror of
https://github.com/MewoLab/AquaDX.git
synced 2025-10-26 12:32:40 +00:00
[O] Rewrite list getters
This commit is contained in:
parent
5f871b1945
commit
39b5032303
@ -219,6 +219,47 @@ fun ChusanServletController.init() {
|
||||
}
|
||||
}
|
||||
|
||||
"GetUserCardPrintError" {
|
||||
val lst = db.userCardPrintState.findByUser_Card_ExtIdAndHasCompleted(uid, false)
|
||||
mapOf("userId" to uid, "length" to lst.size, "userCardPrintStateList" to lst)
|
||||
}
|
||||
|
||||
"GetUserCharacter" {
|
||||
// Let's try not paging at all
|
||||
val lst = db.userCharacter.findByUser_Card_ExtId(uid)
|
||||
mapOf("userId" to uid, "length" to lst.size, "nextIndex" to -1, "userCharacterList" to lst)
|
||||
}
|
||||
|
||||
"GetUserCourse" {
|
||||
val lst = db.userCourse.findByUser_Card_ExtId(uid)
|
||||
mutableMapOf("userId" to uid, "length" to lst.size, "userCourseList" to lst).apply {
|
||||
if (data.containsKey("nextIndex")) this["nextIndex"] = -1
|
||||
}
|
||||
}
|
||||
|
||||
"GetUserItem" {
|
||||
val kind = parsing { (data["nextIndex"]!!.long % 10000000000L).int }
|
||||
val lst = db.userItem.findAllByUser_Card_ExtIdAndItemKind(uid, kind)
|
||||
mapOf("userId" to uid, "length" to lst.size, "nextIndex" to -1, "itemKind" to kind, "userItemList" to lst)
|
||||
}
|
||||
|
||||
"GetUserFavoriteItem" {
|
||||
val kind = parsing { data["kind"]!!.int }
|
||||
|
||||
// TODO: Actually store this info at UpsertUserAll
|
||||
val fav = when (kind) {
|
||||
1 -> "favorite_music"
|
||||
3 -> "favorite_chara"
|
||||
else -> null
|
||||
}?.let { db.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(uid, it)() }?.propertyValue
|
||||
|
||||
val lst = fav?.let {
|
||||
if (it.isNotBlank() && it.contains(",")) it.split(",").map { it.int }
|
||||
else null
|
||||
} ?: emptyList()
|
||||
|
||||
mapOf("userId" to uid, "kind" to kind, "length" to lst.size, "nextIndex" to -1, "userFavoriteItemList" to lst)
|
||||
}
|
||||
// Game settings
|
||||
"GetGameSetting" {
|
||||
val version = data["version"].toString()
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.chusan.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.chusan.model.Chu3UserCardPrintStateRepo;
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserCardPrintState;
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserCardPrintErrorHandler")
|
||||
public class GetUserCardPrintErrorHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserCardPrintErrorHandler.class);
|
||||
private final Chu3UserCardPrintStateRepo userCardPrintStateRepository;
|
||||
private final BasicMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public GetUserCardPrintErrorHandler(Chu3UserCardPrintStateRepo userCardPrintStateRepository, BasicMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
this.userCardPrintStateRepository = userCardPrintStateRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
Long userId = ((Number) request.get("userId")).longValue();
|
||||
|
||||
List<UserCardPrintState> userCardPrintStateList = userCardPrintStateRepository.findByUser_Card_ExtIdAndHasCompleted(userId, false);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", userCardPrintStateList.size());
|
||||
resultMap.put("userCardPrintStateList", userCardPrintStateList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.chusan.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserCharacter;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserCharacterService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle getUserCharacter request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserCharacterHandler")
|
||||
public class GetUserCharacterHandler implements BaseHandler {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserCharacterHandler.class);
|
||||
|
||||
private final StringMapper mapper;
|
||||
|
||||
private final UserCharacterService userCharacterService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public GetUserCharacterHandler(StringMapper mapper, UserCharacterService userCharacterService) {
|
||||
this.mapper = mapper;
|
||||
this.userCharacterService = userCharacterService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
int nextIndex = Integer.parseInt((String) request.get("nextIndex"));
|
||||
int maxCount = Integer.parseInt((String) request.get("maxCount"));
|
||||
|
||||
int pageNum = nextIndex / maxCount;
|
||||
|
||||
Page<UserCharacter> dbPage = userCharacterService.getByUserId(userId, pageNum, maxCount);
|
||||
|
||||
long currentIndex = maxCount * pageNum + dbPage.getNumberOfElements();
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", dbPage.getNumberOfElements());
|
||||
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
|
||||
resultMap.put("userCharacterList", dbPage.getContent());
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.chusan.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserCourse;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserCourseService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle GetUserCourse request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserCourseHandler")
|
||||
public class GetUserCourseHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserCourseHandler.class);
|
||||
|
||||
private final StringMapper mapper;
|
||||
|
||||
private final UserCourseService userCourseService;
|
||||
|
||||
@Autowired
|
||||
public GetUserCourseHandler(StringMapper mapper, UserCourseService userCourseService) {
|
||||
this.mapper = mapper;
|
||||
this.userCourseService = userCourseService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
|
||||
if(request.containsKey("nextIndex")) {
|
||||
int nextIndex = Integer.parseInt((String) request.get("nextIndex"));
|
||||
int maxCount = Integer.parseInt((String) request.get("maxCount"));
|
||||
|
||||
int pageNum = nextIndex / maxCount;
|
||||
|
||||
Page<UserCourse> dbPage = userCourseService.getByUserId(userId, pageNum, maxCount);
|
||||
|
||||
long currentIndex = maxCount * pageNum + dbPage.getNumberOfElements();
|
||||
|
||||
resultMap.put("length", dbPage.getNumberOfElements());
|
||||
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
|
||||
resultMap.put("userCourseList", dbPage.getContent());
|
||||
} else {
|
||||
List<UserCourse> courseList = userCourseService.getByUserId(userId);
|
||||
resultMap.put("length", courseList.size());
|
||||
resultMap.put("userCourseList", courseList);
|
||||
}
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.chusan.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.chusan.model.response.data.UserFavorite;
|
||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserGeneralData;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserGeneralDataService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component("ChusanGetUserFavoriteItemHandler")
|
||||
public class GetUserFavoriteItemHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserFavoriteItemHandler.class);
|
||||
|
||||
private final StringMapper mapper;
|
||||
|
||||
private final UserGeneralDataService userGeneralDataService;
|
||||
|
||||
@Autowired
|
||||
public GetUserFavoriteItemHandler(StringMapper mapper, UserGeneralDataService userGeneralDataService) {
|
||||
this.mapper = mapper;
|
||||
this.userGeneralDataService = userGeneralDataService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
int kind = Integer.parseInt((String) request.get("kind"));
|
||||
Long nextIndexVal = Long.parseLong((String) request.get("nextIndex"));
|
||||
int maxCount = Integer.parseInt((String) request.get("maxCount")); // Fixed to 50?
|
||||
|
||||
List<UserFavorite> userFavorites = new LinkedList<>();
|
||||
Optional<UserGeneralData> favOptional;
|
||||
|
||||
switch (kind) {
|
||||
case 1: // Music
|
||||
favOptional = userGeneralDataService.getByUserIdAndKey(userId, "favorite_music");
|
||||
break;
|
||||
|
||||
case 3: // Chara
|
||||
favOptional = userGeneralDataService.getByUserIdAndKey(userId, "favorite_chara");
|
||||
break;
|
||||
|
||||
default:
|
||||
favOptional = Optional.empty();
|
||||
break;
|
||||
}
|
||||
|
||||
// Let's assume data is in following format:
|
||||
// 1111,2222,3333,4444 ...
|
||||
if(favOptional.isPresent()) {
|
||||
String val = favOptional.get().getPropertyValue();
|
||||
if(StringUtils.isNotBlank(val) && val.contains(",")) {
|
||||
String[] records = val.split(",");
|
||||
for (String record : records) {
|
||||
userFavorites.add(new UserFavorite(Integer.parseInt(record)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// While client seems capable to handle more than 50 items, let's limit it to 50
|
||||
// Reasons: 1. VARCHAR is limited to 255 chars (theoretically <= 51 entries), 2. Multiple pagination is troublesome
|
||||
if (userFavorites.size() > 50) {
|
||||
userFavorites = userFavorites.subList(0, 50);
|
||||
}
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("kind", kind);
|
||||
resultMap.put("length", userFavorites.size());
|
||||
resultMap.put("nextIndex", -1);
|
||||
resultMap.put("userFavoriteItemList", userFavorites);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.chusan.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserGacha;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserGachaService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserGachaHandler")
|
||||
public class GetUserGachaHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserGachaHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
|
||||
private final UserGachaService userGachaService;
|
||||
|
||||
@Autowired
|
||||
public GetUserGachaHandler(BasicMapper mapper, UserGachaService userGachaService) {
|
||||
this.mapper = mapper;
|
||||
this.userGachaService = userGachaService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = String.valueOf(request.get("userId"));
|
||||
|
||||
List<UserGacha> userGachaList = userGachaService.getByUserId(userId);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", userGachaList.size());
|
||||
resultMap.put("userGachaList", userGachaList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.chusan.handler
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException
|
||||
import ext.int
|
||||
import ext.long
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserItemService
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* Handler for getting user item.
|
||||
* This get call before profile create.
|
||||
*
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserItemHandler")
|
||||
class GetUserItemHandler(private val mapper: StringMapper, private val userItemService: UserItemService) : BaseHandler {
|
||||
@Throws(JsonProcessingException::class)
|
||||
override fun handle(request: Map<String, Any>): String {
|
||||
val userId = request["userId"].toString()
|
||||
val nextIndexVal = request["nextIndex"]?.long() ?: 0
|
||||
val maxCount = request["maxCount"]?.int() ?: 100
|
||||
|
||||
val mul = 10000000000L
|
||||
|
||||
val kind = (nextIndexVal / mul).toInt()
|
||||
val nextIndex = (nextIndexVal % mul).toInt()
|
||||
val pageNum = nextIndex / maxCount
|
||||
|
||||
val userItemPage = userItemService.getByUserAndItemKind(userId, kind, pageNum, maxCount)
|
||||
val userItemList = userItemPage.content
|
||||
val currentIndex = kind * mul + maxCount * pageNum + userItemPage.numberOfElements
|
||||
|
||||
// TODO: Music unlock
|
||||
|
||||
val resultMap = mapOf(
|
||||
"userId" to userId,
|
||||
"length" to userItemPage.numberOfElements,
|
||||
"nextIndex" to if (userItemPage.numberOfElements < maxCount) -1 else currentIndex,
|
||||
"itemKind" to kind,
|
||||
"userItemList" to userItemList
|
||||
)
|
||||
|
||||
val json = mapper.write(resultMap)
|
||||
logger.info("Response: $json")
|
||||
return json
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger: Logger = LoggerFactory.getLogger(GetUserItemHandler::class.java)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user