Skip to content

Commit

Permalink
WIP profile edit, creates endpoint and accepts one param
Browse files Browse the repository at this point in the history
  • Loading branch information
renatolond committed Oct 24, 2024
1 parent b1a1869 commit 53a4ce0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/api/authenticated/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ class Profile < Grape::API
profile_info = Persistence::Repository::Account.profile_info(account_id: rodauth.session[:account_id])
Entities::ProfileInfo.represent(profile_info)
end

desc "Updates the current user's profile with the given parameters.",
success: { model: API::Entities::ProfileInfo, message: "The profile for the authenticated user" },
failure: Authenticated::FAILURES,
produces: Authenticated::PRODUCES,
consumes: Authenticated::CONSUMES
params do
optional :about_me, type: String, desc: "The about me text for the profile"
end
post :complete do
Persistence::Repository::Account.update_profile_info(account_id: rodauth.session[:account_id], **declared(params))
profile_info = Persistence::Repository::Account.profile_info(account_id: rodauth.session[:account_id])
status :ok
Entities::ProfileInfo.represent(profile_info)
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions app/persistence/repository/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def basic_profile_info(account_id:)
account_informations.where(account_id:).select(:created_at, :display_name, :account_id).first
end

# Updates the profile information for a given account
# Does not validate argument names passed to +args+, so if not validated before-hand can raise an exception
# @param account_id (see #profile_info)
# @param args [Hash{Symbol => Object}] A hash containing the fields to be updated. Will not be verified for validity.
# @return [void]
def update_profile_info(account_id:, **args)
account_informations.where(account_id:).update(args)
end

private

# @return [Sequel::Postgres::Dataset]
Expand Down

0 comments on commit 53a4ce0

Please sign in to comment.