Skip to content

Commit

Permalink
Add profile id to some entities
Browse files Browse the repository at this point in the history
  • Loading branch information
renatolond committed Nov 22, 2024
1 parent 3be0c3e commit a8ff692
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/api/entities/basic_profile_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Entities
# Represents the profile info entity for the API
class BasicProfileInfo < Grape::Entity
format_with(:iso_timestamp) { |date| date&.iso8601 }
expose :id, documentation: { type: String }
expose :display_name, documentation: { type: String }
expose :created_at, format_with: :iso_timestamp, documentation: { type: String }
end
Expand Down
1 change: 1 addition & 0 deletions app/api/entities/profile_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module API
module Entities
# Represents the profile info entity for the API
class ProfileInfo < BasicProfileInfo
expose :id, documentation: { type: String }
expose :birth_date, documentation: { type: Date }
expose :about_me, documentation: { type: String }
expose :genders, documentation: { type: String, is_array: true }
Expand Down
4 changes: 2 additions & 2 deletions app/persistence/repository/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def profile_info(id:)
# Returns basic profile information for a given account
#
# @param account_id (see .profile_id_from_account_id)
# @return [Hash{Symbol => Object}] A record containing +account_id+, +created_at+ and +display_name+
# @return [Hash{Symbol => Object}] A record containing +profile_id+, +created_at+ and +display_name+
def basic_profile_info(account_id:)
profiles.where(account_id:).select(:created_at, :display_name, :account_id).first
profiles.where(account_id:).select(:created_at, :display_name, :id).first
end

# Updates the profile information for a given account
Expand Down
8 changes: 5 additions & 3 deletions app/persistence/repository/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ def insert_message(conversation_id:, profile_id:, content:)
# @param profile_id (see .insert_message)
# @return [Array<Hash>]
def find_conversations(profile_id:)
profile1_query = conversations.where(profile1_id: profile_id)
profile2_query = conversations.where(profile2_id: profile_id)

# TODO: (renatolond, 2024-11-20) I think this needs an index to support this query, look into it
conversations.where(profile1_id: profile_id)
.union(conversations.where(profile2_id: profile_id), from_self: false)
.to_a
profile1_query.union(profile2_query, from_self: false)
.to_a
end

# Returns the last 20 messages from a conversation
Expand Down
3 changes: 2 additions & 1 deletion test/app/api/authenticated/profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

it "has the information expected" do
expected_response = { display_name: "Foo", created_at: Time.new(2024, 9, 20, 16, 50, 0) }
expected_response = { id: @account.profile.id, display_name: "Foo", created_at: Time.new(2024, 9, 20, 16, 50, 0) }
authorized_get @auth, "/api/profile/info"

assert_predicate last_response, :ok?
Expand All @@ -33,6 +33,7 @@
it "gets the user information" do
profile = @account.profile
expected_response = {
id: profile.id,
about_me: profile.about_me,
created_at: profile.created_at.iso8601,
birth_date: profile.birth_date.to_s,
Expand Down

0 comments on commit a8ff692

Please sign in to comment.