-
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.
- Loading branch information
1 parent
8f06781
commit c33a731
Showing
13 changed files
with
342 additions
and
50 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
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,57 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/henriquepw/imperium-tattoo/pkg/date" | ||
"github.com/henriquepw/imperium-tattoo/web/types" | ||
) | ||
|
||
type ClientProcedureStore interface { | ||
Insert(ctx context.Context, item types.ClientProcedure) error | ||
Update(ctx context.Context, id string, dto types.ClientProcedureUpdateDTO) error | ||
List(ctx context.Context, clientID string) ([]types.ClientProcedure, error) | ||
} | ||
|
||
type clientProcedureStore struct { | ||
db *sql.DB | ||
} | ||
|
||
func NewClientProcedureStore(db *sql.DB) *clientProcedureStore { | ||
return &clientProcedureStore{db} | ||
} | ||
|
||
func (s *clientProcedureStore) Insert(ctx context.Context, c types.ClientProcedure) error { | ||
query := ` | ||
INSERT INTO client_procedure ( | ||
id, | ||
client_id, | ||
procedure_id, | ||
description, | ||
done_at, | ||
created_at, | ||
updated_at | ||
) VALUES (?, ?, ?, ?, ?, ?, ?) | ||
` | ||
_, error := s.db.ExecContext( | ||
ctx, query, | ||
c.ID, | ||
c.ClientID, | ||
c.ProcedureID, | ||
c.Description, | ||
date.FormatToISO(c.DoneAt), | ||
date.FormatToISO(c.CreatedAt), | ||
date.FormatToISO(c.UpdatedAt), | ||
) | ||
|
||
return error | ||
} | ||
|
||
func (s *clientProcedureStore) List(ctx context.Context, clientID string) ([]types.ClientProcedure, error) { | ||
return []types.ClientProcedure{}, nil | ||
} | ||
|
||
func (s *clientProcedureStore) Update(ctx context.Context, clientID string, dto types.ClientProcedureUpdateDTO) 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
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,63 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/henriquepw/imperium-tattoo/pkg/customid" | ||
"github.com/henriquepw/imperium-tattoo/pkg/errors" | ||
"github.com/henriquepw/imperium-tattoo/pkg/validate" | ||
"github.com/henriquepw/imperium-tattoo/web/db" | ||
"github.com/henriquepw/imperium-tattoo/web/types" | ||
) | ||
|
||
type ClientProcedureService interface { | ||
CreateClientProcedure(ctx context.Context, dto types.ClientProcedureCreateDTO) (*types.ClientProcedure, error) | ||
} | ||
|
||
type clientProcedureService struct { | ||
store db.ClientProcedureStore | ||
} | ||
|
||
func NewClientProcedureService(store db.ClientProcedureStore) *clientProcedureService { | ||
return &clientProcedureService{store} | ||
} | ||
|
||
func (s *clientProcedureService) CreateClientProcedure(ctx context.Context, dto types.ClientProcedureCreateDTO) (*types.ClientProcedure, error) { | ||
if err := validate.CheckPayload(dto); err != nil { | ||
return nil, err | ||
} | ||
|
||
id, err := customid.New() | ||
if err != nil { | ||
return nil, errors.Internal("Não foi possível inserir o procedimento") | ||
} | ||
|
||
// TODO: check if procedure exist | ||
// TODO: check if client exist | ||
|
||
doneAt, err := time.Parse(time.DateOnly, dto.DoneAt) | ||
if err != nil { | ||
return nil, errors.InvalidRequestData(map[string]string{"doneAt": "Data inválida"}) | ||
} | ||
|
||
now := time.Now() | ||
procedure := types.ClientProcedure{ | ||
ID: id, | ||
CreatedAt: now, | ||
UpdatedAt: now, | ||
DoneAt: doneAt, | ||
Description: dto.Description, | ||
ClientID: dto.ClientID, | ||
ProcedureID: dto.ProcedureID, | ||
} | ||
|
||
err = s.store.Insert(ctx, procedure) | ||
if err != nil { | ||
fmt.Println(err) | ||
return nil, errors.Internal("Não foi possível inserir o procedimento") | ||
} | ||
|
||
return &procedure, 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,25 @@ | ||
package types | ||
|
||
import "time" | ||
|
||
type ClientProcedure struct { | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
DoneAt time.Time | ||
ID string | ||
ClientID string | ||
ProcedureID string | ||
Description string | ||
} | ||
|
||
type ClientProcedureCreateDTO struct { | ||
DoneAt string `json:"doneAt" validate:"required"` | ||
ClientID string `json:"clientId" validate:"required,id,len=18"` | ||
ProcedureID string `json:"procedureId" validate:"required,id,len=18"` | ||
Description string `json:"description" validate:"required,min=5"` | ||
} | ||
|
||
type ClientProcedureUpdateDTO struct { | ||
DoneAt time.Time `validate:"required"` | ||
Description string `validate:"required,min=5"` | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package types | ||
|
||
type Procedure struct { | ||
ID string | ||
Name string | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} |
Oops, something went wrong.