Removing code which doesn't make sense
This commit is contained in:
@@ -19,7 +19,7 @@ const (
|
||||
|
||||
type InviteMemberRequest struct {
|
||||
Email string `json:"email" binding:"required"`
|
||||
StorageLimit string `json:"storageLimit" binding:"required"`
|
||||
StorageLimit int64 `json:"storageLimit" binding:"omitempty"`
|
||||
}
|
||||
|
||||
type InviteInfoResponse struct {
|
||||
|
||||
@@ -2,7 +2,6 @@ package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/ente-io/museum/pkg/controller/family"
|
||||
"github.com/ente-io/stacktrace"
|
||||
@@ -17,7 +16,6 @@ import (
|
||||
|
||||
// "github.com/ente-io/museum/pkg/utils/time"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// FamilyHandler contains handlers for managing family plans
|
||||
@@ -43,19 +41,9 @@ func (h *FamilyHandler) InviteMember(c *gin.Context) {
|
||||
handler.Error(c, stacktrace.Propagate(err, "Could not bind request params"))
|
||||
return
|
||||
}
|
||||
storageLimit, err := strconv.ParseInt(request.StorageLimit, 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
familyMembershipID, err := uuid.Parse(c.Param("id"))
|
||||
logrus.Println("Hey hey hey, here I am, you're finding me", familyMembershipID)
|
||||
err := h.Controller.InviteMember(c, auth.GetUserID(c.Request.Header), request.Email, request.StorageLimit)
|
||||
if err != nil {
|
||||
stacktrace.Propagate(err, "Invalid Membership ID")
|
||||
}
|
||||
|
||||
inviteReq := h.Controller.InviteMember(c, auth.GetUserID(c.Request.Header), request.Email, familyMembershipID, storageLimit)
|
||||
if inviteReq != nil {
|
||||
handler.Error(c, stacktrace.Propagate(err, ""))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (c *Controller) CreateFamily(ctx context.Context, adminUserID int64) error
|
||||
}
|
||||
|
||||
// InviteMember invites a user to join the family plan of admin User
|
||||
func (c *Controller) InviteMember(ctx *gin.Context, adminUserID int64, email string, memberUserID uuid.UUID, StorageLimit int64) error {
|
||||
func (c *Controller) InviteMember(ctx *gin.Context, adminUserID int64, email string, StorageLimit int64) error {
|
||||
err := c.BillingCtrl.IsActivePayingSubscriber(adminUserID)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(ente.ErrNoActiveSubscription, "you must be on a paid plan")
|
||||
@@ -120,7 +120,10 @@ func (c *Controller) InviteMember(ctx *gin.Context, adminUserID int64, email str
|
||||
}
|
||||
|
||||
if adminUser.FamilyAdminID != nil {
|
||||
err = c.FamilyRepo.UpdateStorage(ctx, adminUserID, StorageLimit, AcceptedTemplate)
|
||||
// hardcoded storageLimit
|
||||
// Will ideally come from the request
|
||||
StorageLimit = 1
|
||||
err := c.FamilyRepo.SetStorageLimit(ctx, StorageLimit, activeInviteToken)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(err, "failed to update storage limit")
|
||||
}
|
||||
|
||||
@@ -145,19 +145,13 @@ func (repo *FamilyRepository) GetMembersWithStatus(adminID int64, statuses []ent
|
||||
}
|
||||
|
||||
// UpdateStorage will set the value of storage for the given user by the Admin of the family.
|
||||
func (repo *FamilyRepository) UpdateStorage(ctx context.Context, adminID int64, storageLimit int64, token string) error {
|
||||
tx, err := repo.DB.BeginTx(ctx, nil)
|
||||
func (repo *FamilyRepository) SetStorageLimit(ctx context.Context, storageLimit int64, token string) error {
|
||||
// Need to ad a check related to admin here
|
||||
_, err := repo.DB.ExecContext(ctx, `UPDATE families SET storage=$1 WHERE token=$2`, storageLimit, token)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(err, "")
|
||||
}
|
||||
// Update Storage limit
|
||||
_, err = tx.ExecContext(ctx, `UPDATE users SET storage=$1 WHERE token=$2`, storageLimit, token)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return stacktrace.Propagate(err, "failed to update storage")
|
||||
}
|
||||
|
||||
return stacktrace.Propagate(tx.Commit(), "failed to commit txn for updating storage")
|
||||
return nil
|
||||
}
|
||||
|
||||
// AcceptInvite change the invitation status in the family db for the given invite token
|
||||
|
||||
Reference in New Issue
Block a user