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

Ibk branch #32

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion api/cmd/console-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

controllers "github.com/plutov/formulosity/api/pkg/controllers"
"github.com/plutov/formulosity/api/pkg/log"
"github.com/plutov/formulosity/api/pkg/middleware"
"github.com/plutov/formulosity/api/pkg/services"
"github.com/plutov/formulosity/api/pkg/surveys"
)
Expand All @@ -21,17 +22,25 @@ func main() {
if err != nil {
log.WithError(err).Fatal("unable to init dependencies")
}
jwtSecret := os.Getenv("JWT_SECRET")
if jwtSecret == "" {
log.WithError(err).Fatal("JWT_SECRET environment variable is not set")
}
jwtSvc := services.NewJWTService(jwtSecret, svc)

if err := surveys.SyncSurveys(svc); err != nil {
log.WithError(err).Fatal("unable to sync surveys")
}

handler := controllers.NewHandler(svc)
handler := controllers.NewHandler(svc, jwtSvc)
if err != nil {
log.WithError(err).Fatal("unable to start server")
}

r := controllers.NewRouter(handler)
authMiddleware := middleware.AuthMiddleware(jwtSvc)

r.Group("/app").Use(authMiddleware)

if err := r.Start(":8080"); err != nil {
log.WithError(err).Fatal("shutting down the server")
Expand Down
9 changes: 9 additions & 0 deletions api/migrations/postgres/000001_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ CREATE TABLE
);

CREATE UNIQUE INDEX surveys_answers_unique ON surveys_answers (session_id, question_id);

CREATE TABLE IF NOT EXISTS
users(
id bigserial PRIMARY KEY,
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
name text NOT NULL,
email citext UNIQUE NOT NULL,
password_hash bytea NOT NULL,
)
9 changes: 9 additions & 0 deletions api/migrations/sqlite/000001_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ CREATE TABLE surveys_answers (
);

CREATE UNIQUE INDEX surveys_answers_unique ON surveys_answers (session_id, question_id);

CREATE TABLE IF NOT EXISTS
users(
id bigserial PRIMARY KEY,
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
name text NOT NULL,
email citext UNIQUE NOT NULL,
password_hash bytea NOT NULL,
)
133 changes: 0 additions & 133 deletions api/mocks/answer.go

This file was deleted.

Loading