fixed lots of bugs
This commit is contained in:
99
routes/api/user/param_userid/profile/param_usrid.go
Normal file
99
routes/api/user/param_userid/profile/param_usrid.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"bdgrp_go/db"
|
||||
"bdgrp_go/master"
|
||||
"bdgrp_go/pbutil"
|
||||
"bdgrp_go/routes"
|
||||
"bdgrp_go/utils"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
path := routes.PathOf()
|
||||
routes.Register(func(app *fiber.App) {
|
||||
app.Put(path, profile)
|
||||
fmt.Println("Loaded:", path)
|
||||
})
|
||||
}
|
||||
|
||||
func profile(c *fiber.Ctx) error {
|
||||
userid := c.Params("usrid")
|
||||
user := db.FindUser(userid)
|
||||
m := master.GetMaster()
|
||||
|
||||
userSituations := utils.BuildUserSituations(userid, m, user)
|
||||
situationMap := map[string]any{}
|
||||
for _, sit := range userSituations {
|
||||
s := sit.(map[string]any)
|
||||
situationMap[fmt.Sprintf("%v", s["situationId"])] = s
|
||||
}
|
||||
|
||||
decks := user["decks"].([]any)
|
||||
mainDeckIdx := 1
|
||||
if md, ok := user["mainDeck"].(float64); ok {
|
||||
mainDeckIdx = int(md)
|
||||
}
|
||||
mainDeck := decks[mainDeckIdx-1].(map[string]any)
|
||||
|
||||
situationIdFields := []string{"leader", "member1", "member2", "member3", "member4"}
|
||||
var mainDeckSituations []any
|
||||
for _, field := range situationIdFields {
|
||||
if sid, ok := mainDeck[field]; ok && sid != nil {
|
||||
sidStr := fmt.Sprintf("%v", sid)
|
||||
if s, ok := situationMap[sidStr]; ok {
|
||||
mainDeckSituations = append(mainDeckSituations, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userProfileDegree := utils.BuildUserProfileDegree(userid, user)
|
||||
musicScore, _ := user["musicScore"].(map[string]any)
|
||||
|
||||
data := map[string]any{
|
||||
"userName": user["userName"],
|
||||
"rank": user["rank"],
|
||||
"degree": 100,
|
||||
"introduction": user["introduction"],
|
||||
"searchableFlg": true,
|
||||
"publishUpdatedAtFlg": true,
|
||||
"friendApplicableFlg": true,
|
||||
"publishStageChallengeFriendRankingFlg": true,
|
||||
"mainDeckUserSituations": map[string]any{"entries": mainDeckSituations},
|
||||
"enabledUserAreaItems": map[string]any{},
|
||||
"bandRankMap": map[string]any{"entries": utils.BandRankMap},
|
||||
"userHighScoreRating": map[string]any{
|
||||
"userPoppinPartyHighScoreMusicList": map[string]any{},
|
||||
"userPastelPalettesHighScoreMusicList": map[string]any{},
|
||||
"userRoseliaHighScoreMusicList": map[string]any{},
|
||||
"userOtherHighScoreMusicList": map[string]any{},
|
||||
"userMorfonicaHighScoreMusicList": map[string]any{},
|
||||
"userRaiseASuilenHighScoreMusicList": map[string]any{},
|
||||
"userMyGOScoreMusicList": map[string]any{},
|
||||
},
|
||||
"mainUserDeck": mainDeck,
|
||||
"userProfileSituation": map[string]any{},
|
||||
"userProfileDegreeMap": map[string]any{"entries": userProfileDegree},
|
||||
"userTwitter": map[string]any{},
|
||||
"userDeckTotalRatingMap": map[string]any{"entries": utils.DeckRatingMap},
|
||||
"stageChallengeAchievementConditionsMap": map[string]any{},
|
||||
"userMusicClearInfoMap": utils.ComputeMusicClearInfo(musicScore),
|
||||
"userCharacterRankMap": utils.BuildCharacterRankMap(),
|
||||
}
|
||||
|
||||
encoded, err := pbutil.Encode("UserProfile", data)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
encrypted, err := utils.Encrypt(encoded)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.Send(encrypted)
|
||||
}
|
||||
109
routes/api/user/param_userid/profile/search/param_targetid.go
Normal file
109
routes/api/user/param_userid/profile/search/param_targetid.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"bdgrp_go/db"
|
||||
"bdgrp_go/master"
|
||||
"bdgrp_go/pbutil"
|
||||
"bdgrp_go/routes"
|
||||
"bdgrp_go/utils"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
path := routes.PathOf()
|
||||
routes.Register(func(app *fiber.App) {
|
||||
app.Put(path, profileSearch)
|
||||
fmt.Println("Loaded:", path)
|
||||
})
|
||||
}
|
||||
|
||||
func profileSearch(c *fiber.Ctx) error {
|
||||
targetid := c.Params("targetid")
|
||||
user := db.FindUser(targetid)
|
||||
|
||||
var data map[string]any
|
||||
|
||||
if user == nil {
|
||||
data = map[string]any{"searchSuccessFlg": false}
|
||||
} else {
|
||||
m := master.GetMaster()
|
||||
userid := fmt.Sprintf("%v", user["userId"])
|
||||
|
||||
userSituations := utils.BuildUserSituations(userid, m, user)
|
||||
situationMap := map[string]any{}
|
||||
for _, sit := range userSituations {
|
||||
s := sit.(map[string]any)
|
||||
situationMap[fmt.Sprintf("%v", s["situationId"])] = s
|
||||
}
|
||||
|
||||
decks := user["decks"].([]any)
|
||||
mainDeckIdx := 1
|
||||
if md, ok := user["mainDeck"].(float64); ok {
|
||||
mainDeckIdx = int(md)
|
||||
}
|
||||
mainDeck := decks[mainDeckIdx-1].(map[string]any)
|
||||
|
||||
situationIdFields := []string{"leader", "member1", "member2", "member3", "member4"}
|
||||
var mainDeckSituations []any
|
||||
for _, field := range situationIdFields {
|
||||
if sid, ok := mainDeck[field]; ok && sid != nil {
|
||||
sidStr := fmt.Sprintf("%v", sid)
|
||||
if s, ok := situationMap[sidStr]; ok {
|
||||
mainDeckSituations = append(mainDeckSituations, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userProfileDegree := utils.BuildUserProfileDegree(userid, user)
|
||||
musicScore, _ := user["musicScore"].(map[string]any)
|
||||
|
||||
data = map[string]any{
|
||||
"userProfile": map[string]any{
|
||||
"userName": user["userName"],
|
||||
"rank": user["rank"],
|
||||
"degree": 100,
|
||||
"introduction": user["introduction"],
|
||||
"searchableFlg": true,
|
||||
"publishUpdatedAtFlg": true,
|
||||
"friendApplicableFlg": true,
|
||||
"publishStageChallengeFriendRankingFlg": true,
|
||||
"mainDeckUserSituations": map[string]any{"entries": mainDeckSituations},
|
||||
"enabledUserAreaItems": map[string]any{},
|
||||
"bandRankMap": map[string]any{"entries": utils.BandRankMap},
|
||||
"userHighScoreRating": map[string]any{
|
||||
"userPoppinPartyHighScoreMusicList": map[string]any{},
|
||||
"userPastelPalettesHighScoreMusicList": map[string]any{},
|
||||
"userRoseliaHighScoreMusicList": map[string]any{},
|
||||
"userOtherHighScoreMusicList": map[string]any{},
|
||||
"userMorfonicaHighScoreMusicList": map[string]any{},
|
||||
"userRaiseASuilenHighScoreMusicList": map[string]any{},
|
||||
"userMyGOScoreMusicList": map[string]any{},
|
||||
},
|
||||
"mainUserDeck": mainDeck,
|
||||
"userProfileSituation": map[string]any{},
|
||||
"userProfileDegreeMap": map[string]any{"entries": userProfileDegree},
|
||||
"userTwitter": map[string]any{},
|
||||
"userDeckTotalRatingMap": map[string]any{"entries": utils.DeckRatingMap},
|
||||
"stageChallengeAchievementConditionsMap": map[string]any{},
|
||||
"userMusicClearInfoMap": utils.ComputeMusicClearInfo(musicScore),
|
||||
"userCharacterRankMap": utils.BuildCharacterRankMap(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
encoded, err := pbutil.Encode("UserProfileSearchResponse", data)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
encrypted, err := utils.Encrypt(encoded)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.Send(encrypted)
|
||||
}
|
||||
Reference in New Issue
Block a user