@@ -4,16 +4,16 @@ import (
44 "net/http"
55
66 "github.com/gin-gonic/gin"
7+ "github.com/juggleim/commons/errs"
8+ "github.com/juggleim/commons/responses"
79 utils "github.com/juggleim/commons/tools"
8- "github.com/juggleim/jugglechat-server/admins/apis/responses"
9- "github.com/juggleim/jugglechat-server/admins/errs"
1010 "github.com/juggleim/jugglechat-server/admins/services"
1111)
1212
1313func Login (ctx * gin.Context ) {
1414 var req AccountReq
1515 if err := ctx .ShouldBindJSON (& req ); err != nil {
16- ctx .JSON (http .StatusBadRequest , & errs.ApiErrorMsg {
16+ ctx .JSON (http .StatusBadRequest , & errs.AdminApiErrorMsg {
1717 Code : errs .AdminErrorCode_ParamError ,
1818 Msg : "param illegal" ,
1919 })
@@ -23,20 +23,20 @@ func Login(ctx *gin.Context) {
2323 if code == errs .AdminErrorCode_Success {
2424 authStr , err := generateAuthorization (req .Account )
2525 if err != nil {
26- ctx .JSON (http .StatusInternalServerError , & errs.ApiErrorMsg {
26+ ctx .JSON (http .StatusInternalServerError , & errs.AdminApiErrorMsg {
2727 Code : errs .AdminErrorCode_Default ,
2828 Msg : "auth fail" ,
2929 })
3030 return
3131 }
32- responses .SuccessHttpResp (ctx , & LoginResp {
32+ responses .AdminSuccessHttpResp (ctx , & LoginResp {
3333 Account : req .Account ,
3434 Authorization : authStr ,
3535 Env : "private" , //public
3636 RoleId : account .RoleId ,
3737 })
3838 } else {
39- ctx .JSON (http .StatusOK , & errs.ApiErrorMsg {
39+ ctx .JSON (http .StatusOK , & errs.AdminApiErrorMsg {
4040 Code : code ,
4141 Msg : "login failed" ,
4242 })
@@ -60,59 +60,59 @@ type LoginResp struct {
6060func AddAccount (ctx * gin.Context ) {
6161 var req AccountReq
6262 if err := ctx .ShouldBindJSON (& req ); err != nil {
63- ctx .JSON (http .StatusBadRequest , & errs.ApiErrorMsg {
63+ ctx .JSON (http .StatusBadRequest , & errs.AdminApiErrorMsg {
6464 Code : errs .AdminErrorCode_ParamError ,
6565 Msg : "param illegal" ,
6666 })
6767 return
6868 }
6969 code := services .AddAccount (GetLoginedAccount (ctx ), req .Account , req .Password , req .RoleId )
70- ctx .JSON (http .StatusOK , & errs.ApiErrorMsg {
70+ ctx .JSON (http .StatusOK , & errs.AdminApiErrorMsg {
7171 Code : code ,
7272 })
7373}
7474
7575func UpdPassword (ctx * gin.Context ) {
7676 var req AccountReq
7777 if err := ctx .ShouldBindJSON (& req ); err != nil {
78- ctx .JSON (http .StatusBadRequest , & errs.ApiErrorMsg {
78+ ctx .JSON (http .StatusBadRequest , & errs.AdminApiErrorMsg {
7979 Code : errs .AdminErrorCode_ParamError ,
8080 Msg : "param illegal" ,
8181 })
8282 return
8383 }
8484 code := services .UpdPassword (req .Account , req .Password , req .NewPassword )
85- ctx .JSON (http .StatusOK , & errs.ApiErrorMsg {
85+ ctx .JSON (http .StatusOK , & errs.AdminApiErrorMsg {
8686 Code : code ,
8787 })
8888}
8989
9090func DisableAccounts (ctx * gin.Context ) {
9191 var req AccountsReq
9292 if err := ctx .ShouldBindJSON (& req ); err != nil || len (req .Accounts ) <= 0 {
93- ctx .JSON (http .StatusBadRequest , & errs.ApiErrorMsg {
93+ ctx .JSON (http .StatusBadRequest , & errs.AdminApiErrorMsg {
9494 Code : errs .AdminErrorCode_ParamError ,
9595 Msg : "param illegal" ,
9696 })
9797 return
9898 }
9999 code := services .DisableAccounts (req .Accounts , req .IsDisable )
100- ctx .JSON (http .StatusOK , & errs.ApiErrorMsg {
100+ ctx .JSON (http .StatusOK , & errs.AdminApiErrorMsg {
101101 Code : code ,
102102 })
103103}
104104
105105func DeleteAccounts (ctx * gin.Context ) {
106106 var req AccountsReq
107107 if err := ctx .ShouldBindJSON (& req ); err != nil || len (req .Accounts ) <= 0 {
108- ctx .JSON (http .StatusBadRequest , & errs.ApiErrorMsg {
108+ ctx .JSON (http .StatusBadRequest , & errs.AdminApiErrorMsg {
109109 Code : errs .AdminErrorCode_ParamError ,
110110 Msg : "param illegal" ,
111111 })
112112 return
113113 }
114114 code := services .DeleteAccounts (req .Accounts )
115- ctx .JSON (http .StatusOK , & errs.ApiErrorMsg {
115+ ctx .JSON (http .StatusOK , & errs.AdminApiErrorMsg {
116116 Code : code ,
117117 })
118118}
0 commit comments