2025-01-04 18:51:40 -05:00
|
|
|
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"
|
2025-01-04 18:51:40 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|