계정 대량 조회 추가
This commit is contained in:
79
core/api.go
79
core/api.go
@ -396,43 +396,62 @@ func (caller apiCaller) userinfoAPI(w http.ResponseWriter, r *http.Request) erro
|
|||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
// 계정 조회
|
// 계정 조회
|
||||||
accid, _ := gocommon.ReadObjectIDFormValue(r.Form, "accid")
|
accid, _ := gocommon.ReadObjectIDFormValue(r.Form, "accid")
|
||||||
if len(accid) == 0 {
|
if len(accid) > 0 {
|
||||||
logger.Println("[userinfoAPI] accid is empty")
|
all, err := mg.mongoClient.FindAll(CollectionAccount, bson.M{
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
"accid": accid,
|
||||||
return nil
|
}, options.Find().SetProjection(bson.M{"_id": 1, "accid": 1}))
|
||||||
}
|
|
||||||
|
|
||||||
all, err := mg.mongoClient.FindAll(CollectionAccount, bson.M{
|
|
||||||
"accid": accid,
|
|
||||||
}, options.Find().SetProjection(bson.M{"_id": 1, "accid": 1}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var linkinfos []accountlinkinfo
|
|
||||||
for _, doc := range all {
|
|
||||||
id := doc["_id"].(primitive.ObjectID)
|
|
||||||
|
|
||||||
link, err := mg.mongoClient.FindOne(CollectionLink, bson.M{
|
|
||||||
"_id": id,
|
|
||||||
}, options.FindOne().SetProjection(bson.M{"_id": 1, "platform": 1, "uid": 1}))
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("link failed. FindOneAndUpdate link err:", err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var info accountlinkinfo
|
var linkinfos []accountlinkinfo
|
||||||
info.Platform = link["platform"].(string)
|
for _, doc := range all {
|
||||||
info.Uid = link["uid"].(string)
|
id := doc["_id"].(primitive.ObjectID)
|
||||||
linkinfos = append(linkinfos, info)
|
|
||||||
|
link, err := mg.mongoClient.FindOne(CollectionLink, bson.M{
|
||||||
|
"_id": id,
|
||||||
|
}, options.FindOne().SetProjection(bson.M{"_id": 1, "platform": 1, "uid": 1}))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("link failed. FindOneAndUpdate link err:", err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var info accountlinkinfo
|
||||||
|
info.Platform = link["platform"].(string)
|
||||||
|
info.Uid = link["uid"].(string)
|
||||||
|
linkinfos = append(linkinfos, info)
|
||||||
|
}
|
||||||
|
|
||||||
|
enc := json.NewEncoder(w)
|
||||||
|
enc.Encode(linkinfos)
|
||||||
|
}
|
||||||
|
} else if r.Method == "POST" {
|
||||||
|
r.ParseMultipartForm(32 << 20)
|
||||||
|
var body struct {
|
||||||
|
Platform string
|
||||||
|
Uid []string
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
enc := json.NewEncoder(w)
|
if len(body.Platform) > 0 && len(body.Uid) > 0 {
|
||||||
enc.Encode(linkinfos)
|
output := make(map[string]any)
|
||||||
|
for _, uid := range body.Uid {
|
||||||
|
link, err := mg.mongoClient.FindOne(CollectionLink, bson.M{
|
||||||
|
"platform": body.Platform,
|
||||||
|
"uid": uid,
|
||||||
|
}, options.FindOne().SetProjection(bson.M{"_id": 1}))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
output[uid] = link["_id"]
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user