Skip to content

Commit

Permalink
refactor(exif): Renaming exif to metadata and adding tag value
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Dec 30, 2022
1 parent 436eb05 commit b881866
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 221 deletions.
5 changes: 2 additions & 3 deletions pkg/crud/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

absto "github.com/ViBiOh/absto/pkg/model"
"github.com/ViBiOh/fibr/pkg/exclusive"
"github.com/ViBiOh/fibr/pkg/exif"
"github.com/ViBiOh/fibr/pkg/provider"
"github.com/ViBiOh/fibr/pkg/search"
"github.com/ViBiOh/fibr/pkg/thumbnail"
Expand All @@ -35,7 +34,7 @@ type App struct {
storageApp absto.Storage
shareApp provider.ShareManager
webhookApp provider.WebhookManager
exifApp provider.ExifManager
exifApp provider.MetadataManager
searchApp search.App
pushEvent provider.EventProducer
exclusiveApp exclusive.App
Expand Down Expand Up @@ -64,7 +63,7 @@ func Flags(fs *flag.FlagSet, prefix string) Config {
}
}

func New(config Config, storageApp absto.Storage, filteredStorage absto.Storage, rendererApp renderer.App, shareApp provider.ShareManager, webhookApp provider.WebhookManager, thumbnailApp thumbnail.App, exifApp exif.App, searchApp search.App, eventProducer provider.EventProducer, exclusiveApp exclusive.App, tracer trace.Tracer) (App, error) {
func New(config Config, storageApp absto.Storage, filteredStorage absto.Storage, rendererApp renderer.App, shareApp provider.ShareManager, webhookApp provider.WebhookManager, thumbnailApp thumbnail.App, exifApp provider.MetadataManager, searchApp search.App, eventProducer provider.EventProducer, exclusiveApp exclusive.App, tracer trace.Tracer) (App, error) {
app := App{
sanitizeOnStart: *config.sanitizeOnStart,

Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (a App) serveGeoJSON(w http.ResponseWriter, r *http.Request, request provid
return
}

exifs, err := a.exifApp.ListExifFor(ctx, items...)
exifs, err := a.exifApp.GetAllMetadataFor(ctx, items...)
if err != nil {
a.error(w, r, request, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/crud/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func BenchmarkServeGeoJSON(b *testing.B) {
ctrl := gomock.NewController(b)
defer ctrl.Finish()

mockExif := mocks.NewExifManager(ctrl)
mockExif := mocks.NewMetadataManager(ctrl)

mockExif.EXPECT().ListExifFor(gomock.Any(), gomock.Any()).Return(map[string]provider.Metadata{
mockExif.EXPECT().GetAllMetadataFor(gomock.Any(), gomock.Any()).Return(map[string]provider.Metadata{
"9012": {
Exif: exas.Exif{
Geocode: exas.Geocode{
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (a App) list(ctx context.Context, request provider.Request, message rendere
wg.Go(func() {
var err error

aggregates, err = a.exifApp.ListAggregateFor(ctx, files...)
aggregates, err = a.exifApp.GetAllAggregateFor(ctx, files...)
if err != nil {
listLogger(item.Pathname).Error("list exifs: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (a App) handlePostDescription(w http.ResponseWriter, r *http.Request, reque

description := r.FormValue("description")

if err = a.exifApp.UpdateDescription(ctx, item, description); err != nil {
if _, err = a.exifApp.Update(ctx, item, provider.ReplaceDescription(description)); err != nil {
a.error(w, r, request, err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/story.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (a App) story(r *http.Request, request provider.Request, item absto.Item, f
wg.Go(func() {
var err error

exifs, err = a.exifApp.ListExifFor(ctx, files...)
exifs, err = a.exifApp.GetAllMetadataFor(ctx, files...)
if err != nil {
logger.WithField("fn", "crud.story").WithField("item", request.Path).Error("list exifs: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/exif/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (a App) GetMetadataFor(ctx context.Context, item absto.Item) (provider.Meta
return a.exifCacheApp.Get(ctx, item)
}

func (a App) ListExifFor(ctx context.Context, items ...absto.Item) (map[string]provider.Metadata, error) {
func (a App) GetAllMetadataFor(ctx context.Context, items ...absto.Item) (map[string]provider.Metadata, error) {
ctx, end := tracer.StartSpan(ctx, a.tracer, "list_exif")
defer end()

Expand Down Expand Up @@ -65,7 +65,7 @@ func (a App) GetAggregateFor(ctx context.Context, item absto.Item) (provider.Agg
return a.aggregateCacheApp.Get(ctx, item)
}

func (a App) ListAggregateFor(ctx context.Context, items ...absto.Item) (map[string]provider.Aggregate, error) {
func (a App) GetAllAggregateFor(ctx context.Context, items ...absto.Item) (map[string]provider.Aggregate, error) {
ctx, end := tracer.StartSpan(ctx, a.tracer, "list_aggregate")
defer end()

Expand Down
2 changes: 1 addition & 1 deletion pkg/exif/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func (a App) AMQPHandler(ctx context.Context, message amqp.Delivery) error {
return nil
}

_, err := a.update(ctx, resp.Item, WithExif(resp.Exif))
_, err := a.Update(ctx, resp.Item, provider.ReplaceExif(resp.Exif))
return err
}
2 changes: 1 addition & 1 deletion pkg/exif/exif.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (a App) extractAndSaveExif(ctx context.Context, item absto.Item) (provider.
return provider.Metadata{}, fmt.Errorf("extract exif: %w", err)
}

return a.update(ctx, item, WithExif(exif))
return a.Update(ctx, item, provider.ReplaceExif(exif))
}

func (a App) extractExif(ctx context.Context, item absto.Item) (exif exas.Exif, err error) {
Expand Down
26 changes: 1 addition & 25 deletions pkg/exif/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,12 @@ import (
"fmt"

absto "github.com/ViBiOh/absto/pkg/model"
exas "github.com/ViBiOh/exas/pkg/model"
"github.com/ViBiOh/fibr/pkg/exclusive"
"github.com/ViBiOh/fibr/pkg/provider"
"github.com/ViBiOh/httputils/v4/pkg/logger"
)

type MetadataOption func(provider.Metadata) provider.Metadata

func WithExif(exif exas.Exif) MetadataOption {
return func(instance provider.Metadata) provider.Metadata {
instance.Exif = exif

return instance
}
}

func WithDescription(description string) MetadataOption {
return func(instance provider.Metadata) provider.Metadata {
instance.Description = description

return instance
}
}

func (a App) update(ctx context.Context, item absto.Item, opts ...MetadataOption) (provider.Metadata, error) {
func (a App) Update(ctx context.Context, item absto.Item, opts ...provider.MetadataAction) (provider.Metadata, error) {
var metadata provider.Metadata

return metadata, a.exclusiveApp.Execute(ctx, "fibr:mutex:"+item.ID, exclusive.Duration, func(ctx context.Context) error {
Expand All @@ -51,8 +32,3 @@ func (a App) update(ctx context.Context, item absto.Item, opts ...MetadataOption
return nil
})
}

func (a App) UpdateDescription(ctx context.Context, item absto.Item, description string) error {
_, err := a.update(ctx, item, WithDescription(description))
return err
}
143 changes: 3 additions & 140 deletions pkg/mocks/interfaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b881866

Please sign in to comment.