Skip to content

Commit

Permalink
feat: add common folder; start postgres work
Browse files Browse the repository at this point in the history
  • Loading branch information
SomethingSexy committed Jul 25, 2024
1 parent c8faedb commit 0820e59
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 126 deletions.
11 changes: 10 additions & 1 deletion .devcontainer/Dockerfile
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"vscode"
],
"shutdownAction": "stopCompose",
"postCreateCommand": "~/.windows.sh && go mod download && go mod tidy",
"postCreateCommand": "go mod download && go mod tidy",
"workspaceFolder": "/workspace",
// "overrideCommand": "",
"customizations": {
Expand Down
5 changes: 5 additions & 0 deletions go.work
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 internal/chronicle/adapter/persistence/postgres/sqlc/query.sql
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;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 internal/chronicle/adapter/persistence/postgres/sqlc/sqlc.yml
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"
105 changes: 0 additions & 105 deletions internal/chronicle/core/game/adapter/http.go

This file was deleted.

39 changes: 39 additions & 0 deletions internal/chronicle/core/game/adapter/http/game_request.go
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,
}
}
Loading

0 comments on commit 0820e59

Please sign in to comment.