Skip to content

Commit

Permalink
Merge pull request #96 from isaqueveras/fix-create-project
Browse files Browse the repository at this point in the history
fix: add project_id in table project_participants
  • Loading branch information
isaqueveras committed Jan 3, 2023
2 parents 3d35372 + 02a3dde commit 024cf89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions internal/infrastructure/project/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ type pg struct {

// Create contains the flow for create project in database
func (pg *pg) create(input *project.CreateProject) (err error) {
var projectID *string
if err = pg.DB.Builder.
Insert("projects").
Columns("created_by", "name", "description", "color", "slug").
Values(input.CreatedByID, input.Name, input.Description, input.Color, input.Slug).
Suffix(`RETURNING "id"`).
Scan(new(string)); err != nil {
Scan(&projectID); err != nil {
return oops.Err(err)
}

for _, value := range input.Participants {
if err = pg.DB.Builder.
Insert("project_participants").
Columns("user_id", "start_date", "departure_date").
Values(value.UserID, value.StartDate, value.DepartureDate).
Columns("user_id", "start_date", "departure_date", "project_id").
Values(value.UserID, value.StartDate, value.DepartureDate, projectID).
Suffix(`RETURNING "user_id"`).
Scan(new(string)); err != nil {
return oops.Err(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
-- license that can be found in the LICENSE file.

CREATE TABLE project_participants (
"user_id" UUID NOT NULL REFERENCES users (id),
"start_date" TIMESTAMP WITH TIME ZONE NOT NULL,
departure_date TIMESTAMP WITH TIME ZONE,
project_id UUID NOT NULL REFERENCES projects (id),
user_id UUID NOT NULL REFERENCES users (id),
"start_date" DATE NOT NULL,
departure_date DATE,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE
);

1 comment on commit 024cf89

@vercel
Copy link

@vercel vercel bot commented on 024cf89 Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

power-sso – ./

power-sso.vercel.app
power-sso-isaqueveras.vercel.app
power-sso-git-main-isaqueveras.vercel.app

Please sign in to comment.