class TodoService
- TodoService
- Reference
- Object
Overview
TodoService
A class that represents a service for managing todos.
Initialization
-
.new(repository : TodoRepository, output_port : TodoOutputPort)
Initializes a new instance of the TodoService class.
#repository
- An instance of the TodoRepository class that provides methods for accessing and manipulating todos.#output_port
- An instance of the TodoOutputPort class that provides methods for displaying todos.
Methods
-
get_all_todos : Array(Todo)
Retrieves all todos from the repository and displays them. Returns an array of Todo objects representing all the todos retrieved from the repository.
-
get_todo_by_id(id : String) : Todo?
Retrieves a todo with the given id from the repository and displays its details.
id
- The id of the todo to retrieve. Returns a Todo object representing the todo with the given id, or nil if no todo is found.
-
create_todo(title : String) : Todo
Creates a new todo with the given title, saves it to the repository, and displays the created todo.
title
- The title of the new todo. Returns a Todo object representing the newly created todo.
-
mark_todo_as_completed(todo : Todo) : Todo
Marks the given todo as completed and displays the completed todo.
todo
- The todo to mark as completed. Returns a Todo object representing the todo that was marked as completed.
Defined in:
domain/services/todo_services.crConstructors
-
.new(repository : TodoRepository, output_port : TodoOutputPort)
Initializes a new instance of the TodoService class.
Instance Method Summary
-
#all_todos : Array(Todo)
Retrieves all todos from the repository and displays them.
-
#create_todo(title : String) : Todo
Creates a new todo with the given title, saves it to the repository, and displays the created todo.
-
#get_todo_by_id(id : String) : Todo | Nil
Retrieves a todo with the given id from the repository and displays its details.
-
#mark_todo_as_completed(todo : Todo) : Todo
Marks the given todo as completed and displays the completed todo.
- #output_port : TodoOutputPort
- #output_port=(output_port : TodoOutputPort)
- #repository : TodoRepository
- #repository=(repository : TodoRepository)
Constructor Detail
Initializes a new instance of the TodoService class.
@param repository [TodoRepository] An instance of the TodoRepository class that provides methods for accessing and manipulating todos. @param output_port [TodoOutputPort] An instance of the TodoOutputPort class that provides methods for displaying todos.
Instance Method Detail
Retrieves all todos from the repository and displays them.
@return [Array(Todo)] An array of Todo objects representing all the todos retrieved from the repository.
Creates a new todo with the given title, saves it to the repository, and displays the created todo.
@param title [String] The title of the new todo. @return [Todo] A Todo object representing the newly created todo.
Retrieves a todo with the given id from the repository and displays its details.
@param id [String] The id of the todo to retrieve. @return [Todo?] A Todo object representing the todo with the given id, or nil if no todo is found.
Marks the given todo as completed and displays the completed todo.
@param todo [Todo] The todo to mark as completed. @return [Todo] A Todo object representing the todo that was marked as completed.