Skip to content

Commit

Permalink
feat: delete comments
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Aug 28, 2024
1 parent 8225e77 commit 98d36b0
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.R
designs.Post("/:id/tags", handlers.AddTagDesign())
designs.Delete("/:id/tags/:tag_id", handlers.RemoveTagDesign())
designs.Post("/:id/comments", handlers.CreateDesignComment())
designs.Delete("/:id/comments/:comment_id", handlers.DeleteDesignComment())
designs.Get("/:id/body/edit", handlers.EditBodyDesign())
designs.Put("/:id/body/edit", handlers.UpdateBodyDesign())
designs.Get("/:id/title/edit", handlers.EditTitleDesign())
Expand Down
5 changes: 5 additions & 0 deletions internal/adapters/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,8 @@ func (rw *writeTxImpl) UpdateWorkflowStateOrder(ctx context.Context, workflowId

return rw.conn.Session(&gorm.Session{FullSaveAssociations: true}).Save(&workflow.States).Error
}

// DeleteDesignComment ...
func (rw *writeTxImpl) DeleteDesignComment(ctx context.Context, comment *models.DesignComment) error {
return rw.conn.Debug().Delete(comment, comment.ID).Error
}
7 changes: 7 additions & 0 deletions internal/adapters/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,10 @@ func (a *handlers) RemoveTagDesign() fiber.Handler {
return designs.NewTagController(a.store)
})
}

// DeleteDesignComment ...
func (a *handlers) DeleteDesignComment() fiber.Handler {
return htmx.NewHxControllerHandler(func() htmx.Controller {
return designs.NewCommentsController(a.store)
})
}
18 changes: 17 additions & 1 deletion internal/components/designs/design-comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"github.com/zeiss/fiber-htmx/components/icons"
"github.com/zeiss/fiber-htmx/components/tailwind"
"github.com/zeiss/fiber-htmx/components/tooltips"
"github.com/zeiss/fiber-htmx/components/typography"
"github.com/zeiss/pkg/cast"
"github.com/zeiss/service-lens/internal/models"
"github.com/zeiss/service-lens/internal/utils"
)

// DesignCommentProps ...
Expand Down Expand Up @@ -85,9 +87,23 @@ func DesignComment(props DesignCommentProps) htmx.Node {
dropdowns.DropdownMenuItems(
dropdowns.DropdownMenuItemsProps{
ClassNames: htmx.ClassNames{
tailwind.WFull: true,
tailwind.WFull: false,
"w-52": false,
},
},
dropdowns.DropdownMenuItem(
dropdowns.DropdownMenuItemProps{},
htmx.A(
typography.Error(
typography.Props{},
htmx.Text("Delete"),
),
htmx.HxDelete(fmt.Sprintf(utils.DeleteDesignCommentUrlFormat, props.Design.ID, props.Comment.ID)),
htmx.HxTarget("closest .card"),
htmx.HxSwap("outerHTML"),
htmx.HxConfirm("Are you sure you want to delete this comment?"),
),
),
),
),
),
Expand Down
55 changes: 55 additions & 0 deletions internal/controllers/designs/comments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package designs

import (
"context"

"github.com/zeiss/fiber-htmx/components/toasts"
"github.com/zeiss/service-lens/internal/models"
"github.com/zeiss/service-lens/internal/ports"

"github.com/google/uuid"
htmx "github.com/zeiss/fiber-htmx"
seed "github.com/zeiss/gorm-seed"
)

// CommentsControllerImpl ...
type CommentsControllerImpl struct {
store seed.Database[ports.ReadTx, ports.ReadWriteTx]
htmx.DefaultController
}

// NewCommentsController ...
func NewCommentsController(store seed.Database[ports.ReadTx, ports.ReadWriteTx]) *CommentsControllerImpl {
return &CommentsControllerImpl{store: store}
}

// Error ...
func (l *CommentsControllerImpl) Error(err error) error {
return toasts.RenderToasts(
l.Ctx(),
toasts.Toasts(
toasts.ToastsProps{},
toasts.ToastAlertError(
toasts.ToastProps{},
htmx.Text(err.Error()),
),
),
)
}

// Delete ...
func (l *CommentsControllerImpl) Delete() error {
var params struct {
DesignID uuid.UUID `json:"design_id" params:"id"`
CommentID uuid.UUID `json:"Comment_id" params:"Comment_id"`
}

err := l.BindParams(&params)
if err != nil {
return err
}

return l.store.ReadWriteTx(l.Context(), func(ctx context.Context, tx ports.ReadWriteTx) error {
return tx.DeleteDesignComment(ctx, &models.DesignComment{ID: params.CommentID, DesignID: params.DesignID})
})
}
2 changes: 2 additions & 0 deletions internal/ports/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,6 @@ type Handlers interface {
AddTagDesign() fiber.Handler
// RemoveTagDesign ...
RemoveTagDesign() fiber.Handler
// DeleteDesignComment ...
DeleteDesignComment() fiber.Handler
}
2 changes: 2 additions & 0 deletions internal/ports/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,6 @@ type ReadWriteTx interface {
DeleteWorkflowState(ctx context.Context, state *models.WorkflowState) error
// UpdateWorkflowStateOrder is a method that updates workflow states
UpdateWorkflowStateOrder(ctx context.Context, workflowId uuid.UUID, states []int) error
// DeleteDesignComment is a method that deletes a design comment
DeleteDesignComment(ctx context.Context, comment *models.DesignComment) error
}
1 change: 1 addition & 0 deletions internal/utils/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
CreateWorkloadUrlFormat = "/workloads/new"
AddDesignTagUrlFormat = "/designs/%s/tags"
RemoveDesignTagUrlFormat = "/designs/%s/tags/%s"
DeleteDesignCommentUrlFormat = "/designs/%s/comments/%s"
UpdateWorkflowStepUrlFormat = "/workflows/%s/steps"
SearchWorkflowsUrlFormat = "/designs/search/workflows"
DeleteDesignUrlFormat = "/designs/%s"
Expand Down

0 comments on commit 98d36b0

Please sign in to comment.