From cf9c4d57c75c26fb8a5784b9e3bcb4f1bdfe601a Mon Sep 17 00:00:00 2001 From: rehjinh Date: Tue, 2 Jul 2024 10:53:41 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=84=EC=A0=95=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20accid=20->=20platform,=20uid=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=98=EB=8A=94=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/api.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) 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 {