How to create a like action?

You have a :like action, and so how you call it in code can’t and won’t affect how the JSON:API behaves (which is why Ash is the way that it is).

There are three ways to call this like action in code, one of which is no longer available in 3.0. AshJsonApi will be unaffected by your choice here. You should choose #1, but I’m including 2 & 3 informationally.

  1. You can define a code interface function as @joelpaulkoch says. This is the recommended approach. For this, you’d define something like this:
define :like, args: [:sender_id, :receiver_id]

and call it like YourResource.like(sender_id, receiver_id).

NOTE: In 3.0 this can be done in one additional way, where you define the code interface on the domain. It’s not relevant here, see the upgrade guide for more.

  1. You can build a changeset and then call YourApi.create not YourApi.Resource.create. This is deprecated in 3.0

  2. You can build a changeset and then call Ash.create. However, this only works if you have configured an api when using the resource, i.e use Ash.Resource, api: Api. (because we have to know the api). This is essentially a compatibility feature to make upgrading to 3.0. Don’t bother with it right now. When you are interested in upgrading to 3.0, the upgrade guide will explain how to make this change.