-
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
3d1eb8c
commit da7099e
Showing
11 changed files
with
194 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
}, | ||
"forwardPorts": [ | ||
3000, | ||
5432 | ||
5432, | ||
26257 | ||
], | ||
"customizations": { | ||
"vscode": { | ||
|
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
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,96 @@ | ||
package comments | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
"github.com/zeiss/fiber-htmx/components/cards" | ||
"github.com/zeiss/fiber-htmx/components/toasts" | ||
"github.com/zeiss/service-lens/internal/models" | ||
"github.com/zeiss/service-lens/internal/ports" | ||
|
||
"github.com/go-playground/validator/v10" | ||
htmx "github.com/zeiss/fiber-htmx" | ||
seed "github.com/zeiss/gorm-seed" | ||
) | ||
|
||
var validate *validator.Validate | ||
|
||
// CreateDesignCommentControllerImpl ... | ||
type CreateDesignCommentControllerImpl struct { | ||
Comment models.DesignComment | ||
store seed.Database[ports.ReadTx, ports.ReadWriteTx] | ||
htmx.DefaultController | ||
} | ||
|
||
// NewCreateDesignCommentController ... | ||
func NewCreateDesignCommentController(store seed.Database[ports.ReadTx, ports.ReadWriteTx]) *CreateDesignCommentControllerImpl { | ||
return &CreateDesignCommentControllerImpl{store: store} | ||
} | ||
|
||
// Error ... | ||
func (l *CreateDesignCommentControllerImpl) Error(err error) error { | ||
return toasts.RenderToasts( | ||
l.Ctx(), | ||
toasts.Toasts( | ||
toasts.ToastsProps{}, | ||
toasts.ToastAlertError( | ||
toasts.ToastProps{}, | ||
htmx.Text(err.Error()), | ||
), | ||
), | ||
) | ||
} | ||
|
||
// Prepare ... | ||
func (l *CreateDesignCommentControllerImpl) Prepare() error { | ||
validate = validator.New() | ||
|
||
var request struct { | ||
ID uuid.UUID `uri:"id" validate:"required,uuid"` | ||
Comment string `json:"comment" validate:"required"` | ||
} | ||
|
||
err := l.BindBody(&request) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = l.BindParams(&request) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = validate.Struct(&request) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
l.Comment = models.DesignComment{ | ||
DesignID: request.ID, | ||
Comment: request.Comment, | ||
} | ||
|
||
return l.store.ReadWriteTx(l.Context(), func(ctx context.Context, tx ports.ReadWriteTx) error { | ||
return tx.CreateDesignComment(ctx, &l.Comment) | ||
}) | ||
} | ||
|
||
// Post ... | ||
func (l *CreateDesignCommentControllerImpl) Post() error { | ||
return l.Render( | ||
cards.CardBordered( | ||
cards.CardProps{ | ||
ClassNames: htmx.ClassNames{ | ||
"my-4": true, | ||
}, | ||
}, | ||
cards.Body( | ||
cards.BodyProps{}, | ||
htmx.Div( | ||
htmx.Text(l.Comment.Comment), | ||
), | ||
), | ||
), | ||
) | ||
} |
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
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,5 +1,6 @@ | ||
package utils | ||
|
||
const ( | ||
ShowDesigUrlFormat = "/designs/%s" | ||
ShowDesigUrlFormat = "/designs/%s" | ||
CreateDesignCommentUrlFormat = "/designs/%s/comments" | ||
) |