Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaddeusJiang committed Oct 25, 2024
1 parent 625fdfd commit 256dde8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 53 deletions.
14 changes: 7 additions & 7 deletions lib/migration/typesense.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
defmodule Migration.Typesense do
def list_collections() do
req = build_request("/collections")
{:ok, res} = Req.get(req)

res.body
end

def create_collection!(schema) do
req = build_request("/collections")
{:ok, res} = Req.post(req, json: schema)
Expand All @@ -20,6 +13,13 @@ defmodule Migration.Typesense do
res.body
end

def list_collections() do
req = build_request("/collections")
{:ok, res} = Req.get(req)

res.body
end

defp get_env() do
url = Application.fetch_env!(:save_it, :typesense_url)
api_key = Application.fetch_env!(:save_it, :typesense_api_key)
Expand Down
20 changes: 10 additions & 10 deletions lib/save_it/bot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule SaveIt.Bot do
alias SaveIt.GoogleDrive
alias SaveIt.GoogleOAuth2DeviceFlow

alias SaveIt.TypesensePhoto
alias SaveIt.PhotoService

alias SaveIt.NoteService

Expand Down Expand Up @@ -131,7 +131,7 @@ defmodule SaveIt.Bot do
send_message(chat.id, "What do you want to search? animal, food, etc.")

_ ->
photos = TypesensePhoto.search_photos!(q, belongs_to_id: chat.id)
photos = PhotoService.search_photos!(q, belongs_to_id: chat.id)

answer_photos(chat.id, photos)
end
Expand All @@ -142,7 +142,7 @@ defmodule SaveIt.Bot do
# end

def handle(
{:command, :note, %{chat: chat, text: text, reply_to_message: reply_to_message}} = msg,
{:command, :note, %{chat: chat, text: text, reply_to_message: reply_to_message}},
_context
)
when is_binary(text) do
Expand All @@ -161,7 +161,7 @@ defmodule SaveIt.Bot do

note_content ->
# photo_url = photo_url(chat.id, file_id)
# TypesensePhoto.update_photo!(photo_url, %{"note" => text})
# PhotoService.update_photo!(photo_url, %{"note" => text})

note =
NoteService.create_note!(%{
Expand Down Expand Up @@ -197,15 +197,15 @@ defmodule SaveIt.Bot do
chat_id = chat.id

typesense_photo =
TypesensePhoto.create_photo!(%{
PhotoService.create_photo!(%{
image: Base.encode64(photo_file_content),
caption: "",
url: photo_url(bot_id, file.file_id),
belongs_to_id: chat_id
})

photos =
TypesensePhoto.search_similar_photos!(
PhotoService.search_similar_photos!(
typesense_photo["id"],
distance_threshold: 0.1,
belongs_to_id: chat_id
Expand Down Expand Up @@ -235,7 +235,7 @@ defmodule SaveIt.Bot do
end

typesense_photo =
TypesensePhoto.create_photo!(%{
PhotoService.create_photo!(%{
image: Base.encode64(photo_file_content),
caption: caption,
url: photo_url(bot_id, file.file_id),
Expand All @@ -245,7 +245,7 @@ defmodule SaveIt.Bot do
case caption do
"" ->
photos =
TypesensePhoto.search_similar_photos!(
PhotoService.search_similar_photos!(
typesense_photo["id"],
distance_threshold: 0.4,
belongs_to_id: chat_id
Expand All @@ -255,7 +255,7 @@ defmodule SaveIt.Bot do

_ ->
photos =
TypesensePhoto.search_similar_photos!(
PhotoService.search_similar_photos!(
typesense_photo["id"],
distance_threshold: 0.1,
belongs_to_id: chat_id
Expand Down Expand Up @@ -483,7 +483,7 @@ defmodule SaveIt.Bot do
{:file_content, file_content, _file_name} -> Base.encode64(file_content)
end

TypesensePhoto.create_photo!(%{
PhotoService.create_photo!(%{
image: image_base64,
caption: file_name,
url: photo_url(bot_id, file_id),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule SaveIt.TypesensePhoto do
defmodule SaveIt.PhotoService do
require Logger
alias SmallSdk.Typesense

Expand Down
35 changes: 0 additions & 35 deletions lib/small_sdk/typesense_admin.ex

This file was deleted.

0 comments on commit 256dde8

Please sign in to comment.