2020-11-02 17:46:38 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-11-04 20:12:13 +01:00
|
|
|
"myapp/api"
|
|
|
|
"myapp/domain/repository"
|
2020-11-02 17:46:38 +01:00
|
|
|
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-11-04 20:12:13 +01:00
|
|
|
userRepository = repository.NewMemoryUserRepository()
|
|
|
|
todoRepository = repository.NewMemoryTodoRepository()
|
2020-11-02 17:46:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-11-04 20:12:13 +01:00
|
|
|
if err := repository.GenerateSamples(userRepository, todoRepository); err != nil {
|
|
|
|
panic(err)
|
2020-11-02 17:46:38 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:12:13 +01:00
|
|
|
app := iris.New()
|
2020-11-02 17:46:38 +01:00
|
|
|
|
2020-11-04 20:12:13 +01:00
|
|
|
app.Post("/signin", api.SignIn(userRepository))
|
2020-11-02 17:46:38 +01:00
|
|
|
|
2020-11-04 20:12:13 +01:00
|
|
|
verify := api.Verify()
|
2020-11-02 17:46:38 +01:00
|
|
|
|
2020-11-04 20:12:13 +01:00
|
|
|
todosAPI := app.Party("/todos", verify)
|
|
|
|
todosAPI.Post("/", api.CreateTodo(todoRepository))
|
|
|
|
todosAPI.Get("/", api.ListTodos(todoRepository))
|
|
|
|
todosAPI.Get("/{id}", api.GetTodo(todoRepository))
|
2020-11-02 17:46:38 +01:00
|
|
|
|
2020-11-04 20:12:13 +01:00
|
|
|
adminAPI := app.Party("/admin", verify, api.AllowAdmin)
|
|
|
|
adminAPI.Get("/todos", api.ListAllTodos(todoRepository))
|
2020-11-02 17:46:38 +01:00
|
|
|
|
2020-11-04 20:12:13 +01:00
|
|
|
// POST http://localhost:8080/signin (Form: username, password)
|
|
|
|
// GET http://localhost:8080/todos
|
|
|
|
// GET http://localhost:8080/todos/{id}
|
|
|
|
// POST http://localhost:8080/todos (JSON, Form or URL: title, body)
|
|
|
|
// GET http://localhost:8080/admin/todos
|
|
|
|
app.Listen(":8080")
|
2020-11-02 17:46:38 +01:00
|
|
|
}
|