I have made a function that returns data for required users from the database, I have made an application that is similar to Tinder where the user comes, sees, and swipes their profile, now the problem I am facing is,
the one user-4714(Test) swipe right to user-4713(Test1) Nothing happens all work, now when the user-4713(Test1) swipe right to user-4714(Test) now the second user(test1) able to see the first user(test)
but first user(test1) not able to see the second user(Test),
I have a table in the database which is to store matches between users, in which data is stored as
ID user_one_id user_one_id
6578 4713 4714
The below code is from my Matched_match.ex file,
def list_matches_without_conversations(user_id) do
queryString = "SELECT * FROM (" <>
"SELECT m.*, count(cm.id) AS messages_count FROM matches AS m " <>
"LEFT JOIN chat_messages AS cm ON ((sender_id = user_one_id AND receiver_id = user_two_id) OR (sender_id = user_two_id AND receiver_id = user_one_id)) " <>
"GROUP BY m.id " <>
"ORDER BY m.inserted_at DESC" <>
") AS matches " <>
"WHERE messages_count = 0 "<>
"AND (user_one_id = $1 OR user_two_id = $1) "<>
"AND NOT (user_one_id = ANY($2::integer[])) " <>
"AND NOT (user_two_id = ANY($2::integer[]))"
blocked_ids = WS2.Accounts.get_blocked_user_ids(user_id)
blocked_ids = blocked_ids ++ [-1]
result = WS2.Repo.query!(queryString, [user_id, blocked_ids])
Enum.map(result.rows, fn(e) -> Repo.load(WS2.Matches.Match, {result.columns, e}) end)
|> preload_base_match()
|> Enum.filter(fn (m) -> m.user_one_id != m.user_two_id end)
|> Enum.map(fn (m) ->
user = [m.user_one, m.user_two]
|> Enum.find(&(&1.id != user_id))
Map.put(m ,:user_one, user)
end)
end
My match_controller.ex file code is:
def list(conn, _) do
user = Guardian.Plug.current_resource(conn)
matches = Matches.list_matches_without_conversations(user.id)
render(conn, "list.json", matches: matches)
end
now when I login from user-4713(Test1) then I am able to see user-4714(Test) but when I login from user-4714(Test) I am not able to see user-4713(Test1) .
as I need information of user-4713(Test1) when I login from user-4714(Test) account but I got the information about user-4714(Test) user.