This repository has been archived by the owner on Mar 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added Comment proto * added extra fields to the makefile * added docker set-up * added comment methods to Backender interface * added Comment model with auto migration extension * added controllers for Comment, added two new helper func to work with time&model * style fix * fix typo * added missing field for the Comment entity and implemented crud functionality * fixed docker flow, added air.toml for hot-reloading, makefile add-ons, removed godotenv * removed godotenv and refactored * refactor * implemented Comment functionalities
- Loading branch information
Showing
25 changed files
with
3,257 additions
and
445 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
root = "." | ||
testdata_dir = "testdata" | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
bin = "./tmp/main" | ||
cmd = "go build -o ./tmp/main ./cmd/pano-api" | ||
delay = 1000 | ||
exclude_dir = ["assets", "tmp", "vendor", "testdata"] | ||
exclude_file = [] | ||
exclude_regex = ["_test.go"] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
full_bin = "" | ||
include_dir = [] | ||
include_ext = ["go", "tpl", "tmpl", "html"] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
send_interrupt = false | ||
stop_on_error = true | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
time = false | ||
|
||
[misc] | ||
clean_on_exit = false | ||
|
||
[screen] | ||
clear_on_rebuild = false |
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,18 @@ | ||
# Building the binary of the App | ||
FROM golang:latest AS builder | ||
RUN mkdir -p /app | ||
WORKDIR /app | ||
COPY . . | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/pano-api /app/cmd/pano-api/main.go | ||
|
||
# Moving the binary to the 'final Image' to make it smaller | ||
FROM alpine | ||
RUN mkdir -p /app | ||
WORKDIR /app | ||
RUN apk add --no-cache nano git curl | ||
# COPY --from=builder /feedback-api/internal/configs/dev.env .env | ||
COPY --from=builder bin/pano-api pano-api | ||
|
||
CMD ["./pano-api"] | ||
|
||
EXPOSE 80 |
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,19 @@ | ||
gen: | ||
@echo "Generating proto files..." | ||
protoc --twirp_out=. --go_out=. rpc/pano-api/service.proto | ||
|
||
upgrade: | ||
@echo "Upgrading dependencies..." | ||
go get -u | ||
|
||
build_up: | ||
@echo "Building pano-api..." | ||
sudo docker compose up --build --remove-orphans | ||
|
||
up: | ||
@echo "Starting docker-compose..." | ||
sudo docker compose up | ||
|
||
down: | ||
@echo "Stopping docker-compose..." | ||
sudo docker compose down --remove-orphans |
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,67 @@ | ||
version: "3.9" | ||
|
||
services: | ||
api-with-air: | ||
image: cosmtrek/air | ||
working_dir: /app | ||
environment: | ||
- POSTGRES_USER=pgtest | ||
- POSTGRES_DB=pgtest | ||
- POSTGRES_PASSWORD=pgtest | ||
- POSTGRES_HOST=postgres | ||
ports: | ||
- "8080:80" | ||
volumes: | ||
- ./.:/app | ||
links: | ||
- postgres | ||
depends_on: | ||
- postgres | ||
|
||
postgres: | ||
image: postgres:13.3-alpine | ||
environment: | ||
- POSTGRES_USER=pgtest | ||
- POSTGRES_DB=pgtest | ||
- POSTGRES_PASSWORD=pgtest | ||
ports: | ||
- "15432:5432" | ||
healthcheck: | ||
test: pg_isready -U pgtest -d pgtest | ||
interval: 10s | ||
timeout: 3s | ||
retries: 5 | ||
|
||
pgadmin: | ||
image: dpage/pgadmin4 | ||
restart: always | ||
environment: | ||
- PGADMIN_DEFAULT_EMAIL=admin@kamp.us | ||
- PGADMIN_DEFAULT_PASSWORD=secret | ||
- PGADMIN_LISTEN_PORT=80 | ||
- PGADMIN_LOG_LEVEL=50 | ||
ports: | ||
- "8090:80" | ||
links: | ||
- postgres | ||
logging: | ||
driver: "none" | ||
volumes: | ||
- ./scripts/servers.json:/pgadmin4/servers.json | ||
|
||
db-migrator: | ||
image: migrate/migrate | ||
command: | ||
- -path | ||
- /migrations/ | ||
- -database | ||
- postgres://pgtest:pgtest@postgres:5432/pgtest?sslmode=disable | ||
- up | ||
links: | ||
- postgres | ||
depends_on: | ||
- postgres | ||
volumes: | ||
- ./db/migrations:/migrations | ||
profiles: | ||
- tools |
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
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,32 @@ | ||
package postgresql | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/kamp-us/pano-api/internal/models" | ||
) | ||
|
||
func (b *PostgreSQLBackend) CreateComment(ctx context.Context, content string, postId string, userId string, parentId *string, deletedAt *time.Time) (*models.Comment, error) { | ||
comment := models.Comment{ | ||
Content: content, | ||
PostID: postId, | ||
UserID: userId, | ||
} | ||
|
||
// TODO: is this the way? | ||
if parentId != nil { | ||
comment.ParentID = *parentId | ||
} | ||
|
||
if deletedAt != nil { | ||
comment.DeletedAt = *deletedAt | ||
} | ||
|
||
result := b.DB.Create(&comment) | ||
if result.Error != nil { | ||
return nil, result.Error | ||
} | ||
|
||
return &comment, nil | ||
} |
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,23 @@ | ||
package postgresql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kamp-us/pano-api/internal/models" | ||
) | ||
|
||
func (b *PostgreSQLBackend) DeleteComment(ctx context.Context, id string) error { | ||
comment := models.Comment{} | ||
|
||
result := b.DB.First(&comment, "id = ?", id) | ||
if result.Error != nil { | ||
return result.Error | ||
} | ||
|
||
result = b.DB.Delete(&comment) | ||
if result.Error != nil { | ||
return result.Error | ||
} | ||
|
||
return nil | ||
} |
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,19 @@ | ||
package postgresql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kamp-us/pano-api/internal/models" | ||
) | ||
|
||
// TODO: why do we return array of pointers? | ||
func (b *PostgreSQLBackend) GetBatchComments(ctx context.Context, ids []string) ([]*models.Comment, error) { | ||
var comments []*models.Comment | ||
result := b.DB.Find(comments, ids) | ||
|
||
if result.Error != nil { | ||
return nil, result.Error | ||
} | ||
|
||
return comments, nil | ||
} |
Oops, something went wrong.