dev
This commit is contained in:
parent
458cc25ded
commit
dd6f2e2d14
@ -13,6 +13,9 @@ func CreateTarget(targetService model.TargetService, authClient model.AuthClient
|
|||||||
Amount model.DonatAmount `json:"amount"`
|
Amount model.DonatAmount `json:"amount"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
type Response struct {
|
||||||
|
TargetID model.TargetID `json:"targetID"`
|
||||||
|
}
|
||||||
return func(request echo.Context) error {
|
return func(request echo.Context) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var body CreateTargetBody
|
var body CreateTargetBody
|
||||||
@ -31,12 +34,12 @@ func CreateTarget(targetService model.TargetService, authClient model.AuthClient
|
|||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = targetService.CreateTarget(ctx, model.StreamerID(authData.StreamerID), body.Amount, body.Text)
|
targetID, err := targetService.CreateTarget(ctx, model.StreamerID(authData.StreamerID), body.Amount, body.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
return request.String(http.StatusOK, "Created target successfully")
|
return request.JSON(http.StatusOK, Response{TargetID: targetID})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +52,13 @@ type DonatRepo interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TargetService interface {
|
type TargetService interface {
|
||||||
CreateTarget(ctx context.Context, streamerID StreamerID, amount DonatAmount, text string) error
|
CreateTarget(ctx context.Context, streamerID StreamerID, amount DonatAmount, text string) (TargetID, error)
|
||||||
GetAllTarget(ctx context.Context, streamerID StreamerID) ([]*Target, error)
|
GetAllTarget(ctx context.Context, streamerID StreamerID) ([]*Target, error)
|
||||||
AddAmountToTarget(ctx context.Context, targetID TargetID, amount DonatAmount) error
|
AddAmountToTarget(ctx context.Context, targetID TargetID, amount DonatAmount) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type TargetRepo interface {
|
type TargetRepo interface {
|
||||||
CreateTarget(ctx context.Context, streamerID StreamerID, amount DonatAmount, text string) error
|
CreateTarget(ctx context.Context, streamerID StreamerID, amount DonatAmount, text string) (TargetID, error)
|
||||||
GetAllTarget(ctx context.Context, streamerID StreamerID) ([]*Target, error)
|
GetAllTarget(ctx context.Context, streamerID StreamerID) ([]*Target, error)
|
||||||
AddAmountToTarget(ctx context.Context, targetID TargetID, amount DonatAmount) error
|
AddAmountToTarget(ctx context.Context, targetID TargetID, amount DonatAmount) error
|
||||||
}
|
}
|
||||||
|
@ -24,19 +24,19 @@ func (targetRepo *RepoTarget) CreateTarget(
|
|||||||
streamerID model.StreamerID,
|
streamerID model.StreamerID,
|
||||||
amount model.DonatAmount,
|
amount model.DonatAmount,
|
||||||
text string,
|
text string,
|
||||||
) error {
|
) (model.TargetID, error) {
|
||||||
args := pgx.NamedArgs{
|
args := pgx.NamedArgs{
|
||||||
"streamer_id": streamerID,
|
"streamer_id": streamerID,
|
||||||
"amount": amount,
|
"amount": amount,
|
||||||
"text": text,
|
"text": text,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := targetRepo.db.Insert(ctx, sql.CreateTarget, args)
|
targetID, err := targetRepo.db.Insert(ctx, sql.CreateTarget, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
return nil
|
return model.TargetID(targetID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (targetRepo *RepoTarget) GetAllTarget(
|
func (targetRepo *RepoTarget) GetAllTarget(
|
||||||
|
@ -23,13 +23,13 @@ func (targetService *ServiceTarget) CreateTarget(
|
|||||||
streamerID model.StreamerID,
|
streamerID model.StreamerID,
|
||||||
amount model.DonatAmount,
|
amount model.DonatAmount,
|
||||||
text string,
|
text string,
|
||||||
) error {
|
) (model.TargetID, error) {
|
||||||
err := targetService.targetRepo.CreateTarget(ctx, streamerID, amount, text)
|
targetID, err := targetService.targetRepo.CreateTarget(ctx, streamerID, amount, text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
return nil
|
return targetID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (targetService *ServiceTarget) GetAllTarget(
|
func (targetService *ServiceTarget) GetAllTarget(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user