summaryrefslogtreecommitdiff
path: root/src/discipline/Sport.cpp
diff options
context:
space:
mode:
authorSteru <jerrydream111@gmail.com>2024-08-02 16:07:15 +0200
committerSteru <jerrydream111@gmail.com>2024-08-02 16:07:15 +0200
commita767d83d81755710fc760a6d3dc040b4a379c16a (patch)
tree131b23f31e7b25f7106b2a51da99090985038891 /src/discipline/Sport.cpp
parentab7280aa471346374520eca3ca8c50742e70510f (diff)
Extracted API call in seperate class. Started class to handle data and filter (Sport).
Diffstat (limited to 'src/discipline/Sport.cpp')
-rw-r--r--src/discipline/Sport.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/discipline/Sport.cpp b/src/discipline/Sport.cpp
new file mode 100644
index 0000000..ed8331d
--- /dev/null
+++ b/src/discipline/Sport.cpp
@@ -0,0 +1,48 @@
+
+#include "Sport.h"
+#include <set>
+
+#include <QJsonObject>
+#include <QJsonArray>
+#include <QJsonValueRef>
+#include <QString>
+
+
+/**
+ * @brief Sport::getCategories Reads all possible categories (also called units).
+ * @return A set of all category names.
+ */
+set<QString> Sport::getCategories() {
+ set<QString> categoryNames;
+
+ for (const QJsonValueRef& unit : this->discipline["units"].toArray()) {
+ categoryNames.insert(unit.toObject()["eventUnitName"].toString());
+ }
+
+ return categoryNames;
+}
+
+/**
+ * @brief Sport::getCompetitorsByCategory Searches for all competitors, who took part in the given category.
+ * @param category The category to search in.
+ * @return An QJsonArray with all competitors as QJsonValueRef, which can be casted to QJsonObject.
+ */
+QJsonArray Sport::getCompetitorsByCategory(QString category) {
+ QJsonArray competitors;
+
+ for (const QJsonValueRef& unitRef : this->discipline["units"].toArray()) {
+ QJsonObject unit = unitRef.toObject();
+
+ // search all units with the same category
+ if (QString::compare(unit["eventUnitName"].toString(), category, Qt::CaseSensitive) == 0) {
+
+ // add all competitors from one unit
+ for (const QJsonValueRef& comp : unit["competitors"].toArray()) {
+ competitors.push_back(comp.toObject());
+ }
+
+ }
+ }
+
+ return competitors;
+}