Migrate accessories to user data
- Add user_accessory as the per-user accessory inventory table. - Migrate old accessory wear records to user-owned accessory ids, including legacy common_accessory_m lookups for old installs. - Allocate default accessories for newly created users and update accessory reads to use user_accessory at runtime. - Validate accessory ownership when wearing accessories and keep existing accessory-based responses working. Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"honoka-chan/internal/middleware"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/router"
|
||||
unitschema "honoka-chan/internal/schema/unit"
|
||||
"honoka-chan/internal/session"
|
||||
@@ -32,8 +34,20 @@ func wearAccessory(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
// 佩戴饰品
|
||||
var exists bool
|
||||
for _, v := range req.Wear {
|
||||
// fmt.Println("Wear:", v.AccessoryOwningUserID, v.UnitOwningUserID)
|
||||
exists, err = ss.UserEng.Table(new(usermodel.UserAccessory)).
|
||||
Where("user_id = ? AND accessory_owning_user_id = ?", ss.UserID, v.AccessoryOwningUserID).
|
||||
Exist()
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
if !exists {
|
||||
ss.CheckErr(errors.New("accessory not found for user"))
|
||||
return
|
||||
}
|
||||
|
||||
data := unitschema.WearAccessoryData{
|
||||
AccessoryOwningUserID: v.AccessoryOwningUserID,
|
||||
UnitOwningUserID: v.UnitOwningUserID,
|
||||
|
||||
Reference in New Issue
Block a user