Compare commits
2 Commits
473ea2ba74
...
v1.1.0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3c6d7e027a | ||
![]() |
50420bc0a5 |
@@ -159,7 +159,7 @@ func main() {
|
|||||||
|
|
||||||
app.GET("/admin/clients/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
app.GET("/admin/clients/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
||||||
for _, client := range clients {
|
for _, client := range clients {
|
||||||
if client.ID == id {
|
if client.ID == id || client.Name == id.String() {
|
||||||
return c.JSONPretty(http.StatusOK, client, indent)
|
return c.JSONPretty(http.StatusOK, client, indent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,7 +228,7 @@ func main() {
|
|||||||
return c.NoContent(http.StatusInternalServerError)
|
return c.NoContent(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSONPretty(http.StatusOK, string(bytes[:n]), indent)
|
return c.String(http.StatusOK, string(bytes[:n]))
|
||||||
})))
|
})))
|
||||||
|
|
||||||
app.POST("/admin/name/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
app.POST("/admin/name/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
||||||
@@ -237,12 +237,22 @@ func main() {
|
|||||||
return c.JSON(http.StatusBadRequest, "missing field 'name'")
|
return c.JSON(http.StatusBadRequest, "missing field 'name'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var target *Client = nil
|
||||||
|
|
||||||
for _, client := range clients {
|
for _, client := range clients {
|
||||||
if client.ID == id {
|
if client.ID == id || client.Name == id.String() {
|
||||||
client.Name = name
|
target = client
|
||||||
client.UpdatedAt = time.Now()
|
|
||||||
return c.JSON(http.StatusOK, echo.Map{"message": "ok"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if client.Name == name {
|
||||||
|
return c.JSON(http.StatusBadRequest, echo.Map{"message": "name already used"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if target != nil {
|
||||||
|
target.Name = name
|
||||||
|
target.UpdatedAt = time.Now()
|
||||||
|
return c.JSON(http.StatusOK, echo.Map{"message": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusNotFound, echo.Map{"message": "not found"})
|
return c.JSON(http.StatusNotFound, echo.Map{"message": "not found"})
|
||||||
@@ -250,7 +260,7 @@ func main() {
|
|||||||
|
|
||||||
app.POST("/admin/exit/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
app.POST("/admin/exit/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
||||||
for _, client := range clients {
|
for _, client := range clients {
|
||||||
if client.ID == id {
|
if client.ID == id || client.Name == id.String() {
|
||||||
client.ExitWanted = true
|
client.ExitWanted = true
|
||||||
return c.JSON(http.StatusOK, echo.Map{"message": "ok"})
|
return c.JSON(http.StatusOK, echo.Map{"message": "ok"})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user