현 상태를 친구에게 공개
This commit is contained in:
@ -234,13 +234,23 @@ func (iv *invitation) Trim(ctx wshandler.ApiCallContext) {
|
||||
}
|
||||
|
||||
func (iv *invitation) InviteAsFriend(w http.ResponseWriter, r *http.Request) {
|
||||
// 1. mongodb에 추가
|
||||
// 1-1. block이 되어있다면(==이미 도큐먼트가 있다면) 마치 성공인 것처럼 아무것도 안하고 끝
|
||||
// 2. mongodb에 추가가 성공하면 publish
|
||||
// 내 현재 친구 숫자 + 내가 보낸 초대 숫자가 FriendsMax를 넘을 수 없다.
|
||||
// TODO : 이미 친구면 초대 불가
|
||||
|
||||
var ivdoc invitationDoc
|
||||
|
||||
if err := gocommon.MakeDecoder(r).Decode(&ivdoc); err != nil {
|
||||
logger.Println("IniviteAsFriend failed:", err)
|
||||
logger.Println("InviteAsFriend failed:", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if exists, err := iv.mongoClient.Exists(friends_collection_name, bson.M{"_id": combineObjectID(ivdoc.From, ivdoc.To)}); err != nil {
|
||||
logger.Println("InviteAsFriend failed:", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
} else if exists {
|
||||
// 이미 친구
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -248,19 +258,18 @@ func (iv *invitation) InviteAsFriend(w http.ResponseWriter, r *http.Request) {
|
||||
// ivdoc.To가 invdoc.From을 차단했으면 표시
|
||||
exists, err := iv.mongoClient.Exists(block_collection_name, bson.M{"_id": combineObjectID(ivdoc.To, ivdoc.From)})
|
||||
if err != nil {
|
||||
logger.Println("IniviteAsFriend failed:", err)
|
||||
logger.Println("InviteAsFriend failed:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// exists면 차단된 상태
|
||||
ivdoc.Blocked = exists
|
||||
ivdoc.Timestamp = time.Now().UTC().Unix()
|
||||
_, newid, err := iv.mongoClient.Update(invitation_collection_name, bson.M{
|
||||
"_id": combineObjectID(ivdoc.From, ivdoc.To),
|
||||
}, bson.M{"$setOnInsert": ivdoc}, options.Update().SetUpsert(true))
|
||||
if err != nil || newid == nil {
|
||||
logger.Println("IniviteAsFriend failed:", err)
|
||||
logger.Println("InviteAsFriend failed:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user