-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first commit * refactor, show photo's caption * refactor, typesense sdk delete_document * refactor * refactor: 💡 handle_response and handle_response! * refactor: 💡 get_env * refactor: 💡 UrlHelper validate_url * chore: 🤖 typesense migration SaveIt.Migration.Typesense.Photo.migrate_photos_2024_10_29!() * refactor * fix: typesense list_documents
- Loading branch information
1 parent
b74c335
commit 4e86a66
Showing
20 changed files
with
471 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 2024-10-25 | ||
|
||
## Req call typesense API alway :timeout, but typesense was updated. | ||
|
||
```elixir | ||
** (MatchError) no match of right hand side value: {:error, %Req.TransportError{reason: :timeout}} | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Typesense | ||
|
||
## Typesense API Errors | ||
|
||
``` | ||
# 400 Bad Request - The request could not be understood due to malformed syntax. | ||
# 401 Unauthorized - Your API key is wrong. | ||
# 404 Not Found - The requested resource is not found. | ||
# 409 Conflict - When a resource already exists. | ||
# 422 Unprocessable Entity - Request is well-formed, but cannot be processed. | ||
# 503 Service Unavailable - We’re temporarily offline. Please try again later. | ||
``` | ||
|
||
docs: https://typesense.org/docs/27.1/api/api-errors.html#api-errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
defmodule SaveIt.Migration.Typesense do | ||
alias SmallSdk.Typesense | ||
|
||
import Tj.UrlHelper, only: [validate_url!: 1] | ||
|
||
def create_collection!(schema) do | ||
req = build_request("/collections") | ||
res = Req.post!(req, json: schema) | ||
|
||
Typesense.handle_response!(res) | ||
end | ||
|
||
def update_collection!(collection_name, schema) do | ||
req = build_request("/collections/#{collection_name}") | ||
res = Req.patch!(req, json: schema) | ||
|
||
Typesense.handle_response!(res) | ||
end | ||
|
||
def list_collections!() do | ||
req = build_request("/collections") | ||
res = Req.get!(req) | ||
|
||
Typesense.handle_response!(res) | ||
end | ||
|
||
def delete_collection!(collection_name) do | ||
req = build_request("/collections/#{collection_name}") | ||
res = Req.delete!(req) | ||
|
||
Typesense.handle_response!(res) | ||
end | ||
|
||
defp get_env() do | ||
url = Application.fetch_env!(:save_it, :typesense_url) |> validate_url!() | ||
|
||
api_key = Application.fetch_env!(:save_it, :typesense_api_key) | ||
|
||
{url, api_key} | ||
end | ||
|
||
defp build_request(path) do | ||
{url, api_key} = get_env() | ||
|
||
Req.new( | ||
base_url: url, | ||
url: path, | ||
headers: [ | ||
{"Content-Type", "application/json"}, | ||
{"X-TYPESENSE-API-KEY", api_key} | ||
] | ||
) | ||
end | ||
end |
Oops, something went wrong.