fix : update logo clients
This commit is contained in:
parent
840acca7fe
commit
88db076da6
|
|
@ -30,7 +30,7 @@ func NewClientLogoUploadService(minioStorage *config.MinioStorage, log zerolog.L
|
|||
}
|
||||
|
||||
// UploadLogo uploads client logo to MinIO and returns the image path
|
||||
func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName string) (string, error) {
|
||||
func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName string) (string, string, error) {
|
||||
|
||||
s.Log.Info().
|
||||
Str("UploadLogo", clientId).
|
||||
|
|
@ -39,7 +39,7 @@ func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName
|
|||
// Get the uploaded file
|
||||
file, err := c.FormFile("logo")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get uploaded file: %w", err)
|
||||
return "", "", fmt.Errorf("failed to get uploaded file: %w", err)
|
||||
}
|
||||
|
||||
s.Log.Info().
|
||||
|
|
@ -47,7 +47,7 @@ func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName
|
|||
|
||||
// Validate file type
|
||||
if !s.isValidImageType(file.Filename) {
|
||||
return "", fmt.Errorf("invalid file type. Only jpg, jpeg, png, gif, webp are allowed")
|
||||
return "", "", fmt.Errorf("invalid file type. Only jpg, jpeg, png, gif, webp are allowed")
|
||||
}
|
||||
|
||||
s.Log.Info().
|
||||
|
|
@ -56,13 +56,13 @@ func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName
|
|||
// Validate file size (max 5MB)
|
||||
const maxSize = 5 * 1024 * 1024 // 5MB
|
||||
if file.Size > maxSize {
|
||||
return "", fmt.Errorf("file size too large. Maximum size is 5MB")
|
||||
return "", "", fmt.Errorf("file size too large. Maximum size is 5MB")
|
||||
}
|
||||
|
||||
// Create MinIO connection
|
||||
minioClient, err := s.MinioStorage.ConnectMinio()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to connect to MinIO: %w", err)
|
||||
return "", "", fmt.Errorf("failed to connect to MinIO: %w", err)
|
||||
}
|
||||
|
||||
bucketName := s.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||
|
|
@ -77,7 +77,7 @@ func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName
|
|||
// Open file
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to open uploaded file: %w", err)
|
||||
return "", "", fmt.Errorf("failed to open uploaded file: %w", err)
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName
|
|||
},
|
||||
)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to upload file to MinIO: %w", err)
|
||||
return "", "", fmt.Errorf("failed to upload file to MinIO: %w", err)
|
||||
}
|
||||
|
||||
s.Log.Info().
|
||||
|
|
@ -103,7 +103,7 @@ func (s *ClientLogoUploadService) UploadLogo(c *fiber.Ctx, clientId, clientName
|
|||
Int64("fileSize", file.Size).
|
||||
Msg("Client logo uploaded successfully")
|
||||
|
||||
return objectName, nil
|
||||
return objectName, filename, nil
|
||||
}
|
||||
|
||||
// DeleteLogo deletes client logo from MinIO
|
||||
|
|
|
|||
|
|
@ -19,12 +19,14 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
config "netidhub-saas-be/config/config"
|
||||
utilSvc "netidhub-saas-be/utils/service"
|
||||
)
|
||||
|
||||
// ClientsService
|
||||
type clientsService struct {
|
||||
Repo repository.ClientsRepository
|
||||
Cfg *config.Config
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
UsersSvc usersService.UsersService
|
||||
ClientLogoUploadSvc *ClientLogoUploadService
|
||||
|
|
@ -60,10 +62,11 @@ type ClientsService interface {
|
|||
}
|
||||
|
||||
// NewClientsService init ClientsService
|
||||
func NewClientsService(repo repository.ClientsRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository, usersSvc usersService.UsersService, clientLogoUploadSvc *ClientLogoUploadService) ClientsService {
|
||||
func NewClientsService(repo repository.ClientsRepository, cfg *config.Config, log zerolog.Logger, usersRepo usersRepository.UsersRepository, usersSvc usersService.UsersService, clientLogoUploadSvc *ClientLogoUploadService) ClientsService {
|
||||
|
||||
return &clientsService{
|
||||
Repo: repo,
|
||||
Cfg: cfg,
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
UsersSvc: usersSvc,
|
||||
|
|
@ -550,7 +553,7 @@ func (_i *clientsService) UploadLogo(authToken string, c *fiber.Ctx) (string, er
|
|||
}
|
||||
|
||||
// Upload logo using the upload service
|
||||
imagePath, err := _i.ClientLogoUploadSvc.UploadLogo(c, clientId.String(), client.Name)
|
||||
imagePath, newFilename, err := _i.ClientLogoUploadSvc.UploadLogo(c, clientId.String(), client.Name)
|
||||
if err != nil {
|
||||
_i.Log.Error().Err(err).Str("clientId", clientId.String()).Msg("Failed to upload client logo")
|
||||
return "", err
|
||||
|
|
@ -559,11 +562,17 @@ func (_i *clientsService) UploadLogo(authToken string, c *fiber.Ctx) (string, er
|
|||
_i.Log.Info().
|
||||
Str("Upload imagePath", imagePath).Msg("Client upload logo files")
|
||||
|
||||
logoUrl := fmt.Sprintf("%s/%s/%s", _i.Cfg.App.Domain, "clients/logo", newFilename)
|
||||
|
||||
// Update client with new logo image path
|
||||
updateReq := request.ClientsUpdateRequest{
|
||||
LogoImagePath: &imagePath,
|
||||
LogoUrl: &logoUrl,
|
||||
}
|
||||
|
||||
_i.Log.Info().
|
||||
Str("Upload Update Request", imagePath).Interface("updateReq ", updateReq).Msg("Client upload logo files")
|
||||
|
||||
err = _i.Repo.Update(clientId, updateReq.ToEntity())
|
||||
if err != nil {
|
||||
_i.Log.Error().Err(err).Str("clientId", clientId.String()).Str("imagePath", imagePath).Msg("Failed to update client with logo path")
|
||||
|
|
|
|||
Loading…
Reference in New Issue