2019-05-22 15:44:50 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-05-22 15:44:50 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.OAuth.Token.Query do
|
|
|
|
@moduledoc """
|
|
|
|
Contains queries for OAuth Token.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import Ecto.Query, only: [from: 2]
|
|
|
|
|
|
|
|
@type query :: Ecto.Queryable.t() | Token.t()
|
|
|
|
|
|
|
|
alias Pleroma.Web.OAuth.Token
|
|
|
|
|
|
|
|
@spec get_by_refresh_token(query, String.t()) :: query
|
|
|
|
def get_by_refresh_token(query \\ Token, refresh_token) do
|
|
|
|
from(q in query, where: q.refresh_token == ^refresh_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec get_by_token(query, String.t()) :: query
|
|
|
|
def get_by_token(query \\ Token, token) do
|
|
|
|
from(q in query, where: q.token == ^token)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec get_by_app(query, String.t()) :: query
|
|
|
|
def get_by_app(query \\ Token, app_id) do
|
2022-08-21 15:22:15 +00:00
|
|
|
from(q in query, where: q.app_id == ^app_id)
|
2019-05-22 15:44:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@spec get_by_id(query, String.t()) :: query
|
|
|
|
def get_by_id(query \\ Token, id) do
|
|
|
|
from(q in query, where: q.id == ^id)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec get_by_user(query, String.t()) :: query
|
|
|
|
def get_by_user(query \\ Token, user_id) do
|
|
|
|
from(q in query, where: q.user_id == ^user_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec preload(query, any) :: query
|
|
|
|
def preload(query \\ Token, assoc_preload \\ [])
|
|
|
|
|
|
|
|
def preload(query, assoc_preload) when is_list(assoc_preload) do
|
|
|
|
from(q in query, preload: ^assoc_preload)
|
|
|
|
end
|
|
|
|
|
|
|
|
def preload(query, _assoc_preload), do: query
|
|
|
|
end
|