use the request context
This commit is contained in:
+17
-16
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/datastore"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/mail"
|
||||
@@ -98,43 +99,43 @@ type ServiceUsingStorage struct {
|
||||
}
|
||||
|
||||
// ExistsAvatar returns whether the user avatar exists from the current avatar object storage
|
||||
func (s *ServiceUsingStorage) ExistsAvatar(uid int64, fileExtension string) (bool, error) {
|
||||
return s.container.ExistsAvatar(s.getUserAvatarPath(uid, fileExtension))
|
||||
func (s *ServiceUsingStorage) ExistsAvatar(ctx core.Context, uid int64, fileExtension string) (bool, error) {
|
||||
return s.container.ExistsAvatar(ctx, s.getUserAvatarPath(uid, fileExtension))
|
||||
}
|
||||
|
||||
// ReadAvatar returns the user avatar from the current avatar object storage
|
||||
func (s *ServiceUsingStorage) ReadAvatar(uid int64, fileExtension string) (storage.ObjectInStorage, error) {
|
||||
return s.container.ReadAvatar(s.getUserAvatarPath(uid, fileExtension))
|
||||
func (s *ServiceUsingStorage) ReadAvatar(ctx core.Context, uid int64, fileExtension string) (storage.ObjectInStorage, error) {
|
||||
return s.container.ReadAvatar(ctx, s.getUserAvatarPath(uid, fileExtension))
|
||||
}
|
||||
|
||||
// SaveAvatar returns whether save the user avatar into the current avatar object storage successfully
|
||||
func (s *ServiceUsingStorage) SaveAvatar(uid int64, object storage.ObjectInStorage, fileExtension string) error {
|
||||
return s.container.SaveAvatar(s.getUserAvatarPath(uid, fileExtension), object)
|
||||
func (s *ServiceUsingStorage) SaveAvatar(ctx core.Context, uid int64, object storage.ObjectInStorage, fileExtension string) error {
|
||||
return s.container.SaveAvatar(ctx, s.getUserAvatarPath(uid, fileExtension), object)
|
||||
}
|
||||
|
||||
// DeleteAvatar returns whether delete the user avatar from the current avatar object storage successfully
|
||||
func (s *ServiceUsingStorage) DeleteAvatar(uid int64, fileExtension string) error {
|
||||
return s.container.DeleteAvatar(s.getUserAvatarPath(uid, fileExtension))
|
||||
func (s *ServiceUsingStorage) DeleteAvatar(ctx core.Context, uid int64, fileExtension string) error {
|
||||
return s.container.DeleteAvatar(ctx, s.getUserAvatarPath(uid, fileExtension))
|
||||
}
|
||||
|
||||
// ExistsTransactionPicture returns whether the transaction picture exists from the current transaction picture object storage
|
||||
func (s *ServiceUsingStorage) ExistsTransactionPicture(uid int64, pictureId int64, fileExtension string) (bool, error) {
|
||||
return s.container.ExistsTransactionPicture(s.getTransactionPicturePath(uid, pictureId, fileExtension))
|
||||
func (s *ServiceUsingStorage) ExistsTransactionPicture(ctx core.Context, uid int64, pictureId int64, fileExtension string) (bool, error) {
|
||||
return s.container.ExistsTransactionPicture(ctx, s.getTransactionPicturePath(uid, pictureId, fileExtension))
|
||||
}
|
||||
|
||||
// ReadTransactionPicture returns the transaction picture from the current transaction picture object storage
|
||||
func (s *ServiceUsingStorage) ReadTransactionPicture(uid int64, pictureId int64, fileExtension string) (storage.ObjectInStorage, error) {
|
||||
return s.container.ReadTransactionPicture(s.getTransactionPicturePath(uid, pictureId, fileExtension))
|
||||
func (s *ServiceUsingStorage) ReadTransactionPicture(ctx core.Context, uid int64, pictureId int64, fileExtension string) (storage.ObjectInStorage, error) {
|
||||
return s.container.ReadTransactionPicture(ctx, s.getTransactionPicturePath(uid, pictureId, fileExtension))
|
||||
}
|
||||
|
||||
// SaveTransactionPicture returns whether save the transaction picture into the current transaction picture object storage successfully
|
||||
func (s *ServiceUsingStorage) SaveTransactionPicture(uid int64, pictureId int64, object storage.ObjectInStorage, fileExtension string) error {
|
||||
return s.container.SaveTransactionPicture(s.getTransactionPicturePath(uid, pictureId, fileExtension), object)
|
||||
func (s *ServiceUsingStorage) SaveTransactionPicture(ctx core.Context, uid int64, pictureId int64, object storage.ObjectInStorage, fileExtension string) error {
|
||||
return s.container.SaveTransactionPicture(ctx, s.getTransactionPicturePath(uid, pictureId, fileExtension), object)
|
||||
}
|
||||
|
||||
// DeleteTransactionPicture returns whether delete the transaction picture from the current transaction picture object storage successfully
|
||||
func (s *ServiceUsingStorage) DeleteTransactionPicture(uid int64, pictureId int64, fileExtension string) error {
|
||||
return s.container.DeleteTransactionPicture(s.getTransactionPicturePath(uid, pictureId, fileExtension))
|
||||
func (s *ServiceUsingStorage) DeleteTransactionPicture(ctx core.Context, uid int64, pictureId int64, fileExtension string) error {
|
||||
return s.container.DeleteTransactionPicture(ctx, s.getTransactionPicturePath(uid, pictureId, fileExtension))
|
||||
}
|
||||
|
||||
func (s *ServiceUsingStorage) getUserAvatarPath(uid int64, fileExtension string) string {
|
||||
|
||||
@@ -159,7 +159,7 @@ func (s *TransactionPictureService) GetPictureByPictureId(c core.Context, uid in
|
||||
return nil, errs.ErrTransactionPictureExtensionInvalid
|
||||
}
|
||||
|
||||
pictureFile, err := s.ReadTransactionPicture(pictureInfo.Uid, pictureInfo.PictureId, pictureInfo.PictureExtension)
|
||||
pictureFile, err := s.ReadTransactionPicture(c, pictureInfo.Uid, pictureInfo.PictureId, pictureInfo.PictureExtension)
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return nil, errs.ErrTransactionPictureNoExists
|
||||
@@ -199,7 +199,7 @@ func (s *TransactionPictureService) UploadPicture(c core.Context, pictureInfo *m
|
||||
pictureInfo.CreatedUnixTime = time.Now().Unix()
|
||||
pictureInfo.UpdatedUnixTime = time.Now().Unix()
|
||||
|
||||
err := s.SaveTransactionPicture(pictureInfo.Uid, pictureInfo.PictureId, pictureFile, pictureInfo.PictureExtension)
|
||||
err := s.SaveTransactionPicture(c, pictureInfo.Uid, pictureInfo.PictureId, pictureFile, pictureInfo.PictureExtension)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -162,7 +162,7 @@ func (s *UserService) GetUserAvatar(c core.Context, uid int64, fileExtension str
|
||||
return nil, errs.ErrUserAvatarExtensionInvalid
|
||||
}
|
||||
|
||||
avatarFile, err := s.ReadAvatar(user.Uid, user.CustomAvatarType)
|
||||
avatarFile, err := s.ReadAvatar(c, user.Uid, user.CustomAvatarType)
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return nil, errs.ErrUserAvatarNoExists
|
||||
@@ -371,7 +371,7 @@ func (s *UserService) UpdateUserAvatar(c core.Context, uid int64, avatarFile mul
|
||||
|
||||
defer avatarFile.Close()
|
||||
|
||||
err := s.SaveAvatar(uid, avatarFile, fileExtension)
|
||||
err := s.SaveAvatar(c, uid, avatarFile, fileExtension)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -394,7 +394,7 @@ func (s *UserService) UpdateUserAvatar(c core.Context, uid int64, avatarFile mul
|
||||
}
|
||||
|
||||
if fileExtension != oldFileExtension && oldFileExtension != "" {
|
||||
err = s.DeleteAvatar(uid, oldFileExtension)
|
||||
err = s.DeleteAvatar(c, uid, oldFileExtension)
|
||||
|
||||
if err != nil {
|
||||
log.Warnf(c, "[users.UpdateUserAvatar] failed to delete old avatar with extension \"%s\" for user \"uid:%d\", because %s", oldFileExtension, uid, err.Error())
|
||||
@@ -410,7 +410,7 @@ func (s *UserService) RemoveUserAvatar(c core.Context, uid int64, fileExtension
|
||||
return errs.ErrUserIdInvalid
|
||||
}
|
||||
|
||||
err := s.DeleteAvatar(uid, fileExtension)
|
||||
err := s.DeleteAvatar(c, uid, fileExtension)
|
||||
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user