계정조회 api 추가 accid -> platform, uid 조회하는 api 추가
This commit is contained in:
54
core/api.go
54
core/api.go
@ -386,6 +386,58 @@ func (caller apiCaller) couponAPI(w http.ResponseWriter, r *http.Request) error
|
||||
return nil
|
||||
}
|
||||
|
||||
type accountlinkinfo struct {
|
||||
Uid string `json:"uid"`
|
||||
Platform string `json:"platform"`
|
||||
}
|
||||
|
||||
func (caller apiCaller) userinfoAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
mg := caller.mg
|
||||
if r.Method == "GET" {
|
||||
// 계정 조회
|
||||
accid, _ := gocommon.ReadObjectIDFormValue(r.Form, "accid")
|
||||
if len(accid) == 0 {
|
||||
logger.Println("[userinfoAPI] accid is empty")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return nil
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var errApiTokenMissing = errors.New("mg-x-api-token is missing")
|
||||
|
||||
func (caller apiCaller) configAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
@ -512,6 +564,8 @@ func (mg *Maingate) api(w http.ResponseWriter, r *http.Request) {
|
||||
err = caller.blockAPI(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/coupon") {
|
||||
err = caller.couponAPI(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/userinfo") {
|
||||
err = caller.userinfoAPI(w, r)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user