fix: refs for cassandra db
This commit is contained in:
@@ -17,11 +17,9 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
|
||||
emailTemplate.ID = uuid.New().String()
|
||||
emailTemplate.Key = emailTemplate.ID
|
||||
}
|
||||
|
||||
emailTemplate.Key = emailTemplate.ID
|
||||
emailTemplate.CreatedAt = time.Now().Unix()
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
||||
_, err := emailTemplateCollection.CreateDocument(ctx, emailTemplate)
|
||||
if err != nil {
|
||||
@@ -33,13 +31,11 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
|
||||
// UpdateEmailTemplate to update EmailTemplate
|
||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||
|
||||
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
||||
meta, err := emailTemplateCollection.UpdateDocument(ctx, emailTemplate.Key, emailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
emailTemplate.Key = meta.Key
|
||||
emailTemplate.ID = meta.ID.String()
|
||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||
@@ -57,22 +53,18 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
|
||||
defer cursor.Close()
|
||||
paginationClone := pagination
|
||||
paginationClone.Total = cursor.Statistics().FullCount()
|
||||
|
||||
for {
|
||||
var emailTemplate *models.EmailTemplate
|
||||
meta, err := cursor.ReadDocument(ctx, &emailTemplate)
|
||||
|
||||
if arangoDriver.IsNoMoreDocuments(err) {
|
||||
break
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if meta.Key != "" {
|
||||
emailTemplates = append(emailTemplates, emailTemplate.AsAPIEmailTemplate())
|
||||
}
|
||||
}
|
||||
|
||||
return &model.EmailTemplates{
|
||||
Pagination: paginationClone,
|
||||
EmailTemplates: emailTemplates,
|
||||
@@ -86,16 +78,14 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
||||
bindVars := map[string]interface{}{
|
||||
"email_template_id": emailTemplateID,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if emailTemplate.Key == "" {
|
||||
if emailTemplate == nil {
|
||||
return nil, fmt.Errorf("email template not found")
|
||||
}
|
||||
break
|
||||
@@ -115,16 +105,14 @@ func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName st
|
||||
bindVars := map[string]interface{}{
|
||||
"event_name": eventName,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if emailTemplate.Key == "" {
|
||||
if emailTemplate == nil {
|
||||
return nil, fmt.Errorf("email template not found")
|
||||
}
|
||||
break
|
||||
|
@@ -48,16 +48,14 @@ func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env,
|
||||
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||
var env *models.Env
|
||||
query := fmt.Sprintf("FOR d in %s RETURN d", models.Collections.Env)
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, nil)
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if env.Key == "" {
|
||||
if env == nil {
|
||||
return env, fmt.Errorf("config not found")
|
||||
}
|
||||
break
|
||||
|
@@ -44,10 +44,8 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
||||
otp.Otp = otpParam.Otp
|
||||
otp.ExpiresAt = otpParam.ExpiresAt
|
||||
}
|
||||
|
||||
otp.UpdatedAt = time.Now().Unix()
|
||||
otpCollection, _ := p.db.Collection(ctx, models.Collections.OTP)
|
||||
|
||||
var meta driver.DocumentMeta
|
||||
var err error
|
||||
if shouldCreate {
|
||||
@@ -55,11 +53,9 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
||||
} else {
|
||||
meta, err = otpCollection.UpdateDocument(ctx, otp.Key, otp)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
otp.Key = meta.Key
|
||||
otp.ID = meta.ID.String()
|
||||
return otp, nil
|
||||
@@ -67,21 +63,19 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
||||
|
||||
// GetOTPByEmail to get otp for a given email address
|
||||
func (p *provider) GetOTPByEmail(ctx context.Context, emailAddress string) (*models.OTP, error) {
|
||||
var otp models.OTP
|
||||
var otp *models.OTP
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email RETURN d", models.Collections.OTP)
|
||||
bindVars := map[string]interface{}{
|
||||
"email": emailAddress,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if otp.Key == "" {
|
||||
if otp == nil {
|
||||
return nil, fmt.Errorf("otp with given email not found")
|
||||
}
|
||||
break
|
||||
@@ -91,13 +85,12 @@ func (p *provider) GetOTPByEmail(ctx context.Context, emailAddress string) (*mod
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &otp, nil
|
||||
return otp, nil
|
||||
}
|
||||
|
||||
// GetOTPByPhoneNumber to get otp for a given phone number
|
||||
func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string) (*models.OTP, error) {
|
||||
var otp models.OTP
|
||||
var otp *models.OTP
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d.phone_number == @phone_number RETURN d", models.Collections.OTP)
|
||||
bindVars := map[string]interface{}{
|
||||
"phone_number": phoneNumber,
|
||||
@@ -109,7 +102,7 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
||||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if otp.Key == "" {
|
||||
if otp == nil {
|
||||
return nil, fmt.Errorf("otp with given phone_number not found")
|
||||
}
|
||||
break
|
||||
@@ -119,8 +112,7 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &otp, nil
|
||||
return otp, nil
|
||||
}
|
||||
|
||||
// DeleteOTP to delete otp
|
||||
@@ -130,6 +122,5 @@ func (p *provider) DeleteOTP(ctx context.Context, otp *models.OTP) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -61,7 +61,6 @@ func NewProvider() (*provider, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var arangodb arangoDriver.Database
|
||||
dbName := memorystore.RequiredEnvStoreObj.GetRequiredEnv().DatabaseName
|
||||
arangodb_exists, err := arangoClient.DatabaseExists(ctx, dbName)
|
||||
@@ -79,7 +78,6 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
userCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.User)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -113,7 +111,6 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
verificationRequestCollection, err := arangodb.Collection(ctx, models.Collections.VerificationRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -136,7 +133,6 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
sessionCollection, err := arangodb.Collection(ctx, models.Collections.Session)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -144,7 +140,6 @@ func NewProvider() (*provider, error) {
|
||||
sessionCollection.EnsureHashIndex(ctx, []string{"user_id"}, &arangoDriver.EnsureHashIndexOptions{
|
||||
Sparse: true,
|
||||
})
|
||||
|
||||
envCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -155,7 +150,6 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
webhookCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Webhook)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -166,7 +160,6 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
webhookCollection, err := arangodb.Collection(ctx, models.Collections.Webhook)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -186,7 +179,6 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
webhookLogCollection, err := arangodb.Collection(ctx, models.Collections.WebhookLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -194,7 +186,6 @@ func NewProvider() (*provider, error) {
|
||||
webhookLogCollection.EnsureHashIndex(ctx, []string{"webhook_id"}, &arangoDriver.EnsureHashIndexOptions{
|
||||
Sparse: true,
|
||||
})
|
||||
|
||||
emailTemplateCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.EmailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -205,7 +196,6 @@ func NewProvider() (*provider, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
emailTemplateCollection, err := arangodb.Collection(ctx, models.Collections.EmailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -214,7 +204,6 @@ func NewProvider() (*provider, error) {
|
||||
Unique: true,
|
||||
Sparse: true,
|
||||
})
|
||||
|
||||
otpCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.OTP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -14,7 +14,6 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
||||
session.ID = uuid.New().String()
|
||||
session.Key = session.ID
|
||||
}
|
||||
|
||||
session.CreatedAt = time.Now().Unix()
|
||||
session.UpdatedAt = time.Now().Unix()
|
||||
sessionCollection, _ := p.db.Collection(ctx, models.Collections.Session)
|
||||
@@ -24,3 +23,8 @@ func (p *provider) AddSession(ctx context.Context, session *models.Session) erro
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession to delete session information from database
|
||||
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||
return nil
|
||||
}
|
||||
|
@@ -73,7 +73,6 @@ func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`FOR d IN %s FILTER d.user_id == @user_id REMOVE { _key: d._key } IN %s`, models.Collections.Session, models.Collections.Session)
|
||||
bindVars := map[string]interface{}{
|
||||
"user_id": user.Key,
|
||||
@@ -83,7 +82,6 @@ func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||
return err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -93,16 +91,13 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||
|
||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.User, pagination.Offset, pagination.Limit)
|
||||
|
||||
cursor, err := p.db.Query(sctx, query, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
paginationClone := pagination
|
||||
paginationClone.Total = cursor.Statistics().FullCount()
|
||||
|
||||
for {
|
||||
var user *models.User
|
||||
meta, err := cursor.ReadDocument(ctx, &user)
|
||||
@@ -115,7 +110,6 @@ func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination)
|
||||
users = append(users, user.AsAPIUser())
|
||||
}
|
||||
}
|
||||
|
||||
return &model.Users{
|
||||
Pagination: paginationClone,
|
||||
Users: users,
|
||||
@@ -136,7 +130,7 @@ func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.Us
|
||||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if user.Key == "" {
|
||||
if user == nil {
|
||||
return user, fmt.Errorf("user not found")
|
||||
}
|
||||
break
|
||||
@@ -163,7 +157,7 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, er
|
||||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if user.Key == "" {
|
||||
if user == nil {
|
||||
return user, fmt.Errorf("user not found")
|
||||
}
|
||||
break
|
||||
@@ -218,7 +212,7 @@ func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string)
|
||||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if user.Key == "" {
|
||||
if user == nil {
|
||||
return nil, fmt.Errorf("user not found")
|
||||
}
|
||||
break
|
||||
|
@@ -17,7 +17,6 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
||||
verificationRequest.ID = uuid.New().String()
|
||||
verificationRequest.Key = verificationRequest.ID
|
||||
}
|
||||
|
||||
verificationRequest.CreatedAt = time.Now().Unix()
|
||||
verificationRequest.UpdatedAt = time.Now().Unix()
|
||||
verificationRequestRequestCollection, _ := p.db.Collection(ctx, models.Collections.VerificationRequest)
|
||||
@@ -27,7 +26,6 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
||||
}
|
||||
verificationRequest.Key = meta.Key
|
||||
verificationRequest.ID = meta.ID.String()
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
@@ -38,16 +36,14 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
||||
bindVars := map[string]interface{}{
|
||||
"token": token,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if verificationRequest.Key == "" {
|
||||
if verificationRequest == nil {
|
||||
return verificationRequest, fmt.Errorf("verification request not found")
|
||||
}
|
||||
break
|
||||
@@ -57,29 +53,25 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
||||
return verificationRequest, err
|
||||
}
|
||||
}
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
// GetVerificationRequestByEmail to get verification request by email from database
|
||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||
var verificationRequest *models.VerificationRequest
|
||||
|
||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email FILTER d.identifier == @identifier LIMIT 1 RETURN d", models.Collections.VerificationRequest)
|
||||
bindVars := map[string]interface{}{
|
||||
"email": email,
|
||||
"identifier": identifier,
|
||||
}
|
||||
|
||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||
if err != nil {
|
||||
return verificationRequest, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if verificationRequest.Key == "" {
|
||||
if verificationRequest == nil {
|
||||
return verificationRequest, fmt.Errorf("verification request not found")
|
||||
}
|
||||
break
|
||||
@@ -89,7 +81,6 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
||||
return verificationRequest, err
|
||||
}
|
||||
}
|
||||
|
||||
return verificationRequest, nil
|
||||
}
|
||||
|
||||
@@ -120,7 +111,6 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination *mod
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return &model.VerificationRequests{
|
||||
VerificationRequests: verificationRequests,
|
||||
Pagination: paginationClone,
|
||||
|
@@ -95,7 +95,7 @@ func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model
|
||||
defer cursor.Close()
|
||||
for {
|
||||
if !cursor.HasMore() {
|
||||
if webhook.Key == "" {
|
||||
if webhook == nil {
|
||||
return nil, fmt.Errorf("webhook not found")
|
||||
}
|
||||
break
|
||||
|
@@ -17,7 +17,6 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.Webhook
|
||||
webhookLog.ID = uuid.New().String()
|
||||
webhookLog.Key = webhookLog.ID
|
||||
}
|
||||
|
||||
webhookLog.Key = webhookLog.ID
|
||||
webhookLog.CreatedAt = time.Now().Unix()
|
||||
webhookLog.UpdatedAt = time.Now().Unix()
|
||||
@@ -33,41 +32,33 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.Webhook
|
||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||
webhookLogs := []*model.WebhookLog{}
|
||||
bindVariables := map[string]interface{}{}
|
||||
|
||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||
|
||||
if webhookID != "" {
|
||||
query = fmt.Sprintf("FOR d in %s FILTER d.webhook_id == @webhook_id SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||
bindVariables = map[string]interface{}{
|
||||
"webhook_id": webhookID,
|
||||
}
|
||||
}
|
||||
|
||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||
cursor, err := p.db.Query(sctx, query, bindVariables)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close()
|
||||
|
||||
paginationClone := pagination
|
||||
paginationClone.Total = cursor.Statistics().FullCount()
|
||||
|
||||
for {
|
||||
var webhookLog *models.WebhookLog
|
||||
meta, err := cursor.ReadDocument(ctx, &webhookLog)
|
||||
|
||||
if arangoDriver.IsNoMoreDocuments(err) {
|
||||
break
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if meta.Key != "" {
|
||||
webhookLogs = append(webhookLogs, webhookLog.AsAPIWebhookLog())
|
||||
}
|
||||
}
|
||||
|
||||
return &model.WebhookLogs{
|
||||
Pagination: paginationClone,
|
||||
WebhookLogs: webhookLogs,
|
||||
|
Reference in New Issue
Block a user