-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add common folder; start postgres work
- Loading branch information
1 parent
c8faedb
commit 0820e59
Showing
21 changed files
with
356 additions
and
126 deletions.
There are no files selected for viewing
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 +1,10 @@ | ||
FROM qmcgaw/godevcontainer | ||
FROM qmcgaw/godevcontainer | ||
|
||
# Need curl to install atlas | ||
RUN apk --no-cache add curl | ||
|
||
# Install sqlc to use command line within container for testing | ||
RUN go mod init tmp && go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest | ||
|
||
# Install atlas to use command line within container for testing | ||
RUN curl -sSf https://atlasgo.sh | sh |
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,5 @@ | ||
go 1.22.1 | ||
|
||
use ./internal/chronicle | ||
|
||
use ./internal/common |
25 changes: 25 additions & 0 deletions
25
internal/chronicle/adapter/persistence/postgres/sqlc/query.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- name: GetGame :one | ||
SELECT * FROM game | ||
WHERE id = $1 LIMIT 1; | ||
|
||
-- name: ListGames :many | ||
SELECT * FROM game | ||
ORDER BY name; | ||
|
||
-- name: CreateGame :one | ||
INSERT INTO game ( | ||
name, type | ||
) VALUES ( | ||
$1, $2 | ||
) | ||
RETURNING *; | ||
|
||
-- name: UpdateGame :exec | ||
UPDATE game | ||
set name = $2, | ||
type = $3 | ||
WHERE id = $1; | ||
|
||
-- name: DeleteGame :exec | ||
DELETE FROM game | ||
WHERE id = $1; |
32 changes: 32 additions & 0 deletions
32
internal/chronicle/adapter/persistence/postgres/sqlc/repository/db.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
internal/chronicle/adapter/persistence/postgres/sqlc/repository/models.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
internal/chronicle/adapter/persistence/postgres/sqlc/repository/query.sql.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
internal/chronicle/adapter/persistence/postgres/sqlc/schema.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE game ( | ||
id BIGSERIAL PRIMARY KEY, | ||
name text NOT NULL, | ||
type text NOT NULL | ||
); |
10 changes: 10 additions & 0 deletions
10
internal/chronicle/adapter/persistence/postgres/sqlc/sqlc.yml
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,10 @@ | ||
version: "2" | ||
sql: | ||
- engine: "postgresql" | ||
queries: "query.sql" | ||
schema: "schema.sql" | ||
gen: | ||
go: | ||
package: "repository" | ||
out: "repository" | ||
sql_package: "pgx/v5" |
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,39 @@ | ||
package http | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/SomethingSexy/chronicle/internal/chronicle/core/game/domain" | ||
) | ||
|
||
type GameRequest struct { | ||
Name string `jsonapi:"attr,name"` | ||
Type string `jsonapi:"attr,type"` | ||
// ID int `jsonapi:"primary,blogs"` | ||
// Title string `jsonapi:"attr,title"` | ||
// Posts []*Post `jsonapi:"relation,posts"` | ||
// CurrentPost *Post `jsonapi:"relation,current_post"` | ||
// CurrentPostID int `jsonapi:"attr,current_post_id"` | ||
// CreatedAt time.Time `jsonapi:"attr,created_at"` | ||
// ViewCount int `jsonapi:"attr,view_count"` | ||
} | ||
|
||
func (a *GameRequest) Bind(r *http.Request) error { | ||
if a.Name == "" { | ||
return errors.New("missing required game fields") | ||
} | ||
|
||
if a.Type == "" { | ||
return errors.New("missing required game fields") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *GameRequest) ToDomain() domain.Game { | ||
return domain.Game{ | ||
Type: a.Type, | ||
Name: a.Name, | ||
} | ||
} |
Oops, something went wrong.