feat: add DeletePinByHash
This commit is contained in:
parent
a5cbb4c4fb
commit
1a5aaa3927
|
@ -4,6 +4,7 @@ import (
|
||||||
"git.lumeweb.com/LumeWeb/portal/db/models"
|
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||||
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -123,3 +124,36 @@ func (s AccountServiceImpl) AccountPins(id uint64, createdAfter uint64) ([]model
|
||||||
|
|
||||||
return pins, nil
|
return pins, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s AccountServiceImpl) DeletePinByHash(hash string, accountID uint) error {
|
||||||
|
// Define a struct for the query condition
|
||||||
|
uploadQuery := models.Upload{Hash: hash}
|
||||||
|
|
||||||
|
// Retrieve the upload ID for the given hash
|
||||||
|
var uploadID uint
|
||||||
|
result := s.portal.Database().
|
||||||
|
Model(&models.Upload{}).
|
||||||
|
Where(&uploadQuery).
|
||||||
|
Select("id").
|
||||||
|
First(&uploadID)
|
||||||
|
|
||||||
|
if result.Error != nil {
|
||||||
|
if result.Error == gorm.ErrRecordNotFound {
|
||||||
|
// No record found, nothing to delete
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete pins with the retrieved upload ID and matching account ID
|
||||||
|
pinQuery := models.Pin{UploadID: uploadID, UserID: accountID}
|
||||||
|
result = s.portal.Database().
|
||||||
|
Where(&pinQuery).
|
||||||
|
Delete(&models.Pin{})
|
||||||
|
|
||||||
|
if result.Error != nil {
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -11,4 +11,5 @@ type AccountService interface {
|
||||||
LoginPassword(email string, password string) (string, error)
|
LoginPassword(email string, password string) (string, error)
|
||||||
LoginPubkey(pubkey string) (string, error)
|
LoginPubkey(pubkey string) (string, error)
|
||||||
AccountPins(id uint64, createdAfter uint64) ([]models.Pin, error)
|
AccountPins(id uint64, createdAfter uint64) ([]models.Pin, error)
|
||||||
|
DeletePinByHash(hash string, accountID uint) error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue