-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(star): rename starring to star
- Loading branch information
Showing
16 changed files
with
475 additions
and
468 deletions.
There are no files selected for viewing
32 changes: 16 additions & 16 deletions
32
lib/mock/starring_repository.go → lib/mock/star_repository.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,34 @@ | ||
package star | ||
|
||
//go:generate mockery --name Repository --outpkg mock --output ../lib/mock/ --structname StarRepository --filename star_repository.go | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type Star struct { | ||
ID string | ||
AssetURN string | ||
AssetType string | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
} | ||
|
||
func (s *Star) Validate() error { | ||
if s == nil { | ||
return ErrNoStarInformation | ||
} | ||
|
||
if s.AssetURN == "" || s.AssetType == "" { | ||
return InvalidError{AssetURN: s.AssetURN, AssetType: s.AssetType} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type Repository interface { | ||
Create(ctx context.Context, star *Star) (string, error) | ||
GetUserIDs(ctx context.Context, assetURN, assetType string) ([]string, error) | ||
GetByUserID(ctx context.Context, userID string) ([]Star, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package star | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
func TestValidate(t *testing.T) { | ||
type testCase struct { | ||
Title string | ||
Star *Star | ||
ExpectError error | ||
} | ||
|
||
var testCases = []testCase{ | ||
{ | ||
Title: "should return error no star information if user is nil", | ||
Star: nil, | ||
ExpectError: ErrNoStarInformation, | ||
}, | ||
{ | ||
Title: "should return error invalid if assert urn is empty", | ||
Star: &Star{AssetType: "asset-type"}, | ||
ExpectError: InvalidError{AssetType: "asset-type"}, | ||
}, | ||
{ | ||
Title: "should return error invalid if assert type is empty", | ||
Star: &Star{AssetURN: "asset-urn"}, | ||
ExpectError: InvalidError{AssetURN: "asset-urn"}, | ||
}, | ||
{ | ||
Title: "should return nil if star is valid", | ||
Star: &Star{AssetURN: "asset-urn", AssetType: "asset-type"}, | ||
ExpectError: nil, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.Title, func(t *testing.T) { | ||
|
||
err := testCase.Star.Validate() | ||
assert.Equal(t, testCase.ExpectError, err) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
store/postgres/migrations/000003_create_starrings_table.down.sql
This file was deleted.
Oops, something went wrong.
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 @@ | ||
DROP TABLE IF EXISTS stars; |
6 changes: 3 additions & 3 deletions
6
...ions/000003_create_starrings_table.up.sql → ...grations/000003_create_stars_table.up.sql
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
CREATE TABLE starrings ( | ||
CREATE TABLE stars ( | ||
id uuid DEFAULT gen_random_uuid() PRIMARY KEY, | ||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
asset_urn text NOT NULL, | ||
asset_type text NOT NULL, | ||
asset_urn text NOT NULL, | ||
created_at timestamp DEFAULT NOW(), | ||
updated_at timestamp DEFAULT NOW() | ||
); | ||
|
||
CREATE UNIQUE INDEX starrings_idx_user_id_asset_type_asset_urn ON starrings(user_id,asset_type,asset_urn); | ||
CREATE UNIQUE INDEX stars_idx_user_id_asset_type_asset_urn ON stars(user_id,asset_type,asset_urn); |
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,28 @@ | ||
package postgres | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStarModel(t *testing.T) { | ||
t.Run("successfully build build star from star model", func(t *testing.T) { | ||
sm := &StarModel{ | ||
ID: "id", | ||
AssetURN: "asseturn", | ||
AssetType: "asserttype", | ||
CreatedAt: time.Now(), | ||
UpdatedAt: time.Now(), | ||
} | ||
|
||
s := sm.toStar() | ||
|
||
assert.Equal(t, s.ID, sm.ID) | ||
assert.Equal(t, s.AssetType, sm.AssetType) | ||
assert.Equal(t, s.AssetURN, sm.AssetURN) | ||
assert.True(t, s.CreatedAt.Equal(sm.CreatedAt)) | ||
assert.True(t, s.UpdatedAt.Equal(sm.UpdatedAt)) | ||
}) | ||
} |
Oops, something went wrong.