diff --git a/.env b/.env index f727440..d655d55 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ ENV=debug PORT=3000 -POSTGRES_URL=postgresql://localhost/micrach \ No newline at end of file +POSTGRES_URL=postgres://localhost/micrach \ No newline at end of file diff --git a/.env.example b/.env.example index f727440..d655d55 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ ENV=debug PORT=3000 -POSTGRES_URL=postgresql://localhost/micrach \ No newline at end of file +POSTGRES_URL=postgres://localhost/micrach \ No newline at end of file diff --git a/.gitignore b/.gitignore index dc806f3..554ca14 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,6 @@ __debug_bin micrach -uploads/ \ No newline at end of file +uploads/ + +.env \ No newline at end of file diff --git a/main.go b/main.go index 5ea44dd..e350ef1 100644 --- a/main.go +++ b/main.go @@ -9,16 +9,15 @@ import ( Config "micrach/config" Controllers "micrach/controllers" - - // Db "micrach/db" + Db "micrach/db" Repositories "micrach/repositories" // Utils "micrach/utils" ) func main() { Config.Init() - // Db.Init() - // defer Db.Pool.Close() + Db.Init() + defer Db.Pool.Close() gin.SetMode(Config.App.Env) Repositories.Seed() diff --git a/repositories/files_repository.go b/repositories/files_repository.go index 391fc08..77a6d62 100644 --- a/repositories/files_repository.go +++ b/repositories/files_repository.go @@ -5,6 +5,7 @@ import ( Db "micrach/db" "github.com/jackc/pgtype" + "github.com/jackc/pgx/v4" ) type FilesRepository struct{} @@ -23,10 +24,15 @@ func (r *FilesRepository) Create(f File) error { VALUES ($1, $2, $3, $4) ` - conn.QueryRow( + row := conn.QueryRow( context.TODO(), sql, f.PostID, f.Name, f.Ext, f.Size, ) + err = row.Scan() + if err != nil && err != pgx.ErrNoRows { + return err + } + return nil } diff --git a/repositories/posts_repository.go b/repositories/posts_repository.go index b366429..eb32a2c 100644 --- a/repositories/posts_repository.go +++ b/repositories/posts_repository.go @@ -93,7 +93,10 @@ func (r *PostsRepository) Create(p Post) (int, error) { } createdPost := new(Post) - row.Scan(&createdPost.ID) + err = row.Scan(&createdPost.ID) + if err != nil { + return 0, err + } return createdPost.ID, nil } diff --git a/repositories/seeds.go b/repositories/seeds.go index 7e201ce..87d610a 100644 --- a/repositories/seeds.go +++ b/repositories/seeds.go @@ -75,7 +75,7 @@ func seedLocal() { func seedDb() { // preparing seed data with parent posts with files var parentPosts []Post - for i := 1; i < 10; i++ { + for i := 1; i < 100; i++ { post := getPost(i, nil) parentPosts = append(parentPosts, post) } @@ -97,7 +97,7 @@ func seedDb() { } // making child posts - for i := 0; i < 10; i++ { + for i := 0; i < 100; i++ { // getting child post with files childPost := getPost(0, &parentPostID) childPostID, err := Posts.Create(childPost)