Skip to content

Commit

Permalink
adapted to fileformat
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvodi committed Sep 3, 2024
1 parent 378ec65 commit f0d1817
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 96 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dmarkham/enumer v1.5.10 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
Expand Down Expand Up @@ -65,6 +66,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pascaldekloe/name v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
Expand All @@ -80,6 +82,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
github.com/dmarkham/enumer v1.5.10 h1:ygL0L6quiTiH1jpp68DyvsWaea6MaZLZrTTkIS++R0M=
github.com/dmarkham/enumer v1.5.10/go.mod h1:e4VILe2b1nYK3JKJpRmNdl5xbDQvELc6tQ8b+GsGk6E=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down Expand Up @@ -177,6 +179,8 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/pascaldekloe/name v1.0.0 h1:n7LKFgHixETzxpRv2R77YgPUFo85QHGZKrdaYm7eY5U=
github.com/pascaldekloe/name v1.0.0/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
Expand Down Expand Up @@ -256,6 +260,8 @@ golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbR
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
6 changes: 3 additions & 3 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/file_type"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/fileformat"

Check failure on line 8 in internal/api/handler.go

View workflow job for this annotation

GitHub Actions / runner-job

no required module provides package github.com/tomvodi/limepipes-plugin-api/plugin/v1/fileformat; to add it:
"github.com/tomvodi/limepipes/internal/apigen/apimodel"
"github.com/tomvodi/limepipes/internal/common"
"github.com/tomvodi/limepipes/internal/interfaces"
Expand Down Expand Up @@ -96,7 +96,7 @@ func (a *Handler) ImportFile(c *gin.Context) {

func (a *Handler) createImportFileInfo(
iFile *multipart.FileHeader,
fType file_type.Type,
fFormat fileformat.Format,
) (*common.ImportFileInfo, error) {
fileReader, err := iFile.Open()
if err != nil {
Expand All @@ -109,7 +109,7 @@ func (a *Handler) createImportFileInfo(
return nil, fmt.Errorf("failed reading file %s: %s", iFile.Filename, err.Error())
}

fInfo, err := common.NewImportFileInfo(iFile.Filename, fType, fileData)
fInfo, err := common.NewImportFileInfo(iFile.Filename, fFormat, fileData)
if err != nil {
return nil, fmt.Errorf("failed creating import file info for file %s: %s", iFile.Filename, err.Error())
}
Expand Down
12 changes: 6 additions & 6 deletions internal/api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/mock"
"github.com/tomvodi/limepipes-plugin-api/musicmodel/v1/tune"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/file_type"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/fileformat"
pmocks "github.com/tomvodi/limepipes-plugin-api/plugin/v1/interfaces/mocks"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/messages"
"github.com/tomvodi/limepipes/internal/apigen/apimodel"
Expand Down Expand Up @@ -205,7 +205,7 @@ var _ = Describe("Api Handler", func() {
HTTPMethod: http.MethodPost,
})
pluginLoader.EXPECT().FileTypeForFileExtension(".abc").
Return(file_type.Type_Unknown, fmt.Errorf("file extension .abc is not supported"))
Return(fileformat.Format_Unknown, fmt.Errorf("file extension .abc is not supported"))
})

It("should return BadRequest", func() {
Expand All @@ -224,7 +224,7 @@ var _ = Describe("Api Handler", func() {
HTTPMethod: http.MethodPost,
})
pluginLoader.EXPECT().FileTypeForFileExtension(".bww").
Return(file_type.Type_BWW, nil)
Return(fileformat.Format_BWW, nil)
dataService.EXPECT().GetImportFileByHash("60f5237ed4049f0382661ef009d2bc42e48c3ceb3edb6600f7024e7ab3b838f3").
Return(nil, nil)
})
Expand All @@ -245,7 +245,7 @@ var _ = Describe("Api Handler", func() {
HTTPMethod: http.MethodPost,
})
pluginLoader.EXPECT().FileTypeForFileExtension(".bww").
Return(file_type.Type_BWW, nil)
Return(fileformat.Format_BWW, nil)
dataService.EXPECT().GetImportFileByHash("60f5237ed4049f0382661ef009d2bc42e48c3ceb3edb6600f7024e7ab3b838f3").
Return(nil, common.ErrNotFound)
pluginLoader.EXPECT().PluginForFileExtension(".bww").
Expand All @@ -268,7 +268,7 @@ var _ = Describe("Api Handler", func() {
HTTPMethod: http.MethodPost,
})
pluginLoader.EXPECT().FileTypeForFileExtension(".bww").
Return(file_type.Type_BWW, nil)
Return(fileformat.Format_BWW, nil)
dataService.EXPECT().GetImportFileByHash("60f5237ed4049f0382661ef009d2bc42e48c3ceb3edb6600f7024e7ab3b838f3").
Return(nil, common.ErrNotFound)
pluginLoader.EXPECT().PluginForFileExtension(".bww").
Expand All @@ -293,7 +293,7 @@ var _ = Describe("Api Handler", func() {
HTTPMethod: http.MethodPost,
})
pluginLoader.EXPECT().FileTypeForFileExtension(".bww").
Return(file_type.Type_BWW, nil)
Return(fileformat.Format_BWW, nil)
dataService.EXPECT().GetImportFileByHash("60f5237ed4049f0382661ef009d2bc42e48c3ceb3edb6600f7024e7ab3b838f3").
Return(nil, common.ErrNotFound)
pluginLoader.EXPECT().PluginForFileExtension(".bww").
Expand Down
16 changes: 10 additions & 6 deletions internal/common/import_file_info.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package common

import (
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/file_type"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/fileformat"
"os"
)

type ImportFileInfo struct {
OriginalPath string
FileType file_type.Type
FileFormat fileformat.Format
Name string
Hash string
Data []byte
}

func NewImportFileInfoFromLocalFile(
originalPath string,
fType file_type.Type,
fFormat fileformat.Format,
) (*ImportFileInfo, error) {
fHash, err := HashFromFile(originalPath)
if err != nil {
Expand All @@ -30,15 +30,19 @@ func NewImportFileInfoFromLocalFile(
fInfo := &ImportFileInfo{
OriginalPath: originalPath,
Name: FilenameFromPath(originalPath),
FileType: fType,
FileFormat: fFormat,
Hash: fHash,
Data: fileData,
}

return fInfo, nil
}

func NewImportFileInfo(fileName string, fType file_type.Type, fileData []byte) (*ImportFileInfo, error) {
func NewImportFileInfo(
fileName string,
fFormat fileformat.Format,
fileData []byte,
) (*ImportFileInfo, error) {
fHash, err := HashFromData(fileData)
if err != nil {
return nil, err
Expand All @@ -47,7 +51,7 @@ func NewImportFileInfo(fileName string, fType file_type.Type, fileData []byte) (
fInfo := &ImportFileInfo{
OriginalPath: fileName,
Name: FilenameFromPath(fileName),
FileType: fType,
FileFormat: fFormat,
Hash: fHash,
Data: fileData,
}
Expand Down
10 changes: 5 additions & 5 deletions internal/common/import_file_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package common

import (
. "github.com/onsi/gomega"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/file_type"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/fileformat"
"github.com/tomvodi/limepipes/internal/utils"
"testing"
)
Expand All @@ -28,7 +28,7 @@ func Test_NewImportFileInfoFromLocalFile(t *testing.T) {
Name: "test",
Hash: "534b1d50f10ee4ea30604ce01660e2429682fe6e53a4ef6a9d01c835ef73b866",
Data: []byte(`Bagpipe Reader:1.0`),
FileType: file_type.Type_BWW,
FileFormat: fileformat.Format_BWW,
}
f.wantErr = false
},
Expand All @@ -43,7 +43,7 @@ func Test_NewImportFileInfoFromLocalFile(t *testing.T) {
tt.prepare(f)
}

fileInfo, err := NewImportFileInfoFromLocalFile(f.originalPath, file_type.Type_BWW)
fileInfo, err := NewImportFileInfoFromLocalFile(f.originalPath, fileformat.Format_BWW)
if f.wantErr {
g.Expect(err).Should(HaveOccurred())
} else {
Expand Down Expand Up @@ -77,7 +77,7 @@ func Test_NewImportFileInfo(t *testing.T) {
Name: "test",
Hash: "534b1d50f10ee4ea30604ce01660e2429682fe6e53a4ef6a9d01c835ef73b866",
Data: f.fileData,
FileType: file_type.Type_BWW,
FileFormat: fileformat.Format_BWW,
}
f.wantErr = false
},
Expand All @@ -92,7 +92,7 @@ func Test_NewImportFileInfo(t *testing.T) {
tt.prepare(f)
}

fileInfo, err := NewImportFileInfo(f.fileName, file_type.Type_BWW, f.fileData)
fileInfo, err := NewImportFileInfo(f.fileName, fileformat.Format_BWW, f.fileData)
if f.wantErr {
g.Expect(err).Should(HaveOccurred())
} else {
Expand Down
26 changes: 13 additions & 13 deletions internal/database/db_data_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/tomvodi/limepipes-plugin-api/musicmodel/v1/measure"
"github.com/tomvodi/limepipes-plugin-api/musicmodel/v1/tune"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/file_type"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/fileformat"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/messages"
"github.com/tomvodi/limepipes/internal/apigen/apimodel"
"github.com/tomvodi/limepipes/internal/common"
Expand Down Expand Up @@ -693,7 +693,7 @@ func (d *Service) importTunesToDatabase(
return err
}

apiTunes, err = d.importTunes(tunes, importFile, fInfo.FileType)
apiTunes, err = d.importTunes(tunes, importFile, fInfo.FileFormat)
if err != nil {
return err
}
Expand All @@ -717,11 +717,11 @@ func (d *Service) importTunesToDatabase(
func (d *Service) importTunes(
tunes []*messages.ImportedTune,
importFile *model.ImportFile,
fType file_type.Type,
fFormat fileformat.Format,
) ([]*apimodel.ImportTune, error) {
var apiTunes []*apimodel.ImportTune
for _, impTune := range tunes {
importTune, err := d.importTune(impTune, importFile, fType)
importTune, err := d.importTune(impTune, importFile, fFormat)
if err != nil {
return nil, err
}
Expand All @@ -736,7 +736,7 @@ func (d *Service) importTunes(
func (d *Service) importTune(
impTune *messages.ImportedTune,
importFile *model.ImportFile,
fType file_type.Type,
fFormat fileformat.Format,
) (*apimodel.ImportTune, error) {
existingTune, err := d.getImportTuneBySingleFileData(
impTune.TuneFileData,
Expand All @@ -748,7 +748,7 @@ func (d *Service) importTune(
return existingTune, nil
}

apiTune, err := d.createTuneWithFiles(impTune, importFile, fType)
apiTune, err := d.createTuneWithFiles(impTune, importFile, fFormat)
if err != nil {
return nil, err
}
Expand All @@ -766,7 +766,7 @@ func (d *Service) importTune(
func (d *Service) createTuneWithFiles(
impTune *messages.ImportedTune,
importFile *model.ImportFile,
fType file_type.Type,
fFormat fileformat.Format,
) (*apimodel.Tune, error) {
t := impTune.Tune
createTune := apimodel.CreateTune{}
Expand All @@ -791,7 +791,7 @@ func (d *Service) createTuneWithFiles(

if impTune.TuneFileData != nil {
muMoTuneFile = &model.TuneFile{
Type: fType,
Format: fFormat,
Data: impTune.TuneFileData,
SingleTuneData: true,
}
Expand Down Expand Up @@ -911,7 +911,7 @@ func musicSetTitleFromTunes(tunes []*apimodel.ImportTune) string {
var tuneTypes []string
for _, t := range tunes {
if strings.TrimSpace(t.Type) == "" {
tuneTypes = append(tuneTypes, "Unknown Type")
tuneTypes = append(tuneTypes, "Unknown Format")
} else {
tuneTypes = append(tuneTypes, t.Type)
}
Expand Down Expand Up @@ -1035,10 +1035,10 @@ func setMessagesToAPITune(apiTune *apimodel.ImportTune, modelTune *tune.Tune) {
}
}

func (d *Service) GetTuneFile(tuneID uuid.UUID, fType file_type.Type) (*model.TuneFile, error) {
func (d *Service) GetTuneFile(tuneID uuid.UUID, fFormat fileformat.Format) (*model.TuneFile, error) {
tuneFile := &model.TuneFile{
TuneID: tuneID,
Type: fType,
Format: fFormat,
}

if err := d.db.First(tuneFile).Error; err != nil {
Expand Down Expand Up @@ -1077,10 +1077,10 @@ func (d *Service) AddFileToTune(tuneID uuid.UUID, tFile *model.TuneFile) error {
return nil
}

func (d *Service) DeleteFileFromTune(tuneID uuid.UUID, fType file_type.Type) error {
func (d *Service) DeleteFileFromTune(tuneID uuid.UUID, fFormat fileformat.Format) error {
tuneFile := &model.TuneFile{
TuneID: tuneID,
Type: fType,
Format: fFormat,
}
if err := d.db.Delete(tuneFile).Error; err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions internal/database/db_data_service_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/tomvodi/limepipes-plugin-api/musicmodel/v1/helper"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/file_type"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/fileformat"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/messages"
"github.com/tomvodi/limepipes/internal/apigen/apimodel"
"github.com/tomvodi/limepipes/internal/common"
Expand Down Expand Up @@ -246,7 +246,7 @@ var _ = Describe("DbDataService CRUD", func() {

When("retrieving that tune file again", func() {
BeforeEach(func() {
returnTuneFile, err = service.GetTuneFile(tune.Id, file_type.Type_MUSIC_MODEL)
returnTuneFile, err = service.GetTuneFile(tune.Id, fileformat.Format_MUSIC_MODEL)
})

It("should contain that same music model tune", func() {
Expand All @@ -258,7 +258,7 @@ var _ = Describe("DbDataService CRUD", func() {

When("deleting that file", func() {
BeforeEach(func() {
err = service.DeleteFileFromTune(tune.Id, file_type.Type_MUSIC_MODEL)
err = service.DeleteFileFromTune(tune.Id, fileformat.Format_MUSIC_MODEL)
})

It("should succeed", func() {
Expand Down
Loading

0 comments on commit f0d1817

Please sign in to comment.