MCPcopy Create free account
hub / github.com/kataras/iris / GetTodo

Function GetTodo

_examples/auth/jwt/tutorial/api/todo.go:40–65  ·  view source on GitHub ↗

GetTodo lists all users todos. Parameter: {id}.

(repo repository.TodoRepository)

Source from the content-addressed store, hash-verified

38// GetTodo lists all users todos.
39// Parameter: {id}.
40func GetTodo(repo repository.TodoRepository) iris.Handler {
41 return func(ctx iris.Context) {
42 id := ctx.Params().Get("id")
43 userID := GetUserID(ctx)
44
45 todo, err := repo.GetByID(id)
46 if err != nil {
47 code := iris.StatusInternalServerError
48 if errors.Is(err, repository.ErrNotFound) {
49 code = iris.StatusNotFound
50 }
51
52 ctx.StopWithError(code, err)
53 return
54 }
55
56 if !IsAdmin(ctx) { // admin can access any user's todos.
57 if todo.UserID != userID {
58 ctx.StopWithStatus(iris.StatusForbidden)
59 return
60 }
61 }
62
63 ctx.JSON(todo)
64 }
65}
66
67// ListTodos lists todos of the current user.
68func ListTodos(repo repository.TodoRepository) iris.Handler {

Callers 1

NewRouterFunction · 0.85

Calls 9

GetUserIDFunction · 0.85
IsAdminFunction · 0.85
ParamsMethod · 0.80
StopWithErrorMethod · 0.80
StopWithStatusMethod · 0.80
GetMethod · 0.65
GetByIDMethod · 0.65
IsMethod · 0.45
JSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…