From b9d2451902114204fa55dc32fc10aa2d42c1f3c6 Mon Sep 17 00:00:00 2001 From: mountain Date: Mon, 9 Oct 2023 22:27:33 +0900 Subject: [PATCH] =?UTF-8?q?instantdoc=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/group_instant.go | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/core/group_instant.go b/core/group_instant.go index 4fb32ba..d538fad 100644 --- a/core/group_instant.go +++ b/core/group_instant.go @@ -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()}, })