From 659cc92c5b4906f207d51127c7141c6fa9c07eca Mon Sep 17 00:00:00 2001 From: "Renato \"Lond\" Cerqueira" Date: Fri, 25 Oct 2024 16:52:02 +0200 Subject: [PATCH] Accept all fields, convert needed fields in profile edit --- app/api/authenticated/profile.rb | 18 +++++- app/persistence/repository/account.rb | 90 +++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/app/api/authenticated/profile.rb b/app/api/authenticated/profile.rb index d65b81c..1546511 100644 --- a/app/api/authenticated/profile.rb +++ b/app/api/authenticated/profile.rb @@ -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) diff --git a/app/persistence/repository/account.rb b/app/persistence/repository/account.rb index 13ac9e5..5bdced8 100644 --- a/app/persistence/repository/account.rb +++ b/app/persistence/repository/account.rb @@ -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 # @@ -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