api_return ShareProfileApi::handleAddProfile(ApiRequest& aRequest) {
		const auto& reqJson = aRequest.getRequestBody();

		auto profile = make_shared<ShareProfile>();
		parseProfile(profile, reqJson);

		ShareManager::getInstance()->addProfile(profile);
		return websocketpp::http::status_code::ok;
	}
Example #2
0
// METODO Database::parseUser( QXmlStreamReader& )
void Database::parseUser( QXmlStreamReader& xmlReader ) {
    if( xmlReader.tokenType() != QXmlStreamReader::StartElement &&
        xmlReader.name() != "user" ) {
        qDebug() << "Nessun elemento utente!";
        return;
    }

    Utente* u = 0;
    QString un = xmlReader.attributes().value( "login" ).toString();
    QString type = xmlReader.attributes().value( "type" ).toString();
    if( type == "basic" ) u = new UtenteBasic( un );
    else if( type == "executive" ) u = new UtenteExecutive( un );
    else if( type == "business" ) u = new UtenteBusiness( un );
    else qDebug() << "#"; // throw

    xmlReader.readNext();
    while( xmlReader.name() != "user" ||
           xmlReader.tokenType() != QXmlStreamReader::EndElement ) {
        xmlReader.readNext();
        if( xmlReader.name() == "profile" ) {
            xmlReader.readNext();
            while( xmlReader.name() != "profile" ||
                   xmlReader.tokenType() != QXmlStreamReader::EndElement ) {
                parseProfile( xmlReader, u );
                xmlReader.readNext();
            }
        }

        // L'aggiunta della lista dei contatti รจ necessario farla in un momento successivo,
        // quanto tutti gli utenti presenti nel file XML sono stati aggiunti al database.

        if( xmlReader.name() == "educations" ) {
            xmlReader.readNext();
            while( xmlReader.name() != "educations"
                   || xmlReader.tokenType() != QXmlStreamReader::EndElement ) {
                if( xmlReader.name() == "title" )
                    parseEducation( xmlReader, u );
                xmlReader.readNext();
            }
        }
        if( xmlReader.name() == "experiences" ) {
            xmlReader.readNext();
            while( xmlReader.name() != "experiences"
                   || xmlReader.tokenType() != QXmlStreamReader::EndElement ) {
                if( xmlReader.name() == "job" )
                    parseExperience( xmlReader, u );
                xmlReader.readNext();
            }
        }
    }

    this->insert( u );
}
	api_return ShareProfileApi::handleUpdateProfile(ApiRequest& aRequest) {
		const auto& reqJson = aRequest.getRequestBody();

		auto token = aRequest.getTokenParam(0);
		if (token == SP_HIDDEN) {
			aRequest.setResponseErrorStr("Hidden profile can't be edited");
			return websocketpp::http::status_code::not_found;
		}

		auto profile = ShareManager::getInstance()->getShareProfile(token);
		if (!profile) {
			aRequest.setResponseErrorStr("Profile not found");
			return websocketpp::http::status_code::not_found;
		}

		parseProfile(profile, reqJson);
		ShareManager::getInstance()->updateProfile(profile);
		return websocketpp::http::status_code::ok;
	}