memberships.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "memberships.h"
  2. Memberships::Memberships()
  3. {
  4. }
  5. struct Memberships::membership Memberships::get ( int membership_id )
  6. {
  7. return this->id2membership[membership_id];
  8. }
  9. QList<struct Memberships::membership> Memberships::get_byproject ( int project_id )
  10. {
  11. return this->projectId2membership[project_id];
  12. }
  13. void Memberships::clear()
  14. {
  15. this->projectId2membership.clear();
  16. this->id2membership.clear();
  17. this->list.clear();
  18. }
  19. void Memberships::add ( QJsonObject json_membership )
  20. {
  21. struct membership membership;
  22. membership.id = json_membership["id"].toInt();
  23. membership.project_id = json_membership["project"].toObject() ["id"].toInt();
  24. membership.user_id = json_membership["user"] .toObject() ["id"].toInt();
  25. membership.user_name = json_membership["user"] .toObject() ["name"].toString();
  26. QJsonArray json_roles = json_membership["roles"].toArray();
  27. membership.roles.clear();
  28. foreach ( const QJsonValue & role_val, json_roles ) {
  29. QJsonObject role = role_val.toObject();
  30. struct membership_role membership_role;
  31. membership_role.role_id = role["id"] .toInt();
  32. membership_role.isInherited = role["inherited"].toBool();
  33. membership.roles.append ( membership_role );
  34. }
  35. this->list.append ( membership );
  36. this->id2membership.insert ( membership.id, membership );
  37. this->projectId2membership[membership.project_id].append ( membership );
  38. }
  39. void Memberships::set ( QJsonArray json_array )
  40. {
  41. this->clear();
  42. foreach ( const QJsonValue & val, json_array )
  43. this->add ( val.toObject() );
  44. }