forked from ThreeDotsLabs/wild-workouts-go-ddd-example
-
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
a638f03
commit 8d92748
Showing
62 changed files
with
2,668 additions
and
870 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package logs | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func LogCommandExecution(commandName string, cmd interface{}, err error) { | ||
log := logrus.WithField("cmd", cmd) | ||
|
||
if err == nil { | ||
log.Info(commandName + " command succeeded") | ||
} else { | ||
log.WithError(err).Error(commandName + " command failed") | ||
} | ||
} |
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,24 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/app/command" | ||
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/app/query" | ||
) | ||
|
||
type Application struct { | ||
Commands Commands | ||
Queries Queries | ||
} | ||
|
||
type Commands struct { | ||
CancelTraining command.CancelTrainingHandler | ||
ScheduleTraining command.ScheduleTrainingHandler | ||
|
||
MakeHoursAvailable command.MakeHoursAvailableHandler | ||
MakeHoursUnavailable command.MakeHoursUnavailableHandler | ||
} | ||
|
||
type Queries struct { | ||
HourAvailability query.HourAvailabilityHandler | ||
TrainerAvailableHours query.AvailableHoursHandler | ||
} |
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,34 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/errors" | ||
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/domain/hour" | ||
) | ||
|
||
type CancelTrainingHandler struct { | ||
hourRepo hour.Repository | ||
} | ||
|
||
func NewCancelTrainingHandler(hourRepo hour.Repository) CancelTrainingHandler { | ||
if hourRepo == nil { | ||
panic("nil hourRepo") | ||
} | ||
|
||
return CancelTrainingHandler{hourRepo: hourRepo} | ||
} | ||
|
||
func (h CancelTrainingHandler) Handle(ctx context.Context, hourToCancel time.Time) error { | ||
if err := h.hourRepo.UpdateHour(ctx, hourToCancel, func(h *hour.Hour) (*hour.Hour, error) { | ||
if err := h.CancelTraining(); err != nil { | ||
return nil, err | ||
} | ||
return h, nil | ||
}); err != nil { | ||
return errors.NewSlugError(err.Error(), "unable-to-update-availability") | ||
} | ||
|
||
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,36 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/errors" | ||
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/domain/hour" | ||
) | ||
|
||
type MakeHoursAvailableHandler struct { | ||
hourRepo hour.Repository | ||
} | ||
|
||
func NewMakeHoursAvailableHandler(hourRepo hour.Repository) MakeHoursAvailableHandler { | ||
if hourRepo == nil { | ||
panic("hourRepo is nil") | ||
} | ||
|
||
return MakeHoursAvailableHandler{hourRepo: hourRepo} | ||
} | ||
|
||
func (c MakeHoursAvailableHandler) Handle(ctx context.Context, hours []time.Time) error { | ||
for _, hourToUpdate := range hours { | ||
if err := c.hourRepo.UpdateHour(ctx, hourToUpdate, func(h *hour.Hour) (*hour.Hour, error) { | ||
if err := h.MakeAvailable(); err != nil { | ||
return nil, err | ||
} | ||
return h, nil | ||
}); err != nil { | ||
return errors.NewSlugError(err.Error(), "unable-to-update-availability") | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.