Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a TODO Api Using Vania Dart #2

Closed
MehediHasannOvi opened this issue Apr 5, 2024 · 1 comment
Closed

Create a TODO Api Using Vania Dart #2

MehediHasannOvi opened this issue Apr 5, 2024 · 1 comment

Comments

@MehediHasannOvi
Copy link

MehediHasannOvi commented Apr 5, 2024

Hello Sir,

I will try to create a todo API using Vania, but I can't I will install Vania on my local computer but I can do it. can you Help me create a todo API ,

i will try this but it's not work

 import 'package:vania/vania.dart' 

class Todo extends Model {
  String title;
  bool completed;

  Todo({this.title, this.completed = false});
}

class TodoController extends ResourceController {
  @Operation.get()
  Future<Response> getAllTodos() async {
    List<Todo> todos = await Todo.query().fetch();
    return Response.ok(todos);
  }

  @Operation.post()
  Future<Response> createTodo() async {
    Todo todo = Todo()..read(await request.body.decode());
    await todo.save();
    return Response.ok(todo);
  }
}

class TodoApiChannel extends ApplicationChannel {
  ManagedContext context;

  @override
  Future prepare() async {
    context = ManagedContext(...); // setup your database connection details here
  }

  @override
  Controller get entryPoint {
    final router = Router();

    router.route('/todos/[:id]')
      .link(() => TodoController());

    return router;
  }
}

Future main() async => runApp(TodoApiChannel());

@javad-zobeidi
Copy link
Owner

The syntax you are using is not Vania syntax, Please check this document

https://vdart.dev

Vania repo
https://github.com/vania-dart/framework

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants