mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
|
package context
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/labstack/echo/v4"
|
||
|
hwayorm "github.com/onsonr/sonr/internal/database/hwayorm"
|
||
|
)
|
||
|
|
||
|
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
|
||
|
}
|