hway/pkg/context/profiles.go

54 lines
1.2 KiB
Go
Raw Normal View History

package context
import (
"net/http"
"github.com/labstack/echo/v4"
2025-01-04 21:13:51 -05:00
hwayorm "github.com/onsonr/hway/internal/models"
)
func UpdateProfile(c echo.Context) (*hwayorm.Profile, error) {
ctx, ok := c.(*GatewayContext)
if !ok {
return nil, echo.NewHTTPError(http.StatusInternalServerError, "Profile Context not found")
}
address := c.FormValue("address")
handle := c.FormValue("handle")
name := c.FormValue("name")
profile, err := ctx.UpdateProfile(bgCtx(), hwayorm.UpdateProfileParams{
Address: address,
Handle: handle,
Name: name,
})
if err != nil {
return nil, err
}
return &profile, nil
}
func ReadProfile(c echo.Context) (*hwayorm.Profile, error) {
ctx, ok := c.(*GatewayContext)
if !ok {
return nil, echo.NewHTTPError(http.StatusInternalServerError, "Profile Context not found")
}
handle := c.Param("handle")
profile, err := ctx.GetProfileByHandle(bgCtx(), handle)
if err != nil {
return nil, err
}
return &profile, nil
}
func DeleteProfile(c echo.Context) error {
ctx, ok := c.(*GatewayContext)
if !ok {
return echo.NewHTTPError(http.StatusInternalServerError, "Profile Context not found")
}
address := c.Param("address")
err := ctx.SoftDeleteProfile(bgCtx(), address)
if err != nil {
return err
}
return nil
}