Skip to content

Commit

Permalink
fix : duplicat storage init
Browse files Browse the repository at this point in the history
remove duplicate file storage
  • Loading branch information
teranixbq authored Jul 13, 2024
2 parents a5cb65f + 283cc8c commit 9dde6b1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 85 deletions.
4 changes: 2 additions & 2 deletions features/admin/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (ar *AdminRepository) Create(image *multipart.FileHeader, data entity.Admin
dataAdmins := entity.AdminCoreToAdminModel(data)

if image != nil {
imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return entity.AdminCore{}, errUpload
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (ar *AdminRepository) Update(image *multipart.FileHeader, adminId string, d
}

if image != nil {
imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return errUpload
}
Expand Down
5 changes: 2 additions & 3 deletions features/article/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (article *articleRepository) UpdateArticle(idArticle string, articleInput e
}

if image != nil {
imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return entity.ArticleCore{}, errUpload
}
Expand All @@ -81,7 +81,6 @@ func (article *articleRepository) UpdateArticle(idArticle string, articleInput e
} else {
input.Image = articleData.Image
}

articleData.Title = articleInput.Title
articleData.Content = articleInput.Content

Expand Down Expand Up @@ -158,7 +157,7 @@ func (article *articleRepository) GetAllArticle(page, limit int, search, filter
func (article *articleRepository) CreateArticle(articleInput entity.ArticleCore, image *multipart.FileHeader) (entity.ArticleCore, error) {
articleData := entity.ArticleCoreToArticleModel(articleInput)

imageURL, uploadErr := storage.UploadThumbnail(image)
imageURL, uploadErr := storage.Upload(image)
if uploadErr != nil {
return entity.ArticleCore{}, uploadErr
}
Expand Down
8 changes: 4 additions & 4 deletions features/community/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewCommunityRepository(db *gorm.DB) entity.CommunityRepositoryInterface {
func (cr *communityRepository) CreateCommunity(image *multipart.FileHeader, data entity.CommunityCore) error {
request := entity.CoreCommunityToModelCommunity(data)

imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return errUpload
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (cr *communityRepository) UpdateCommunityById(id string, image *multipart.F
}

if image != nil {
imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return errUpload
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (cr *communityRepository) GetByName(name string) (entity.CommunityCore, err
func (communityRepo *communityRepository) CreateEvent(communityId string, eventInput entity.CommunityEventCore, image *multipart.FileHeader) error {
eventData := entity.EventCoreToEventModel(eventInput)

imageURL, uploadErr := storage.UploadThumbnail(image)
imageURL, uploadErr := storage.Upload(image)
if uploadErr != nil {
return uploadErr
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func (communityRepo *communityRepository) UpdateEvent(communityId string, eventI
}

if image != nil {
imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return errUpload
}
Expand Down
4 changes: 2 additions & 2 deletions features/mission/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (mr *MissionRepository) CreateUploadMissionTask(userID string, data entity.
}

for _, image := range images {
imageURL, uploadErr := storage.UploadProof(image)
imageURL, uploadErr := storage.Upload(image)
if uploadErr != nil {
return entity.UploadMissionTaskCore{}, uploadErr
}
Expand Down Expand Up @@ -532,7 +532,7 @@ func (mr *MissionRepository) UpdateUploadMissionTask(id string, images []*multip

for _, image := range images {
Imagedata := entity.ImageUploadMissionCore{}
imageURL, uploadErr := storage.UploadProof(image)
imageURL, uploadErr := storage.Upload(image)
if uploadErr != nil {
return uploadErr
}
Expand Down
4 changes: 2 additions & 2 deletions features/mission/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (ms *missionService) CreateMission(image *multipart.FileHeader, data entity
return err
}

imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return err
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (ms *missionService) UpdateMission(image *multipart.FileHeader, missionID s
}

if image != nil {
newImageURL, errUpload := storage.UploadThumbnail(image)
newImageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion features/report/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (report *reportRepository) Insert(reportInput entity.ReportCore, images []*
}

for _, image := range images {
imageURL, uploadErr := storage.UploadProof(image)
imageURL, uploadErr := storage.Upload(image)
if uploadErr != nil {
return entity.ReportCore{}, uploadErr
}
Expand Down
5 changes: 2 additions & 3 deletions features/voucher/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"recything/utils/constanta"
"recything/utils/helper"

//"recything/utils/helper"
"recything/utils/pagination"
"recything/utils/storage"

Expand All @@ -29,7 +28,7 @@ func NewVoucherRepository(db *gorm.DB) entity.VoucherRepositoryInterface {
func (vr *voucherRepository) Create(image *multipart.FileHeader, data entity.VoucherCore) error {
input := entity.CoreVoucherToModelVoucher(data)

imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return errUpload
}
Expand Down Expand Up @@ -131,7 +130,7 @@ func (vr *voucherRepository) Update(idVoucher string, image *multipart.FileHeade
}

if image != nil {
imageURL, errUpload := storage.UploadThumbnail(image)
imageURL, errUpload := storage.Upload(image)
if errUpload != nil {
return errUpload
}
Expand Down
65 changes: 0 additions & 65 deletions utils/storage/article_thumbnail.go

This file was deleted.

6 changes: 3 additions & 3 deletions utils/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"google.golang.org/api/option"
)

func UploadProof(image *multipart.FileHeader) (string, error) {
func Upload(image *multipart.FileHeader) (string, error) {
ctx := context.Background()

// Decode Google Cloud credentials from Base64
Expand All @@ -34,15 +34,15 @@ func UploadProof(image *multipart.FileHeader) (string, error) {
}
defer client.Close()

bucketName := "report_proof"
bucketName := "recything-bucket"
extension := filepath.Ext(image.Filename)
allowedExtensions := map[string]bool{".jpg": true, ".png": true, ".mp4": true}

if !allowedExtensions[strings.ToLower(extension)] {
return "", errors.New("error : format file tidak diizinkan")
}

imagePath := "proof-file/" + uuid.New().String() + extension
imagePath := "recything-bucket/" + uuid.New().String() + extension

wc := client.Bucket(bucketName).Object(imagePath).NewWriter(ctx)
defer wc.Close()
Expand Down

0 comments on commit 9dde6b1

Please sign in to comment.