forked from Cookies_Github_mirror/AquaDX
[+] User data handlers
This commit is contained in:
@@ -5,7 +5,6 @@ import icu.samnyan.aqua.net.utils.simpleDescribe
|
||||
import icu.samnyan.aqua.sega.chusan.handler.*
|
||||
import icu.samnyan.aqua.sega.chusan.model.Chu3Repos
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
||||
import icu.samnyan.aqua.sega.maimai2.handler.UserReqHandler
|
||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper
|
||||
import icu.samnyan.aqua.sega.wacca.empty
|
||||
import icu.samnyan.aqua.spring.Metrics
|
||||
@@ -14,9 +13,9 @@ import org.springframework.web.bind.annotation.RestController
|
||||
import kotlin.collections.set
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
|
||||
fun interface Chu3UserHandler : BaseHandler {
|
||||
override fun handle(request: Map<String, Any>) = handleThis(request, parsing { request["userId"]?.long })
|
||||
fun handleThis(request: Map<String, Any>, extId: Long?): Any
|
||||
fun interface WithUser : BaseHandler {
|
||||
override fun handle(request: Map<String, Any>) = handleThis(request, parsing { request["userId"]!!.long })
|
||||
fun handleThis(request: Map<String, Any>, extId: Long): Any
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,16 +28,12 @@ class ChusanServletController(
|
||||
val gameLogin: GameLoginHandler,
|
||||
val getGameSetting: GetGameSettingHandler,
|
||||
val getUserCharacter: GetUserCharacterHandler,
|
||||
val getUserCharge: GetUserChargeHandler,
|
||||
val getUserCourse: GetUserCourseHandler,
|
||||
val getUserData: GetUserDataHandler,
|
||||
val getUserDuel: GetUserDuelHandler,
|
||||
val getUserFavoriteItem: GetUserFavoriteItemHandler,
|
||||
val getUserItem: GetUserItemHandler,
|
||||
val getUserLoginBonus: GetUserLoginBonusHandler,
|
||||
val getUserMapArea: GetUserMapAreaHandler,
|
||||
val getUserMusic: GetUserMusicHandler,
|
||||
val getUserOption: GetUserOptionHandler,
|
||||
val getUserPreview: GetUserPreviewHandler,
|
||||
val getUserRecentRating: GetUserRecentRatingHandler,
|
||||
val getUserTeam: GetUserTeamHandler,
|
||||
@@ -91,11 +86,25 @@ class ChusanServletController(
|
||||
val getMatchingState = BaseHandler { """{"matchingWaitState":{"restMSec":"30000","pollingInterval":"10","matchingMemberInfoList":[],"isFinish":"true"}}""" }
|
||||
|
||||
// Actual handlers
|
||||
val getUserActivity = UserReqHandler { req, u ->
|
||||
val getUserData = WithUser { _, u ->
|
||||
val user = repos.userData.findByCard_ExtId(u)() ?: (400 - "User not found")
|
||||
mapOf("userId" to u, "userData" to user)
|
||||
}
|
||||
val getUserOption = WithUser { _, u ->
|
||||
val userGameOption = repos.userGameOption.findSingleByUser_Card_ExtId(u)() ?: (400 - "User not found")
|
||||
mapOf("userId" to u, "userGameOption" to userGameOption)
|
||||
}
|
||||
val getUserActivity = WithUser { req, u ->
|
||||
val kind = parsing { req["kind"]!!.int }
|
||||
val a = repos.userActivity.findAllByUser_Card_ExtIdAndKind(u, kind).sortedBy { it.sortNumber }
|
||||
mapOf("userId" to u, "length" to a.size, "kind" to kind, "userActivityList" to a)
|
||||
}
|
||||
val getUserCharge = WithUser { _, u -> repos.userCharge.findByUser_Card_ExtId(u)
|
||||
.let { mapOf("userId" to u, "length" to it.size, "userChargeList" to it) }
|
||||
}
|
||||
val getUserDuel = WithUser { _, u -> repos.userDuel.findByUser_Card_ExtId(u)
|
||||
.let { mapOf("userId" to u, "length" to it.size, "userDuelList" to it) }
|
||||
}
|
||||
val getGameEvent = static(mapOf("type" to 1, "length" to events.size, "gameEventList" to events))
|
||||
val getGameCharge = static(repos.gameCharge.findAll().let { mapOf("length" to it.size, "gameChargeList" to it) })
|
||||
val getGameGacha = static(repos.gameGacha.findAll()
|
||||
|
||||
@@ -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.UserCharge;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserChargeService;
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserChargeHandler")
|
||||
public class GetUserChargeHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserChargeHandler.class);
|
||||
|
||||
private final StringMapper mapper;
|
||||
|
||||
private final UserChargeService userChargeService;
|
||||
|
||||
@Autowired
|
||||
public GetUserChargeHandler(StringMapper mapper, UserChargeService userChargeService) {
|
||||
this.mapper = mapper;
|
||||
this.userChargeService = userChargeService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
|
||||
List<UserCharge> userChargeList = userChargeService.getByUserId(userId);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", userChargeList.size());
|
||||
resultMap.put("userChargeList", userChargeList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +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.Chu3UserData;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserDataService;
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserDataHandler")
|
||||
public class GetUserDataHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserDataHandler.class);
|
||||
|
||||
private final StringMapper mapper;
|
||||
|
||||
private final UserDataService userDataService;
|
||||
|
||||
@Autowired
|
||||
public GetUserDataHandler(StringMapper mapper, UserDataService userDataService) {
|
||||
this.mapper = mapper;
|
||||
this.userDataService = userDataService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
Optional<Chu3UserData> userDataOptional = userDataService.getUserByExtId(userId);
|
||||
|
||||
if (userDataOptional.isPresent()) {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
Chu3UserData user = userDataOptional.get();
|
||||
|
||||
resultMap.put("userData", user);
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +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.UserDuel;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserDuelService;
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle GetUserDuel request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserDuelHandler")
|
||||
public class GetUserDuelHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserDuelHandler.class);
|
||||
|
||||
private final StringMapper mapper;
|
||||
|
||||
private final UserDuelService userDuelService;
|
||||
|
||||
@Autowired
|
||||
public GetUserDuelHandler(StringMapper mapper, UserDuelService userDuelService) {
|
||||
this.mapper = mapper;
|
||||
this.userDuelService = userDuelService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
String duelId = (String) request.get("duelId");
|
||||
String isAllDuel = (String) request.get("isAllDuel");
|
||||
|
||||
List<UserDuel> userDuelList = userDuelService.getByUserId(userId);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", userDuelList.size());
|
||||
resultMap.put("userDuelList", userDuelList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +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.UserGameOption;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserGameOptionService;
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanGetUserOptionHandler")
|
||||
public class GetUserOptionHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetUserOptionHandler.class);
|
||||
|
||||
private final StringMapper mapper;
|
||||
|
||||
private final UserGameOptionService userGameOptionService;
|
||||
|
||||
@Autowired
|
||||
public GetUserOptionHandler(StringMapper mapper, UserGameOptionService userGameOptionService) {
|
||||
this.mapper = mapper;
|
||||
this.userGameOptionService = userGameOptionService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
Optional<UserGameOption> userGameOption = userGameOptionService.getByUserId(userId);
|
||||
|
||||
if (userGameOption.isPresent()) {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("userGameOption", userGameOption.get());
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,6 @@ public class UserActivityService {
|
||||
return userActivityRepository.findTopByUserAndActivityIdAndKindOrderByIdDesc(user, activityId, kind);
|
||||
}
|
||||
|
||||
public List<UserActivity> getAllByUserIdAndKind(String userId, String kind) {
|
||||
return userActivityRepository.findAllByUser_Card_ExtIdAndKindOrderBySortNumberDesc(Long.parseLong(userId), Integer.parseInt(kind));
|
||||
}
|
||||
|
||||
public List<UserActivity> getByUserId(String userId) {
|
||||
return userActivityRepository.findByUser_Card_ExtId(Long.parseLong(userId));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user