-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Miguel Ramos
authored and
Miguel Ramos
committed
Feb 12, 2021
1 parent
c380705
commit f62d746
Showing
13 changed files
with
214 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package models | ||
|
||
import ( | ||
"github.com/gobuffalo/uuid" | ||
"github.com/pkg/errors" | ||
"github.com/websublime/barrel/storage/namespace" | ||
) | ||
|
||
type BucketMedia struct { | ||
ID uuid.UUID `json:"id" db:"id" primary_id:"id"` | ||
BucketID uuid.UUID `json:"bucketId" db:"bucket_id"` | ||
MediaID uuid.UUID `json:"mediaId" db:"media_id"` | ||
} | ||
|
||
func (BucketMedia) TableName() string { | ||
tableName := "bucket_media" | ||
|
||
if namespace.GetNamespace() != "" { | ||
return namespace.GetNamespace() + "." + tableName | ||
} | ||
|
||
return tableName | ||
} | ||
|
||
func NewBucketMedia(bucket uuid.UUID, media uuid.UUID) (*BucketMedia, error) { | ||
uid, err := uuid.NewV4() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Error generating unique id") | ||
} | ||
|
||
bucketMedia := &BucketMedia{ | ||
ID: uid, | ||
BucketID: bucket, | ||
MediaID: media, | ||
} | ||
|
||
return bucketMedia, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package models | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gobuffalo/pop/nulls" | ||
"github.com/gobuffalo/uuid" | ||
"github.com/gobuffalo/validate/v3" | ||
"github.com/gobuffalo/validate/v3/validators" | ||
"github.com/pkg/errors" | ||
"github.com/websublime/barrel/storage/namespace" | ||
) | ||
|
||
type Media struct { | ||
ID uuid.UUID `json:"id" db:"id"` | ||
URL string `json:"url" db:"url"` | ||
Owner nulls.UUID `json:"ownerId" db:"owner"` | ||
BucketFile nulls.String `json:"bucketFile" db:"bucket_file"` | ||
Metafile nulls.String `json:"metadata" db:"meta_file"` | ||
CreatedAt time.Time `json:"createdAt" db:"created_at"` | ||
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` | ||
DeletedAt nulls.Time `json:"deletedAt" db:"deleted_at"` | ||
BucketMedia []*BucketMedia `json:"medias,omitempty" many_to_many:"bucket_media" db:"-" fk_id:"media_id" primary_id:"id"` | ||
} | ||
|
||
func (Media) TableName() string { | ||
tableName := "medias" | ||
|
||
if namespace.GetNamespace() != "" { | ||
return namespace.GetNamespace() + "." + tableName | ||
} | ||
|
||
return tableName | ||
} | ||
|
||
func NewMedia(url string, owner nulls.UUID, bucketFile nulls.String, metadata nulls.String) (*Media, error) { | ||
uid, err := uuid.NewV4() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Error generating unique id") | ||
} | ||
|
||
media := &Media{ | ||
ID: uid, | ||
URL: url, | ||
Owner: owner, | ||
BucketFile: bucketFile, | ||
Metafile: metadata, | ||
} | ||
|
||
return media, nil | ||
} | ||
|
||
func (m *Media) Validate() *validate.Errors { | ||
return validate.Validate( | ||
&validators.StringIsPresent{Field: m.URL, Name: "URL", Message: "Url is missign"}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters