instantdoc 업데이트 api 추가
This commit is contained in:
@ -185,6 +185,47 @@ func (gi *groupInstant) join(gd *instantDoc, mid primitive.ObjectID, character a
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gi *groupInstant) UpdateInstantDocument(w http.ResponseWriter, r *http.Request) {
|
||||
var data struct {
|
||||
Gid primitive.ObjectID
|
||||
Doc primitive.M
|
||||
Result string
|
||||
}
|
||||
if err := gocommon.MakeDecoder(r).Decode(&data); err != nil {
|
||||
logger.Println("UpdateInstantDocument failed. Decode returns err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
gd := partyDoc{
|
||||
id: data.Gid,
|
||||
rh: gi.rh,
|
||||
}
|
||||
if err := gi.rh.JSONMSetRel(gd.strid(), "$.", data.Doc); err != nil {
|
||||
logger.Println("UpdateInstantDocument failed. JSONMSetRel returns err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// 업데이트 알림
|
||||
gi.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||
Target: "#" + gd.strid(),
|
||||
Body: data.Doc,
|
||||
Tag: []string{"GroupDocFragment"},
|
||||
})
|
||||
|
||||
if data.Result == "after" {
|
||||
raws, err := gi.rh.JSONGetDocuments(data.Gid.Hex(), "$")
|
||||
if err != nil {
|
||||
logger.Println("QueryInstantDocument failed. JSONGetDocuments returns err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
gocommon.MakeEncoder(w, r).Encode(raws[0])
|
||||
}
|
||||
}
|
||||
|
||||
func (gi *groupInstant) Join(w http.ResponseWriter, r *http.Request) {
|
||||
var data struct {
|
||||
Gid primitive.ObjectID
|
||||
@ -273,7 +314,7 @@ func (gi *groupInstant) leave(gd *instantDoc, mid primitive.ObjectID) error {
|
||||
// mid한테는 빈 GroupDocFull을 보낸다. 그러면 지워짐
|
||||
gi.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||
Target: mid.Hex(),
|
||||
Body: bson.M{"_gid": gd.Gid},
|
||||
Body: bson.M{},
|
||||
Tag: []string{"GroupDocFull", gd.strid()},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user