Compare commits

..

2 Commits

Author SHA1 Message Date
a7a9b207e2 계정 대량 조회 추가 2024-07-31 16:49:06 +09:00
f7e3da51ae RegisterHandlers 시그니쳐 수정 (ServerMuxInterface) 2024-07-31 16:48:54 +09:00
3 changed files with 53 additions and 34 deletions

View File

@ -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

View File

@ -431,7 +431,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
var portptr = flagx.Int("port", 80, "") var portptr = flagx.Int("port", 80, "")
func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMux, prefix string) error { func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux gocommon.ServerMuxInterface, prefix string) error {
var allServices []*serviceDescription var allServices []*serviceDescription
if err := mg.mongoClient.AllAs(CollectionService, &allServices, options.Find().SetReturnKey(false)); err != nil { if err := mg.mongoClient.AllAs(CollectionService, &allServices, options.Find().SetReturnKey(false)); err != nil {
return logger.ErrorWithCallStack(err) return logger.ErrorWithCallStack(err)

View File

@ -3,13 +3,13 @@ package core
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"net/http"
"os" "os"
"path" "path"
"sync/atomic" "sync/atomic"
"time" "time"
"unsafe" "unsafe"
"repositories.action2quare.com/ayo/gocommon"
"repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/gocommon/logger"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
@ -34,7 +34,7 @@ type filePipelineDocument struct {
File *FileDocumentDesc `bson:"fullDocument"` File *FileDocumentDesc `bson:"fullDocument"`
} }
func (mg *Maingate) watchFileCollection(parentctx context.Context, serveMux *http.ServeMux, prefix string) { func (mg *Maingate) watchFileCollection(parentctx context.Context, serveMux gocommon.ServerMuxInterface, prefix string) {
defer func() { defer func() {
s := recover() s := recover()
if s != nil { if s != nil {
@ -119,7 +119,7 @@ func (mg *Maingate) watchFileCollection(parentctx context.Context, serveMux *htt
} }
} }
func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux *http.ServeMux, prefix string) { func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux gocommon.ServerMuxInterface, prefix string) {
defer func() { defer func() {
s := recover() s := recover()
if s != nil { if s != nil {