-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
1f50f52
commit aba1cfb
Showing
55 changed files
with
1,545 additions
and
735 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package asset | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Southclaws/fault" | ||
"github.com/Southclaws/fault/fctx" | ||
"github.com/Southclaws/fault/ftag" | ||
"github.com/rs/xid" | ||
|
||
"github.com/Southclaws/storyden/app/resources/account" | ||
"github.com/Southclaws/storyden/internal/ent" | ||
) | ||
|
||
type database struct { | ||
db *ent.Client | ||
} | ||
|
||
func New(db *ent.Client) Repository { | ||
return &database{db} | ||
} | ||
|
||
func (d *database) Add(ctx context.Context, | ||
accountID account.AccountID, | ||
id, url, mt string, | ||
width, height int, | ||
) (*Asset, error) { | ||
asset, err := d.db.Asset.Get(ctx, id) | ||
if err != nil && !ent.IsNotFound(err) { | ||
return nil, fault.Wrap(err, fctx.With(ctx)) | ||
} | ||
|
||
if asset == nil { | ||
asset, err = d.db.Asset. | ||
Create(). | ||
SetID(id). | ||
SetURL(url). | ||
SetWidth(width). | ||
SetHeight(height). | ||
SetMimetype(mt). | ||
SetAccountID(xid.ID(accountID)). | ||
Save(ctx) | ||
if err != nil { | ||
return nil, fault.Wrap(err, fctx.With(ctx), ftag.With(ftag.Internal)) | ||
} | ||
} | ||
|
||
return FromModel(asset), nil | ||
} | ||
|
||
func (d *database) Remove(ctx context.Context, accountID account.AccountID, id AssetID) error { | ||
q := d.db.Asset. | ||
DeleteOneID(string(id)) | ||
|
||
if err := q.Exec(ctx); err != nil { | ||
return fault.Wrap(err, fctx.With(ctx), ftag.With(ftag.Internal)) | ||
} | ||
|
||
return 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
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,17 @@ | ||
package asset | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Southclaws/storyden/app/resources/account" | ||
) | ||
|
||
type Repository interface { | ||
Add(ctx context.Context, | ||
owner account.AccountID, | ||
id, url, mt string, | ||
width, height int, | ||
) (*Asset, error) | ||
|
||
Remove(ctx context.Context, owner account.AccountID, id AssetID) error | ||
} |
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
Oops, something went wrong.