Implement more endpoints & overhaul [2/n]
Drop LevelDB and move all the things to SQLite. Implemented endpoints: /api <unit, accessoryMaterialAll> /api <unit, accessoryTab> /live/continue /live/partyList /unit/favoriteAccessory (WIP) /unit/sale Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@ package profile
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"honoka-chan/internal/schema/api/profile"
|
||||
profileapischema "honoka-chan/internal/schema/api/profile"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
@@ -15,7 +15,7 @@ func cardRanking() (res any, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = profile.CardRankingResp{
|
||||
res = profileapischema.CardRankingResp{
|
||||
Result: result,
|
||||
Status: 200,
|
||||
CommandNum: false,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/schema/api/profile"
|
||||
unitmodel "honoka-chan/internal/model/unit"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
profileapischema "honoka-chan/internal/schema/api/profile"
|
||||
"honoka-chan/internal/session"
|
||||
"time"
|
||||
|
||||
@@ -12,57 +13,25 @@ import (
|
||||
func profileInfo(ctx *gin.Context) (res any, err error) {
|
||||
ss := session.Get(ctx)
|
||||
|
||||
pref := user.UserPref{}
|
||||
pref := usermodel.UserPref{}
|
||||
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Get(&pref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commonUnit, err := ss.MainEng.Table("common_unit_m").Count()
|
||||
unitCount, err := ss.UserEng.Table(new(usermodel.UserUnitData)).
|
||||
Where("user_id = ?", ss.UserID).Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userUnit, err := ss.UserEng.Table("user_unit").Where("user_id = ?", ss.UserID).Count()
|
||||
unitData := unitmodel.UnitDataMap{}
|
||||
_, err = ss.GetBasicUnitInfo().
|
||||
Where("a.unit_owning_user_id = ?", pref.UnitOwningUserID).Get(&unitData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
unitData := profile.UnitData{}
|
||||
exists, err := ss.MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", pref.UnitOwningUserID).Get(&unitData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
isCommon := true
|
||||
if !exists {
|
||||
_, err = ss.UserEng.Table("user_unit").
|
||||
Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ss.UserID).Get(&unitData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
isCommon = false
|
||||
}
|
||||
|
||||
var attrId, maxHp, baseSmile, basePure, baseCool int
|
||||
var smileMax, pureMax, coolMax int
|
||||
if isCommon {
|
||||
// 公共卡片仅为100级属性
|
||||
_, err = ss.MainEng.Table("unit_m").Where("unit_id = ?", unitData.UnitID).
|
||||
Cols("attribute_id,hp_max,smile_max,pure_max,cool_max").Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 偷懒起见不计算饰品、宝石、回忆画廊等属性加成
|
||||
smileMax = baseSmile
|
||||
pureMax = basePure
|
||||
coolMax = baseCool
|
||||
// } else {
|
||||
// // 用户卡片需要根据等级计算属性
|
||||
// // TODO
|
||||
}
|
||||
|
||||
var accessoryOwningId, accessoryId, exp int
|
||||
_, err = ss.UserEng.Table("user_accessory_wear").Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ss.UserID).
|
||||
Cols("accessory_owning_user_id").Get(&accessoryOwningId)
|
||||
@@ -74,7 +43,7 @@ func profileInfo(ctx *gin.Context) (res any, err error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
accessoryInfo := profile.AccessoryInfo{
|
||||
accessoryInfo := profileapischema.AccessoryInfo{
|
||||
AccessoryOwningUserID: accessoryOwningId,
|
||||
AccessoryID: accessoryId,
|
||||
Exp: exp,
|
||||
@@ -92,9 +61,9 @@ func profileInfo(ctx *gin.Context) (res any, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = profile.InfoResp{
|
||||
Result: profile.InfoData{
|
||||
UserInfo: profile.UserInfo{
|
||||
res = profileapischema.InfoResp{
|
||||
Result: profileapischema.InfoData{
|
||||
UserInfo: profileapischema.UserInfo{
|
||||
UserID: pref.UserID,
|
||||
Name: pref.UserName,
|
||||
Level: pref.UserLevel,
|
||||
@@ -102,16 +71,17 @@ func profileInfo(ctx *gin.Context) (res any, err error) {
|
||||
UnitMax: 5000,
|
||||
EnergyMax: 417,
|
||||
FriendMax: 99,
|
||||
UnitCnt: int(commonUnit + userUnit),
|
||||
UnitCnt: int(unitCount),
|
||||
InviteCode: pref.InviteCode,
|
||||
ElapsedTimeFromLogin: "14\u5c0f\u65f6\u524d",
|
||||
Introduction: pref.UserDesc,
|
||||
},
|
||||
CenterUnitInfo: profile.CenterUnitInfo{
|
||||
// TODO: 区分队伍中心卡片和看板卡片
|
||||
CenterUnitInfo: profileapischema.CenterUnitInfo{
|
||||
UnitOwningUserID: unitData.UnitOwningUserID,
|
||||
UnitID: unitData.UnitID,
|
||||
Exp: unitData.Exp,
|
||||
NextExp: unitData.NextExp,
|
||||
NextExp: 0,
|
||||
Level: unitData.Level,
|
||||
LevelLimitID: unitData.LevelLimitID,
|
||||
MaxLevel: unitData.MaxLevel,
|
||||
@@ -125,10 +95,10 @@ func profileInfo(ctx *gin.Context) (res any, err error) {
|
||||
DisplayRank: unitData.DisplayRank,
|
||||
UnitSkillExp: unitData.UnitSkillExp,
|
||||
UnitRemovableSkillCapacity: unitData.UnitRemovableSkillCapacity,
|
||||
Attribute: attrId,
|
||||
Smile: baseSmile,
|
||||
Cute: basePure,
|
||||
Cool: baseCool,
|
||||
Attribute: unitData.Attribute,
|
||||
Smile: unitData.Smile,
|
||||
Cute: unitData.Cute,
|
||||
Cool: unitData.Cool,
|
||||
IsLoveMax: unitData.IsLoveMax,
|
||||
IsLevelMax: unitData.IsLevelMax,
|
||||
IsRankMax: unitData.IsRankMax,
|
||||
@@ -137,17 +107,17 @@ func profileInfo(ctx *gin.Context) (res any, err error) {
|
||||
SettingAwardID: pref.AwardID,
|
||||
RemovableSkillIds: removeSkillIds,
|
||||
AccessoryInfo: accessoryInfo,
|
||||
Costume: profile.Costume{},
|
||||
TotalSmile: smileMax,
|
||||
TotalCute: pureMax,
|
||||
TotalCool: coolMax,
|
||||
TotalHp: maxHp,
|
||||
Costume: profileapischema.Costume{},
|
||||
TotalSmile: unitData.Smile, // TODO: 加成计算
|
||||
TotalCute: unitData.Cute, // 同上
|
||||
TotalCool: unitData.Cool, // 同上
|
||||
TotalHp: unitData.MaxHp,
|
||||
},
|
||||
NaviUnitInfo: profile.NaviUnitInfo{
|
||||
NaviUnitInfo: profileapischema.NaviUnitInfo{
|
||||
UnitOwningUserID: unitData.UnitOwningUserID,
|
||||
UnitID: unitData.UnitID,
|
||||
Exp: unitData.Exp,
|
||||
NextExp: unitData.NextExp,
|
||||
NextExp: 0,
|
||||
Level: unitData.Level,
|
||||
MaxLevel: unitData.MaxLevel,
|
||||
LevelLimitID: unitData.LevelLimitID,
|
||||
@@ -168,10 +138,10 @@ func profileInfo(ctx *gin.Context) (res any, err error) {
|
||||
IsSkillLevelMax: unitData.IsSkillLevelMax,
|
||||
IsRemovableSkillCapacityMax: unitData.IsRemovableSkillCapacityMax,
|
||||
InsertDate: "2016-10-11 10:33:03",
|
||||
TotalSmile: smileMax,
|
||||
TotalCute: pureMax,
|
||||
TotalCool: coolMax,
|
||||
TotalHp: maxHp,
|
||||
TotalSmile: unitData.Smile, // TODO: 加成计算
|
||||
TotalCute: unitData.Cute, // 同上
|
||||
TotalCool: unitData.Cool, // 同上
|
||||
TotalHp: unitData.MaxHp,
|
||||
RemovableSkillIds: removeSkillIds,
|
||||
},
|
||||
IsAlliance: false,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"honoka-chan/internal/schema/api/profile"
|
||||
profileapischema "honoka-chan/internal/schema/api/profile"
|
||||
"time"
|
||||
)
|
||||
|
||||
func liveCnt() (res any, err error) {
|
||||
res = profile.LiveCntResp{
|
||||
Result: []profile.LiveCntData{
|
||||
res = profileapischema.LiveCntResp{
|
||||
Result: []profileapischema.LiveCntData{
|
||||
{
|
||||
Difficulty: 1,
|
||||
ClearCnt: 315,
|
||||
|
||||
Reference in New Issue
Block a user