app/controllers/int_api/marketplaces_controller.rb
# Creates a marketplace and an admin user for that marketplace
Creates a marketplace and an admin user for that marketplace
Creates a marketplace and an admin user for that marketplace
def create
    form = NewMarketplaceForm.new(params)
    return render status: 400, json: form.errors unless form.valid?
    ApplicationHelper.store_community_service_name_to_thread(APP_CONFIG.global_service_name)
    marketplace = MarketplaceService::API::Marketplaces.create(
      params.slice(:marketplace_name,
                   :marketplace_type,
                   :marketplace_country,
                   :marketplace_language).merge(paypal_enabled: true)
      )
    user = UserService::API::Users.create_user_with_membership({
        given_name: params[:admin_first_name],
        family_name: params[:admin_last_name],
        email: params[:admin_email],
        password: params[:admin_password],
        locale: params[:marketplace_language]},
      marketplace[:id])
    auth_token = UserService::API::AuthTokens.create_login_token(user[:id])
    url = URLUtils.append_query_param(marketplace[:url], "auth", auth_token[:token])
    render status: 201, json: {"marketplace_url" => url}
  end
def create form = NewMarketplaceForm . new ( params ) return render status : 400 , json : form . errors unless form . valid? ApplicationHelper . store_community_service_name_to_thread ( APP_CONFIG . global_service_name ) marketplace = MarketplaceService :: API :: Marketplaces . create ( params . slice ( :marketplace_name , :marketplace_type , :marketplace_country , :marketplace_language ) . merge ( paypal_enabled : true ) ) user = UserService :: API :: Users . create_user_with_membership ( { given_name : params [ :admin_first_name ] , family_name : params [ :admin_last_name ] , email : params [ :admin_email ] , password : params [ :admin_password ] , locale : params [ :marketplace_language ] } , marketplace [ :id ] ) auth_token = UserService :: API :: AuthTokens . create_login_token ( user [ :id ] ) url = URLUtils . append_query_param ( marketplace [ :url ] , "auth" , auth_token [ :token ] ) render status : 201 , json : { "marketplace_url" => url } end
Creates a marketplace and an admin user for that marketplace
Creates a marketplace and an admin user for that marketplace
# As there's no community yet, we store the global service name to thread # so that mail confirmation email is sent from global service name instead # of the just created marketplace's name # TODO Add user to mailchimp list # TODO handle error cases with proper response