From 61527882d15a11f88d8ef15c5da070b9bff049a0 Mon Sep 17 00:00:00 2001 From: Howl Date: Fri, 2 Sep 2016 18:27:15 +0200 Subject: [PATCH] Get donor info through /users/self/donor_info --- app/start.go | 1 + app/v1/self.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 app/v1/self.go diff --git a/app/start.go b/app/start.go index 278e300..b511d52 100644 --- a/app/start.go +++ b/app/start.go @@ -95,6 +95,7 @@ func Start(conf common.Conf, dbO *sqlx.DB) *gin.Engine { // ReadConfidential privilege required gv1.GET("/friends", Method(v1.FriendsGET, common.PrivilegeReadConfidential)) gv1.GET("/friends/with", Method(v1.FriendsWithGET, common.PrivilegeReadConfidential)) + gv1.GET("/users/self/donor_info", Method(v1.UsersSelfDonorInfoGET, common.PrivilegeReadConfidential)) // Write privilege required gv1.GET("/friends/add", Method(v1.FriendsAddGET, common.PrivilegeWrite)) diff --git a/app/v1/self.go b/app/v1/self.go new file mode 100644 index 0000000..280671e --- /dev/null +++ b/app/v1/self.go @@ -0,0 +1,24 @@ +package v1 + +import "git.zxq.co/ripple/rippleapi/common" + +type donorInfoResponse struct { + common.ResponseBase + HasDonor bool `json:"has_donor"` + Expiration common.UnixTimestamp `json:"expiration"` +} + +// UsersSelfDonorInfoGET returns information about the users' donor status +func UsersSelfDonorInfoGET(md common.MethodData) common.CodeMessager { + var r donorInfoResponse + var privileges uint64 + err := md.DB.QueryRow("SELECT privileges, donor_expire FROM users WHERE id = ?", md.ID()). + Scan(&privileges, &r.Expiration) + if err != nil { + md.Err(err) + return Err500 + } + r.HasDonor = common.UserPrivileges(privileges)&common.UserPrivilegeDonor > 0 + r.Code = 200 + return r +}