Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test new actions and apps #16

Merged
merged 15 commits into from
Sep 29, 2024
23 changes: 23 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version = 1

[[analyzers]]
name = "secrets"

[[analyzers]]
name = "test-coverage"

[[analyzers]]
name = "javascript"

[analyzers.meta]
plugins = ["react"]
environment = [
"nodejs",
"cypress"
]

[[analyzers]]
name = "go"

[analyzers.meta]
import_root = "github.com/Azanul/Next-Watch"
46 changes: 46 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: PR Checks

on:
pull_request:
branches: [ prod ]
types: [opened, synchronize, reopened]

jobs:
frontend-checks:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.17.x'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
# - name: Run tests
# run: npm test
- name: Build
run: npm run build

backend-checks:
runs-on: ubuntu-latest
working-directory: server
steps:
- uses: actions/checkout@v4
- name: Build and embed frontend
working-directory: .
run: make frontend
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Install dependencies
run: go mod download
- name: Run tests
run: go test ./...
- name: Run linter
uses: golangci/[email protected]
2 changes: 1 addition & 1 deletion frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function Home() {
}, []);

function handleGoogleSignIn() {
router.push(`/auth/signin/google`);
router.push("/auth/signin/google");
}

return (
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ go 1.22.7

require (
github.com/99designs/gqlgen v0.17.54
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
github.com/stretchr/testify v1.9.0
github.com/vektah/gqlparser/v2 v2.5.16
google.golang.org/api v0.198.0
)
Expand All @@ -14,13 +16,16 @@ require (
cloud.google.com/go/auth v0.9.4 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
Expand All @@ -33,6 +38,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
Expand Down
6 changes: 6 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A=
github.com/99designs/gqlgen v0.17.54 h1:AsF49k/7RJlwA00RQYsYN0T8cQuaosnV/7G1dHC3Uh8=
github.com/99designs/gqlgen v0.17.54/go.mod h1:77/+pVe6zlTsz++oUg2m8VLgzdUPHxjoAG3BxI5y8Rc=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
Expand Down Expand Up @@ -88,6 +90,7 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand All @@ -104,6 +107,8 @@ github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERA
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
Expand Down Expand Up @@ -207,6 +212,7 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Expand Down
33 changes: 33 additions & 0 deletions server/internal/repository/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package repository

import (
"context"

"github.com/Azanul/Next-Watch/internal/models"
"github.com/google/uuid"
"github.com/pgvector/pgvector-go"
)

type MovieRepositoryInterface interface {
GetMovies(ctx context.Context, searchTerm string, page, pageSize int) (*MoviePage, error)
GetByID(ctx context.Context, id uuid.UUID) (*models.Movie, error)
GetByTitle(ctx context.Context, title string) (*models.Movie, error)
GetSimilarMovies(ctx context.Context, embedding pgvector.Vector, page, pageSize int) (*MoviePage, error)
Create(ctx context.Context, movie *models.Movie) error
Update(ctx context.Context, movie *models.Movie) error
Delete(ctx context.Context, rating *models.Rating) error
}

type RatingRepositoryInterface interface {
GetByID(ctx context.Context, ratingID uuid.UUID) (*models.Rating, error)
GetByUserAndMovie(ctx context.Context, userID, movieID uuid.UUID) (*models.Rating, error)
Create(ctx context.Context, rating *models.Rating) error
Update(ctx context.Context, rating *models.Rating) error
Delete(ctx context.Context, ratingID uuid.UUID) (*models.Rating, error)
}

type UserRepositoryInterface interface {
Create(ctx context.Context, user *models.User) error
GetByEmail(ctx context.Context, email string) (*models.User, error)
Update(ctx context.Context, user *models.User) error
}
77 changes: 36 additions & 41 deletions server/internal/repository/movie_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package repository
import (
"context"
"database/sql"
"fmt"

"github.com/Azanul/Next-Watch/internal/models"
"github.com/google/uuid"
Expand All @@ -15,6 +16,9 @@ type MovieRepository struct {
db *sql.DB
}

// Checking if MovieRepository implements MovieRepositoryInterface during compile time
var _ MovieRepositoryInterface = (*MovieRepository)(nil)

func NewMovieRepository(db *sql.DB) *MovieRepository {
return &MovieRepository{db: db}
}
Expand All @@ -32,58 +36,49 @@ func (r *MovieRepository) GetMovies(ctx context.Context, searchTerm string, page
var rows *sql.Rows
var err error
var totalCount int
if searchTerm == "" {
// Query to get the movies for the current page
query := `

query := `
SELECT id, title, genre, year, wiki, plot, director, "cast"
FROM movies
ORDER BY id
LIMIT $1 OFFSET $2
FROM movies
`

rows, err = r.db.QueryContext(ctx, query, pageSize+1, offset)
if err != nil {
return nil, err
}
countQuery := `SELECT COUNT(*) FROM movies`

countQuery := `SELECT COUNT(*) FROM movies`
if searchTerm != "" {
query += `
WHERE title ILIKE '%' || $3 || '%'
OR "cast" ILIKE '%' || $3 || '%'
OR director ILIKE '%' || $3 || '%'
`

err = r.db.QueryRowContext(ctx, countQuery).Scan(&totalCount)
if err != nil {
return nil, err
}
countQuery += `
WHERE title ILIKE '%' || $1 || '%'
OR "cast" ILIKE '%' || $1 || '%'
OR director ILIKE '%' || $1 || '%'
`
}
query += " ORDER BY id LIMIT $1 OFFSET $2"

// Query movies
if searchTerm == "" {
rows, err = r.db.QueryContext(ctx, query, pageSize+1, offset)
} else {
// Query to get the movies for the current page, including search term filtering
query := `
SELECT id, title, genre, year, wiki, plot, director, "cast"
FROM movies
WHERE title ILIKE '%' || $3 || '%'
OR "cast" ILIKE '%' || $3 || '%'
OR director ILIKE '%' || $3 || '%'
ORDER BY id
LIMIT $1 OFFSET $2
`

rows, err = r.db.QueryContext(ctx, query, pageSize+1, offset, searchTerm)
if err != nil {
return nil, err
}

countQuery := `
SELECT COUNT(*)
FROM movies
WHERE title ILIKE '%' || $1 || '%'
OR "cast" ILIKE '%' || $1 || '%'
OR director ILIKE '%' || $1 || '%'
`
}
if err != nil {
return nil, fmt.Errorf("failed to query movies: %w", err)
}
defer rows.Close()

// Count movies
if searchTerm == "" {
err = r.db.QueryRowContext(ctx, countQuery).Scan(&totalCount)
} else {
err = r.db.QueryRowContext(ctx, countQuery, searchTerm).Scan(&totalCount)
if err != nil {
return nil, err
}
}
defer rows.Close()
if err != nil {
return nil, fmt.Errorf("failed to count movies: %w", err)
}

var movies []*models.Movie
for rows.Next() {
Expand Down
Loading