diff --git a/pkg/app/app.go b/pkg/app/app.go index 984b8c9..5a47239 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -85,10 +85,11 @@ func (a *App) runWithContext(ctx context.Context) (err error) { // usecase database := &repository.Database{ - Episode: database.NewEpisode(mysql), - Series: database.NewSeries(mysql), - Season: database.NewSeason(mysql), - Genre: database.NewGenre(mysql), + Episode: database.NewEpisode(mysql), + Series: database.NewSeries(mysql), + Season: database.NewSeason(mysql), + Genre: database.NewGenre(mysql), + ViewingHistory: database.NewViewingHistory(mysql), } uc := usecase.NewUsecase(database, redis) diff --git a/pkg/repository/database/viewing_history.go b/pkg/repository/database/viewing_history.go index 14fa10f..c410f74 100644 --- a/pkg/repository/database/viewing_history.go +++ b/pkg/repository/database/viewing_history.go @@ -3,6 +3,7 @@ package database import ( "context" "database/sql" + "errors" "github.com/CyberAgentHack/server-performance-tuning-2023/pkg/entity" "github.com/CyberAgentHack/server-performance-tuning-2023/pkg/errcode" @@ -38,7 +39,8 @@ func (e *ViewingHistory) Get(ctx context.Context, id string, userID string) (*en &viewingHistory.Duration, &viewingHistory.LastViewingAt, ) - if err != nil { + + if err != nil && !errors.Is(err, sql.ErrNoRows) { return nil, errcode.New(err) } diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index 9f8518c..095db9c 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -54,7 +54,6 @@ type ListSeasonsParams struct { } type ViewingHistory interface { - Create(ctx context.Context, viewingHistory *entity.ViewingHistory) (*entity.ViewingHistory, error) Get(ctx context.Context, id string, userID string) (*entity.ViewingHistory, error) BatchGet(ctx context.Context, ids []string, userID string) (entity.ViewingHistories, error) }