[이민권] api 수정
- unlink시 link collection에 doc 남겨지는 이슈 수정 - linkinfo api가 단순 link 갯수가 아니라 어떤 platform에 연동 하였는지 반환하도록 수정 - 계정 삭제 api인 delacc api 추가
This commit is contained in:
@ -473,12 +473,12 @@ func (sh *serviceDescription) unlink(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
link, err := sh.mongoClient.FindOne(CollectionLink, bson.M{
|
||||
link, err := sh.mongoClient.FindOneAndDelete(CollectionLink, bson.M{
|
||||
"platform": sType,
|
||||
"uid": sId,
|
||||
}, options.FindOne().SetProjection(bson.M{"_id": 1}))
|
||||
}, options.FindOneAndDelete().SetProjection(bson.M{"_id": 1}))
|
||||
if err != nil {
|
||||
logger.Error("link failed. FindOneAndUpdate link err:", err)
|
||||
logger.Error("link failed. FindOneAndDelete link err:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -545,19 +545,32 @@ func (sh *serviceDescription) linkinfo(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
numRecord, err := sh.mongoClient.Collection(CollectionAccount).CountDocuments(context.Background(), bson.M{
|
||||
platformName := "platform"
|
||||
links, err := sh.mongoClient.FindAll(CollectionAccount, bson.M{
|
||||
"accid": authInfo.Accid,
|
||||
}, options.Count().SetLimit(sh.MaximumNumLinkAccount))
|
||||
|
||||
}, options.Find().SetLimit(sh.MaximumNumLinkAccount).SetProjection(bson.M{
|
||||
platformName: 1,
|
||||
}))
|
||||
if err != nil {
|
||||
logger.Error("linkinfo failed. CountDocuments err :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Println("linkinfo :", numRecord)
|
||||
w.Write([]byte(fmt.Sprintf(`{"num_linked_account":"%d"}`, numRecord)))
|
||||
var linkstrs []string
|
||||
for _, link := range links {
|
||||
linkstrs = append(linkstrs, link[platformName].(string))
|
||||
}
|
||||
|
||||
linkbytes, err := json.Marshal(linkstrs)
|
||||
if err != nil {
|
||||
logger.Error("linkinfo failed. json marshal fail :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Println("linkinfo :", linkbytes)
|
||||
w.Write(linkbytes)
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) {
|
||||
@ -761,6 +774,72 @@ func (sh *serviceDescription) findVersionSplit(version string) []byte {
|
||||
return sh.divisionsSplits[""]
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) delacc(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
if s != nil {
|
||||
logger.Error(s)
|
||||
}
|
||||
}()
|
||||
|
||||
if r.Method != "GET" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
queryvals := r.URL.Query()
|
||||
sType := queryvals.Get("stype")
|
||||
sId := queryvals.Get("sid")
|
||||
sk := queryvals.Get("sk")
|
||||
|
||||
authInfo := sh.auths.Find(sk)
|
||||
if authInfo == nil {
|
||||
// 잘못된 세션
|
||||
logger.Println("delacc failed. session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if authInfo.Uid != sId || authInfo.Platform != sType {
|
||||
logger.Println("delacc failed. session key is not correct :", *authInfo, queryvals)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
accids, err := sh.mongoClient.FindAll(CollectionAccount, bson.M{
|
||||
"accid": authInfo.Accid,
|
||||
}, options.Find().SetProjection(bson.M{
|
||||
"_id": 1,
|
||||
}))
|
||||
if err != nil {
|
||||
logger.Error("delacc failed. FindAll account err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var addIdFilter bson.A
|
||||
for _, accid := range accids {
|
||||
addIdFilter = append(addIdFilter, accid["_id"].(primitive.ObjectID))
|
||||
}
|
||||
|
||||
delfilter := bson.D{{Key: "id", Value: bson.D{{Key: "$in", Value: addIdFilter}}}}
|
||||
delaccnum, err := sh.mongoClient.DeleteMany(CollectionAccount, delfilter)
|
||||
if err != nil {
|
||||
logger.Error("delacc failed. Delete many CollectionAccount err :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = sh.mongoClient.DeleteMany(CollectionLink, delfilter)
|
||||
if err != nil {
|
||||
logger.Error("delacc failed. Delete many CollectionLink err :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Println("delacc success :", delaccnum)
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
@ -782,6 +861,8 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
sh.unlink(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/linkinfo") {
|
||||
sh.linkinfo(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/delacc") {
|
||||
sh.delacc(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/divs") {
|
||||
// TODO : 세션키와 authtoken을 헤더로 받아서 accid 조회
|
||||
queryvals := r.URL.Query()
|
||||
|
||||
Reference in New Issue
Block a user