Commit d067dff387be8f7474b474eead125988b73b0a2a
1 parent
443d5d29
Exists in
master
好友相关接口
Showing
5 changed files
with
169 additions
and
2 deletions
Show diff stats
src/HttpServer/logic/datadef.go
@@ -503,6 +503,30 @@ type GetRecommendListResp struct { | @@ -503,6 +503,30 @@ type GetRecommendListResp struct { | ||
503 | Result GetRecommendListResult `json:"result"` | 503 | Result GetRecommendListResult `json:"result"` |
504 | } | 504 | } |
505 | 505 | ||
506 | + | ||
507 | +type HandleFriendRequestReq struct{ | ||
508 | + Token string `json:"token"` | ||
509 | + User_id int `json:"user_id"` | ||
510 | + Type int `json:"type"` | ||
511 | +} | ||
512 | + | ||
513 | + | ||
514 | +type HandleFriendRequestResp struct { | ||
515 | + Status string `json:"status"` | ||
516 | + Result CommonResult `json:"result"` | ||
517 | +} | ||
518 | + | ||
519 | +type DelFriendReq struct{ | ||
520 | + Token string `json:"token"` | ||
521 | + User_id int `json:"user_id"` | ||
522 | +} | ||
523 | + | ||
524 | + | ||
525 | +type DelFriendResp struct { | ||
526 | + Status string `json:"status"` | ||
527 | + Result CommonResult `json:"result"` | ||
528 | +} | ||
529 | + | ||
506 | //********************************************************************************************************** | 530 | //********************************************************************************************************** |
507 | 531 | ||
508 | 532 |
src/HttpServer/logic/errordef.go
@@ -30,4 +30,8 @@ const ( | @@ -30,4 +30,8 @@ const ( | ||
30 | RROR_FRIENDINAPPROVELISTFAILED = 25 //已经在等待批准列表 | 30 | RROR_FRIENDINAPPROVELISTFAILED = 25 //已经在等待批准列表 |
31 | ERROR_FRIENDAPPROVELIMIT = 26 //当日批准已达上限 | 31 | ERROR_FRIENDAPPROVELIMIT = 26 //当日批准已达上限 |
32 | ERROR_FRIENDGETRECOMMADNFAILED = 27 //获取推荐好友失败 | 32 | ERROR_FRIENDGETRECOMMADNFAILED = 27 //获取推荐好友失败 |
33 | + ERROR_NOTINAPPROVELIST = 28 //玩家不在好友申请列表 | ||
34 | + ERROR_FRIENDAPPROVEFAILED = 29 //好友审批失败 | ||
35 | + ERROR_FRIENDNOTFRIEND = 30 //不是好友 | ||
36 | + ERROR_FRIENDDELFRIENDFAILED = 31 //删除好友失败 | ||
33 | ) | 37 | ) |
34 | \ No newline at end of file | 38 | \ No newline at end of file |
src/HttpServer/logic/function.go
@@ -393,6 +393,11 @@ func (alist *ApproveList) InApproveList(uuid int) bool { | @@ -393,6 +393,11 @@ func (alist *ApproveList) InApproveList(uuid int) bool { | ||
393 | return false | 393 | return false |
394 | } | 394 | } |
395 | 395 | ||
396 | +// | ||
397 | +func DelFromApproveList(uuid,deluuid int) error { | ||
398 | + return nil | ||
399 | +} | ||
400 | + | ||
396 | //待批准列表 | 401 | //待批准列表 |
397 | func GetUserApproveList(uuid int) (*ApproveList,error) { | 402 | func GetUserApproveList(uuid int) (*ApproveList,error) { |
398 | rt := new(ApproveList) | 403 | rt := new(ApproveList) |
@@ -512,11 +517,11 @@ func GetUserFriendList(uuid int) (*FriendList,error) { | @@ -512,11 +517,11 @@ func GetUserFriendList(uuid int) (*FriendList,error) { | ||
512 | return rt,nil | 517 | return rt,nil |
513 | } | 518 | } |
514 | 519 | ||
515 | -func SaveUserFriendList(uuid int,adduuid int) error { | 520 | +func SaveUserFriendList(uuid int,adduuid int,status int) error { |
516 | userkey := redis.FRIEND_LIST_KEY + ":" + strconv.Itoa(uuid) | 521 | userkey := redis.FRIEND_LIST_KEY + ":" + strconv.Itoa(uuid) |
517 | var finfo FriendInfo | 522 | var finfo FriendInfo |
518 | finfo.Uuid = adduuid | 523 | finfo.Uuid = adduuid |
519 | - finfo.Status = 0 | 524 | + finfo.Status = status |
520 | str,err := json.Marshal(&finfo) | 525 | str,err := json.Marshal(&finfo) |
521 | if err != nil { | 526 | if err != nil { |
522 | logger.Error("SaveUserFriendList failed,err=%v",err) | 527 | logger.Error("SaveUserFriendList failed,err=%v",err) |
src/HttpServer/logic/httpserver.go
@@ -50,6 +50,8 @@ func startServerHttpServe() { | @@ -50,6 +50,8 @@ func startServerHttpServe() { | ||
50 | http.HandleFunc("/catcafe/friend/getList", GetFriendList) //获取好友列表 | 50 | http.HandleFunc("/catcafe/friend/getList", GetFriendList) //获取好友列表 |
51 | http.HandleFunc("/catcafe/friend/getAuditList", GetAuditList) //获取待审核好友列表 | 51 | http.HandleFunc("/catcafe/friend/getAuditList", GetAuditList) //获取待审核好友列表 |
52 | http.HandleFunc("/catcafe/friend/getRecommendList", GetRecommendList) //获取推荐好友列表 | 52 | http.HandleFunc("/catcafe/friend/getRecommendList", GetRecommendList) //获取推荐好友列表 |
53 | + http.HandleFunc("/catcafe/friend/handleFriendRequest", HandleFriendRequest) //处理好友请求 | ||
54 | + http.HandleFunc("/catcafe/friend/delFriend", DelFriend) //删除好友 | ||
53 | 55 | ||
54 | 56 | ||
55 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) | 57 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
@@ -57,6 +59,30 @@ func startServerHttpServe() { | @@ -57,6 +59,30 @@ func startServerHttpServe() { | ||
57 | } | 59 | } |
58 | 60 | ||
59 | 61 | ||
62 | +func DelFriend(w http.ResponseWriter, r *http.Request) { | ||
63 | + | ||
64 | + result, _ := ioutil.ReadAll(r.Body) | ||
65 | + r.Body.Close() | ||
66 | + | ||
67 | + s := string(result) | ||
68 | + logger.Info("DelFriend , body:%v,uuid=%v", s) | ||
69 | + | ||
70 | + HandleDelFriend(w,s) | ||
71 | +} | ||
72 | + | ||
73 | + | ||
74 | +func HandleFriendRequest(w http.ResponseWriter, r *http.Request) { | ||
75 | + | ||
76 | + result, _ := ioutil.ReadAll(r.Body) | ||
77 | + r.Body.Close() | ||
78 | + | ||
79 | + s := string(result) | ||
80 | + logger.Info("HandleFriendRequest , body:%v,uuid=%v", s) | ||
81 | + | ||
82 | + HandleHandleFriendRequest(w,s) | ||
83 | +} | ||
84 | + | ||
85 | + | ||
60 | func GetRecommendList(w http.ResponseWriter, r *http.Request) { | 86 | func GetRecommendList(w http.ResponseWriter, r *http.Request) { |
61 | 87 | ||
62 | result, _ := ioutil.ReadAll(r.Body) | 88 | result, _ := ioutil.ReadAll(r.Body) |
src/HttpServer/logic/logic.go
@@ -1381,4 +1381,112 @@ func HandleGetRecommendList(w http.ResponseWriter, data string) { | @@ -1381,4 +1381,112 @@ func HandleGetRecommendList(w http.ResponseWriter, data string) { | ||
1381 | //回包 | 1381 | //回包 |
1382 | respstr, _ := json.Marshal(&resp) | 1382 | respstr, _ := json.Marshal(&resp) |
1383 | fmt.Fprint(w, string(respstr)) | 1383 | fmt.Fprint(w, string(respstr)) |
1384 | +} | ||
1385 | + | ||
1386 | + | ||
1387 | +func HandleHandleFriendRequest(w http.ResponseWriter, data string) { | ||
1388 | + SetHeader(w) | ||
1389 | + var resp HandleFriendRequestResp | ||
1390 | + resp.Status = "true" | ||
1391 | + resp.Result.Code = ERROR_OK | ||
1392 | + var rdata HandleFriendRequestReq | ||
1393 | + err := json.Unmarshal([]byte(data), &rdata) | ||
1394 | + for { | ||
1395 | + if err != nil { | ||
1396 | + logger.Error("HandleHandleFriendRequest json unmarshal failed=%v", err) | ||
1397 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
1398 | + break | ||
1399 | + } | ||
1400 | + | ||
1401 | + uuid,err := GetTouristUid(rdata.Token) | ||
1402 | + if err != nil || uuid==0{ | ||
1403 | + logger.Error("HandleHandleFriendRequest GetTouristUid failed=%v", err) | ||
1404 | + resp.Result.Code = ERROR_GETUSERIDFAILED | ||
1405 | + break | ||
1406 | + } | ||
1407 | + | ||
1408 | + approvelist,err := GetUserApproveList(uuid) | ||
1409 | + if !approvelist.InApproveList(rdata.User_id) { | ||
1410 | + logger.Error("HandleHandleFriendRequest NOTINAPPROVELIST failed=%v", err) | ||
1411 | + resp.Result.Code = ERROR_NOTINAPPROVELIST | ||
1412 | + break | ||
1413 | + } | ||
1414 | + | ||
1415 | + //从待批准列表删除 | ||
1416 | + err = DelFromApproveList(uuid,rdata.User_id) | ||
1417 | + if err != nil { | ||
1418 | + logger.Error("HandleHandleFriendRequest ERROR_FRIENDAPPROVEFAILED failed=%v", err) | ||
1419 | + resp.Result.Code = ERROR_FRIENDAPPROVEFAILED | ||
1420 | + break | ||
1421 | + } | ||
1422 | + | ||
1423 | + if rdata.Type == 0 { | ||
1424 | + //如果同意将其加入好友列表 status 1表示删除 0表示未删除 | ||
1425 | + err = SaveUserFriendList(uuid,rdata.User_id,0) | ||
1426 | + if err != nil { | ||
1427 | + logger.Error("HandleHandleFriendRequest ERROR_FRIENDAPPROVEFAILED failed=%v", err) | ||
1428 | + resp.Result.Code = ERROR_FRIENDAPPROVEFAILED | ||
1429 | + break | ||
1430 | + } | ||
1431 | + } | ||
1432 | + | ||
1433 | + | ||
1434 | + resp.Result.Code = ERROR_OK | ||
1435 | + break | ||
1436 | + } | ||
1437 | + | ||
1438 | + //回包 | ||
1439 | + respstr, _ := json.Marshal(&resp) | ||
1440 | + fmt.Fprint(w, string(respstr)) | ||
1441 | +} | ||
1442 | + | ||
1443 | + | ||
1444 | +func HandleDelFriend(w http.ResponseWriter, data string) { | ||
1445 | + SetHeader(w) | ||
1446 | + var resp DelFriendResp | ||
1447 | + resp.Status = "true" | ||
1448 | + resp.Result.Code = ERROR_OK | ||
1449 | + var rdata DelFriendReq | ||
1450 | + err := json.Unmarshal([]byte(data), &rdata) | ||
1451 | + for { | ||
1452 | + if err != nil { | ||
1453 | + logger.Error("HandleDelFriend json unmarshal failed=%v", err) | ||
1454 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
1455 | + break | ||
1456 | + } | ||
1457 | + | ||
1458 | + uuid,err := GetTouristUid(rdata.Token) | ||
1459 | + if err != nil || uuid==0{ | ||
1460 | + logger.Error("HandleDelFriend GetTouristUid failed=%v", err) | ||
1461 | + resp.Result.Code = ERROR_GETUSERIDFAILED | ||
1462 | + break | ||
1463 | + } | ||
1464 | + | ||
1465 | + friendlist,err := GetUserFriendList(uuid) | ||
1466 | + if err != nil { | ||
1467 | + logger.Error("HandleDelFriend GetFriendList failed=%v", err) | ||
1468 | + resp.Result.Code = ERROR_GETFRIENDLISTAILED | ||
1469 | + break | ||
1470 | + } | ||
1471 | + if !friendlist.IsInFreiendList(rdata.User_id) { | ||
1472 | + logger.Error("HandleSetFriendRequest ERROR_FRIENDNOTFRIEND failed=%v", err) | ||
1473 | + resp.Result.Code = ERROR_FRIENDNOTFRIEND | ||
1474 | + break | ||
1475 | + } | ||
1476 | + | ||
1477 | + err = SaveUserFriendList(uuid,rdata.User_id,1) | ||
1478 | + if err != nil { | ||
1479 | + logger.Error("HandleSetFriendRequest ERROR_FRIENDAPPROVEFAILED failed=%v", err) | ||
1480 | + resp.Result.Code = ERROR_FRIENDDELFRIENDFAILED | ||
1481 | + break | ||
1482 | + } | ||
1483 | + | ||
1484 | + | ||
1485 | + resp.Result.Code = ERROR_OK | ||
1486 | + break | ||
1487 | + } | ||
1488 | + | ||
1489 | + //回包 | ||
1490 | + respstr, _ := json.Marshal(&resp) | ||
1491 | + fmt.Fprint(w, string(respstr)) | ||
1384 | } | 1492 | } |
1385 | \ No newline at end of file | 1493 | \ No newline at end of file |