Skip to content

Commit e6ece0e

Browse files
committed
improve activation handler
1 parent 64cad37 commit e6ece0e

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

cmd/api/admin.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
"strings"
1414
"time"
1515

16+
"slices"
17+
1618
db "github.com/Hopertz/rent/db/sqlc"
1719
"github.com/labstack/echo/v4"
18-
"slices"
1920
)
2021

2122
type SignupData struct {
@@ -127,7 +128,6 @@ func (app *application) registerAdminHandler(c echo.Context) error {
127128
return c.JSON(http.StatusCreated, nil)
128129
}
129130

130-
131131
func (app *application) activateAdminHandler(c echo.Context) error {
132132

133133
var input struct {
@@ -156,15 +156,17 @@ func (app *application) activateAdminHandler(c echo.Context) error {
156156
switch {
157157
case errors.Is(err, sql.ErrNoRows):
158158
slog.Error("error fetching token user admin", "error", err)
159-
return c.JSON(http.StatusNotFound, envelope{"error": "invalid token"})
159+
return c.JSON(http.StatusNotFound, envelope{"error": "invalid token or expired"})
160160
default:
161161
slog.Error("error fetching token user admin", "error", err)
162162
return c.JSON(http.StatusInternalServerError, envelope{"error": "internal server error"})
163163
}
164164

165165
}
166166

167-
admin.Activated = true
167+
if admin.Activated {
168+
return c.JSON(http.StatusBadRequest, envelope{"error": "admin arleady actvated"})
169+
}
168170

169171
param := db.UpdateAdminParams{
170172

@@ -188,17 +190,6 @@ func (app *application) activateAdminHandler(c echo.Context) error {
188190

189191
}
190192

191-
a := db.DeleteAllTokenParams{
192-
Scope: db.ScopeActivation,
193-
ID: admin.ID,
194-
}
195-
err = app.store.DeleteAllToken(c.Request().Context(), a)
196-
197-
if err != nil {
198-
slog.Error("error deleting token", "error", err)
199-
return c.JSON(http.StatusInternalServerError, envelope{"error": "internal server error"})
200-
}
201-
202193
return c.JSON(http.StatusOK, nil)
203194
}
204195

0 commit comments

Comments
 (0)