diff --git a/core/api.go b/core/api.go index 6f9b2d7..96e09c6 100644 --- a/core/api.go +++ b/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 {