Add API to update referral code
This commit is contained in:
@@ -612,6 +612,7 @@ func main() {
|
||||
}
|
||||
|
||||
privateAPI.GET("/storage-bonus/details", storageBonusHandler.GetStorageBonusDetails)
|
||||
privateAPI.GET("/storage-bonus/change-code", storageBonusHandler.UpdateReferralCode)
|
||||
privateAPI.GET("/storage-bonus/referral-view", storageBonusHandler.GetReferralView)
|
||||
privateAPI.POST("/storage-bonus/referral-claim", storageBonusHandler.ClaimReferral)
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ type UserReferralPlanStat struct {
|
||||
UpgradedCount int `json:"upgradedCount"`
|
||||
}
|
||||
|
||||
type UpdateReferralCodeRequest struct {
|
||||
Code string `json:"code" binding:"required"`
|
||||
}
|
||||
|
||||
// PlanInfo represents the referral plan metadata
|
||||
type PlanInfo struct {
|
||||
// IsEnabled indicates if the referral plan is enabled for given user
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/ente-io/museum/ente"
|
||||
entity "github.com/ente-io/museum/ente/storagebonus"
|
||||
"github.com/ente-io/museum/pkg/controller/storagebonus"
|
||||
"github.com/ente-io/museum/pkg/utils/auth"
|
||||
"github.com/ente-io/museum/pkg/utils/handler"
|
||||
@@ -24,6 +25,21 @@ func (h StorageBonusHandler) GetReferralView(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (h StorageBonusHandler) UpdateReferralCode(context *gin.Context) {
|
||||
var request entity.UpdateReferralCodeRequest
|
||||
if err := context.ShouldBindJSON(&request); err != nil {
|
||||
handler.Error(context, stacktrace.Propagate(ente.NewBadRequestWithMessage(err.Error()), ""))
|
||||
return
|
||||
}
|
||||
userID := auth.GetUserID(context.Request.Header)
|
||||
err := h.Controller.UpdateReferralCode(context, userID, request.Code)
|
||||
if err != nil {
|
||||
handler.Error(context, stacktrace.Propagate(err, ""))
|
||||
return
|
||||
}
|
||||
context.JSON(http.StatusOK, gin.H{})
|
||||
}
|
||||
|
||||
func (h StorageBonusHandler) GetStorageBonusDetails(context *gin.Context) {
|
||||
response, err := h.Controller.GetStorageBonusDetailResponse(context, auth.GetUserID(context.Request.Header))
|
||||
if err != nil {
|
||||
|
||||
@@ -55,7 +55,7 @@ func (r *Repository) AddNewCode(ctx context.Context, userID int64, code string)
|
||||
}
|
||||
_, err = r.DB.ExecContext(ctx, "UPDATE referral_codes SET is_active = FALSE WHERE user_id = $1", userID)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(err, "failed to update storagebonus code for user %d", userID)
|
||||
return stacktrace.Propagate(err, "failed to update remove existing code code for user %d", userID)
|
||||
}
|
||||
return r.InsertCode(ctx, userID, code)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user