-
Notifications
You must be signed in to change notification settings - Fork 1
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
65990bd
commit f0d33ce
Showing
16 changed files
with
1,524 additions
and
1,229 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
501 changes: 257 additions & 244 deletions
501
micro-service/bookmark-service/grpc/content/content.pb.go
Large diffs are not rendered by default.
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
501 changes: 257 additions & 244 deletions
501
micro-service/content-service/grpc/content/content.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
micro-service/content-service/internal/adapter/persistence_adapter/feed.go
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,69 @@ | ||
package persistenceadapter | ||
|
||
import ( | ||
"context" | ||
|
||
cpb "github.com/YukiOnishi1129/techpicks/micro-service/content-service/grpc/content" | ||
"github.com/YukiOnishi1129/techpicks/micro-service/content-service/internal/domain/entity" | ||
"github.com/YukiOnishi1129/techpicks/micro-service/content-service/internal/domain/repository" | ||
"github.com/volatiletech/sqlboiler/v4/queries/qm" | ||
) | ||
|
||
type FeedPersistenceAdapter interface { | ||
GetFeeds(ctx context.Context, req *cpb.GetFeedsRequest, limit int) (entity.FeedSlice, error) | ||
} | ||
|
||
type feedPersistenceAdapter struct { | ||
feedRepository repository.FeedRepository | ||
} | ||
|
||
func NewFeedPersistenceAdapter(feedRepository repository.FeedRepository) FeedPersistenceAdapter { | ||
return &feedPersistenceAdapter{ | ||
feedRepository: feedRepository, | ||
} | ||
} | ||
|
||
func (fpa *feedPersistenceAdapter) GetFeeds(ctx context.Context, req *cpb.GetFeedsRequest, limit int) (entity.FeedSlice, error) { | ||
q := []qm.QueryMod{ | ||
// qm.InnerJoin("platforms ON feeds.platform_id = platforms.id"), | ||
// qm.InnerJoin("categories ON feeds.category_id = categories.id"), | ||
qm.Where("feeds.deleted_at IS NULL"), | ||
qm.Load(qm.Rels(entity.FeedRels.Platform)), | ||
qm.Load(qm.Rels(entity.FeedRels.Category)), | ||
qm.OrderBy("feeds.created_at ASC"), | ||
qm.Limit(limit), | ||
} | ||
|
||
if req.GetCursor() != "" { | ||
q = append(q, qm.Where("feeds.created_at < (SELECT created_at FROM feeds WHERE id = ?)", req.GetCursor())) | ||
} | ||
|
||
if req.GetPlatformSiteType().GetValue() != 0 { | ||
switch { | ||
case req.GetPlatformSiteType().GetValue() == 1: | ||
q = append(q, qm.Where("platforms.site_type = ?", 1)) | ||
case req.GetPlatformSiteType().GetValue() == 2: | ||
q = append(q, qm.Where("platforms.site_type = ?", 2)) | ||
case req.GetPlatformSiteType().GetValue() == 3: | ||
q = append(q, qm.Where("platforms.site_type = ?", 3)) | ||
} | ||
} | ||
|
||
if req.GetPlatformId().GetValue() != "" { | ||
q = append(q, qm.Where("platforms.id = ?", req.GetPlatformId().GetValue())) | ||
} | ||
|
||
if req.GetKeyword().GetValue() != "" { | ||
q = append(q, qm.Expr( | ||
qm.And("name LIKE ?", "%"+req.GetKeyword().GetValue()+"%"), | ||
qm.Or("description LIKE ?", "%"+req.GetKeyword().GetValue()+"%"), | ||
)) | ||
} | ||
|
||
feeds, err := fpa.feedRepository.GetFeeds(ctx, q) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return feeds, 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
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
12 changes: 12 additions & 0 deletions
12
micro-service/content-service/internal/domain/repository/feed.go
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,12 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/YukiOnishi1129/techpicks/micro-service/content-service/internal/domain/entity" | ||
"github.com/volatiletech/sqlboiler/v4/queries/qm" | ||
) | ||
|
||
type FeedRepository interface { | ||
GetFeeds(ctx context.Context, q []qm.QueryMod) (entity.FeedSlice, error) | ||
} |
33 changes: 33 additions & 0 deletions
33
micro-service/content-service/internal/infrastructure/persistence/feed.go
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,33 @@ | ||
package persistence | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/YukiOnishi1129/techpicks/micro-service/content-service/internal/domain/entity" | ||
"github.com/YukiOnishi1129/techpicks/micro-service/content-service/internal/domain/repository" | ||
"github.com/volatiletech/sqlboiler/v4/queries/qm" | ||
) | ||
|
||
type feedPersistence struct { | ||
db *sql.DB | ||
} | ||
|
||
func NewFeedPersistence(db *sql.DB) repository.FeedRepository { | ||
return &feedPersistence{ | ||
db: db, | ||
} | ||
} | ||
|
||
func (fp *feedPersistence) GetFeeds(ctx context.Context, q []qm.QueryMod) (entity.FeedSlice, error) { | ||
// boil.DebugMode = true | ||
feeds, err := entity.Feeds(q...).All(ctx, fp.db) | ||
if err != nil { | ||
if err == sql.ErrNoRows { | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
// boil.DebugMode = false | ||
return feeds, 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
Oops, something went wrong.