Skip to content

Commit

Permalink
Accept all fields, convert needed fields in profile edit
Browse files Browse the repository at this point in the history
  • Loading branch information
renatolond committed Oct 25, 2024
1 parent 53a4ce0 commit 659cc92
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/api/authenticated/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,25 @@ class Profile < Grape::API
consumes: Authenticated::CONSUMES
params do
optional :about_me, type: String, desc: "The about me text for the profile"
optional :display_name, type: String, desc: "The name that is displayed for other users"
optional :genders, type: [String], values: Persistence::Repository::Account::GENDER_VALUES
optional :orientations, type: [String], values: Persistence::Repository::Account::ORIENTATION_VALUES
optional :languages, type: [String], values: Persistence::Repository::Account::LANGUAGE_VALUES
optional :relationship_type, type: String, values: Persistence::Repository::Account::RELATIONSHIP_TYPE_VALUES
optional :relationship_status, type: String, values: Persistence::Repository::Account::RELATIONSHIP_STATUS_VALUES
optional :religion, type: String, values: Persistence::Repository::Account::RELIGION_VALUES
optional :religion_importance, type: String, values: Persistence::Repository::Account::IMPORTANCE_VALUES
optional :tobacco, type: String, values: Persistence::Repository::Account::FREQUENCY_VALUES
optional :marijuana, type: String, values: Persistence::Repository::Account::FREQUENCY_VALUES
optional :alcohol, type: String, values: Persistence::Repository::Account::FREQUENCY_VALUES
optional :other_recreational_drugs, type: String, values: Persistence::Repository::Account::FREQUENCY_VALUES
optional :kids, type: String, values: Persistence::Repository::Account::HAVES_OR_HAVE_NOTS_VALUES
optional :wants_kids, type: String, values: Persistence::Repository::Account::WANTS_VALUES
optional :pets, type: String, values: Persistence::Repository::Account::HAVES_OR_HAVE_NOTS_VALUES
optional :wants_pets, type: String, values: Persistence::Repository::Account::WANTS_VALUES
end
post :complete do
Persistence::Repository::Account.update_profile_info(account_id: rodauth.session[:account_id], **declared(params))
Persistence::Repository::Account.update_profile_info(account_id: rodauth.session[:account_id], **declared(params, include_missing: false))
profile_info = Persistence::Repository::Account.profile_info(account_id: rodauth.session[:account_id])
status :ok
Entities::ProfileInfo.represent(profile_info)
Expand Down
90 changes: 90 additions & 0 deletions app/persistence/repository/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,93 @@ module Persistence
module Repository
# Contains database logic around accounts
module Account
GENDER_VALUES = %w[
man
woman
non_binary
genderqueer
genderfluid
gender_non_conforming
transgender
trans_man
transmasculine
trans_woman
transfeminine
transsexual
agender
bigender
pangender
two_spirit
intersex
androgynous
questioning
unsure
].freeze

ORIENTATION_VALUES = %w[
straight
bisexual
heteroflexible
homoflexible
gay
lesbian
queer
pansexual
omnisexual
abrosexual
demisexual
asexual
greysexual
reciprosexual
demiromantic
aromantic
greyromantic
fluid
fluctuating
unsure
questioning
].freeze

LANGUAGE_VALUES = %w[abk aar afr aka sqi amh ara arg hye asm ava ave aym aze bam bak eus bel ben bis bos bre bul mya cat cha che nya zho chu chv cor cos cre hrv ces dan div nld dzo eng epo est ewe fao fij fin fra fry ful gla glg lug kat deu ell kal grn guj hat hau heb her hin hmo hun isl ido ibo ind ina ile iku ipk gle ita jpn jav kan kau kas kaz khm kik kin kir kom kon kor kua kur lao lat lav lim lin lit lub ltz mkd mlg msa mal mlt glv mri mar mah mon nau nav nde nbl ndo nep nor nob nno oci oji ori orm oss pli pus fas pol por pan que ron roh run rus sme smo sag san srd srp sna snd sin slk slv som sot spa sun swa ssw swe tgl tah tgk tam tat tel tha bod tir ton tso tsn tur tuk twi uig ukr urd uzb ven vie vol wln cym wol xho iii yid yor zha zul].freeze

RELATIONSHIP_TYPE_VALUES = %w[monogamous non_monogamous].freeze

RELATIONSHIP_STATUS_VALUES = %w[single partnered married].freeze

FREQUENCY_VALUES = %w[never sometimes often].freeze

HAVES_OR_HAVE_NOTS_VALUES = %w[have have_not].freeze

WANTS_VALUES = %w[
want_more
do_not_want_more
want_some
do_not_want_any
dont_know
maybe
].freeze

RELIGION_VALUES = %w[
agnosticism
atheism
buddhism
candomble
catholicism
christianity
hinduism
islam
judaism
rastafari
sikh
spiritism
umbanda
other
].freeze

IMPORTANCE_VALUES = %w[
important not_important do_not_care
].freeze

class << self
# Returns profile information for a given account
#
Expand All @@ -27,6 +114,9 @@ def basic_profile_info(account_id:)
# @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)
args["languages"] = Sequel.pg_array(args["languages"], :languages) if args.key?("languages")
args["genders"] = Sequel.pg_array(args["genders"], :genders) if args.key?("genders")
args["orientations"] = Sequel.pg_array(args["orientations"], :orientations) if args.key?("orientations")
account_informations.where(account_id:).update(args)
end

Expand Down

0 comments on commit 659cc92

Please sign in to comment.