summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/model/Competitor.cpp15
-rw-r--r--src/model/Competitor.h39
-rw-r--r--src/model/CompetitorWithResults.cpp15
-rw-r--r--src/model/CompetitorWithResults.h28
-rw-r--r--src/model/MedalWinner.cpp18
-rw-r--r--src/model/MedalWinner.h35
-rw-r--r--src/model/Sport.cpp (renamed from src/discipline/Sport.cpp)0
-rw-r--r--src/model/Sport.h (renamed from src/discipline/Sport.h)0
8 files changed, 150 insertions, 0 deletions
diff --git a/src/model/Competitor.cpp b/src/model/Competitor.cpp
new file mode 100644
index 0000000..a5d2e69
--- /dev/null
+++ b/src/model/Competitor.cpp
@@ -0,0 +1,15 @@
+
+#include "Competitor.h"
+
+bool Competitor::setCompetitor(const QJsonObject &competitor) {
+ if (!competitor.contains("code")
+ || !competitor.contains("name")
+ || !competitor.contains("noc")) {
+ throw invalid_argument("Not a competitor object.");
+ }
+
+ this->code = competitor["code"].toString();
+ this->name = competitor["name"].toString();
+ this->noc = competitor["noc"].toString();
+ return true;
+}
diff --git a/src/model/Competitor.h b/src/model/Competitor.h
new file mode 100644
index 0000000..919c2fa
--- /dev/null
+++ b/src/model/Competitor.h
@@ -0,0 +1,39 @@
+
+#ifndef ITAT_CHALLANGE_OLYMPICS_COMPETITOR_H
+#define ITAT_CHALLANGE_OLYMPICS_COMPETITOR_H
+
+#include <QString>
+#include <QMap>
+#include <QJsonObject>
+#include <stdexcept>
+
+using namespace std;
+
+class Competitor {
+
+public:
+ Competitor(const Competitor &competitor) {
+ this->code = competitor.code;
+ this->name = competitor.name;
+ this->noc = competitor.noc;
+ }
+
+ Competitor(const QJsonObject &competitor) {
+ setCompetitor(competitor);
+ }
+
+ QString getCode() { return this->code; }
+ QString getName() { return this->name; }
+ QString getNOC() { return this->noc; }
+
+ bool setCompetitor(const QJsonObject &competitor);
+
+private:
+ QString code;
+ QString name;
+ QString noc;
+
+};
+
+
+#endif //ITAT_CHALLANGE_OLYMPICS_COMPETITOR_H
diff --git a/src/model/CompetitorWithResults.cpp b/src/model/CompetitorWithResults.cpp
new file mode 100644
index 0000000..d29441d
--- /dev/null
+++ b/src/model/CompetitorWithResults.cpp
@@ -0,0 +1,15 @@
+
+#include "CompetitorWithResults.h"
+
+bool CompetitorWithResults::setResults(const QJsonObject &results) {
+ if (!results.contains("mark")
+ || !results.contains("medalType")) {
+ throw invalid_argument("Results object of competitor is incomplete.");
+ }
+
+ this->results = {
+ {QString("mark"), results["mark"].toString()},
+ {QString("medalType"), results["medalType"].toString()}
+ };
+ return true;
+}
diff --git a/src/model/CompetitorWithResults.h b/src/model/CompetitorWithResults.h
new file mode 100644
index 0000000..cb952f2
--- /dev/null
+++ b/src/model/CompetitorWithResults.h
@@ -0,0 +1,28 @@
+
+#ifndef ITAT_CHALLANGE_OLYMPICS_COMPETITORWITHRESULTS_H
+#define ITAT_CHALLANGE_OLYMPICS_COMPETITORWITHRESULTS_H
+
+#include "Competitor.h"
+#include <QString>
+#include <QMap>
+#include <QJsonObject>
+#include <stdexcept>
+
+class CompetitorWithResults : public Competitor {
+
+public:
+ CompetitorWithResults(const QJsonObject &competitor) : Competitor(competitor) {
+ if (!competitor.contains("results")) throw invalid_argument("Competitor does not contain results.");
+ QJsonObject results = competitor["results"].toObject();
+ setResults(results);
+ }
+
+ bool setResults(const QJsonObject &results);
+
+private:
+ QMap<QString, QString> results;
+
+};
+
+
+#endif //ITAT_CHALLANGE_OLYMPICS_COMPETITORWITHRESULTS_H
diff --git a/src/model/MedalWinner.cpp b/src/model/MedalWinner.cpp
new file mode 100644
index 0000000..c4cb663
--- /dev/null
+++ b/src/model/MedalWinner.cpp
@@ -0,0 +1,18 @@
+
+#include "MedalWinner.h"
+
+bool MedalWinner::setMedals(const QJsonObject &medals) {
+ if (!medals.contains("ME_GOLD")
+ || !medals.contains("ME_SILVER")
+ || !medals.contains("ME_BRONZE")) {
+ throw invalid_argument("Medal object of competitor is incomplete.");
+ }
+
+ this->wonMedals = {
+ {QString("ME_GOLD"), medals["ME_GOLD"].toString()},
+ {QString("ME_SILVER"), medals["ME_SILVER"].toString()},
+ {QString("ME_BRONZE"), medals["ME_BRONZE"].toString()}
+ };
+
+ return true;
+}
diff --git a/src/model/MedalWinner.h b/src/model/MedalWinner.h
new file mode 100644
index 0000000..e771185
--- /dev/null
+++ b/src/model/MedalWinner.h
@@ -0,0 +1,35 @@
+
+#ifndef ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H
+#define ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H
+
+#include "Competitor.h"
+#include <QMap>
+#include <QJsonObject>
+#include <stdexcept>
+
+class MedalWinner : public Competitor {
+
+public:
+ MedalWinner(const MedalWinner &medalWinner) : Competitor(medalWinner) {
+ this->wonMedals = {
+ {QString("ME_GOLD"), medalWinner.wonMedals.value("ME_GOLD")},
+ {QString("ME_SILVER"), medalWinner.wonMedals.value("ME_SILVER")},
+ {QString("ME_BRONZE"), medalWinner.wonMedals.value("ME_BRONZE")}
+ };
+ }
+
+ MedalWinner(const QJsonObject &competitor) : Competitor(competitor) {
+ if (competitor.contains("medals")) throw invalid_argument("Competitor has no medals.");
+ QJsonObject medals = competitor["medals"].toObject();
+ setMedals(medals);
+ }
+
+ bool setMedals(const QJsonObject &medals);
+
+private:
+ QMap<QString, QString> wonMedals;
+
+};
+
+
+#endif //ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H
diff --git a/src/discipline/Sport.cpp b/src/model/Sport.cpp
index 21b9b9f..21b9b9f 100644
--- a/src/discipline/Sport.cpp
+++ b/src/model/Sport.cpp
diff --git a/src/discipline/Sport.h b/src/model/Sport.h
index 147f6e8..147f6e8 100644
--- a/src/discipline/Sport.h
+++ b/src/model/Sport.h