Add user and profession entity
This commit is contained in:
parent
170a24670d
commit
f41052337c
7 changed files with 222 additions and 10 deletions
32
iFacility/objects/profession.cpp
Normal file
32
iFacility/objects/profession.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "profession.h"
|
||||
|
||||
QString Profession::title() const {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
PID Profession::pID() const {
|
||||
return mPID;
|
||||
}
|
||||
|
||||
Profession Profession::createProfession(const QString &title) {
|
||||
Profession p;
|
||||
|
||||
p.mPID = QUuid::createUuid();
|
||||
p.mTitle = title;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
bool operator==(const Profession &l, const Profession &r) {
|
||||
return l.mPID == r.mPID;
|
||||
}
|
||||
|
||||
QDataStream& operator<<(QDataStream &stream, const Profession &prof) {
|
||||
stream << prof.mPID << prof.mTitle;
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream &stream, Profession &prof) {
|
||||
stream >> prof.mPID >> prof.mTitle;
|
||||
return stream;
|
||||
}
|
||||
28
iFacility/objects/profession.h
Normal file
28
iFacility/objects/profession.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef PROFESSION_H
|
||||
#define PROFESSION_H
|
||||
|
||||
#include <QString>
|
||||
#include <QUuid>
|
||||
#include <QDataStream>
|
||||
|
||||
typedef QUuid PID;
|
||||
|
||||
class Profession {
|
||||
private:
|
||||
PID mPID;
|
||||
QString mTitle;
|
||||
|
||||
Profession() = default;
|
||||
|
||||
public:
|
||||
QString title() const;
|
||||
PID pID() const;
|
||||
|
||||
static Profession createProfession(const QString &title);
|
||||
|
||||
friend bool operator==(const Profession &l, const Profession &r);
|
||||
friend QDataStream& operator<<(QDataStream &stream, const Profession &prof);
|
||||
friend QDataStream& operator>>(QDataStream &stream, Profession &prof);
|
||||
};
|
||||
|
||||
#endif // PROFESSION_H
|
||||
78
iFacility/objects/user.cpp
Normal file
78
iFacility/objects/user.cpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include "user.h"
|
||||
|
||||
UID User::uID() const {
|
||||
return mUID;
|
||||
}
|
||||
|
||||
QString User::getLogin() const {
|
||||
return mLogin;
|
||||
}
|
||||
|
||||
bool User::checkPassword(const QString &password) {
|
||||
return mPassword == password;
|
||||
}
|
||||
|
||||
QString User::firstName() const {
|
||||
return mFirstName;
|
||||
}
|
||||
|
||||
QString User::secondName() const {
|
||||
return mSecondName;
|
||||
}
|
||||
|
||||
QString User::patronymic() const {
|
||||
return mPatronymic;
|
||||
}
|
||||
|
||||
ProfessionsList User::getProfessions() const {
|
||||
return mProfessions;
|
||||
}
|
||||
|
||||
PID User::getCurrentProfession() const {
|
||||
return mCurrentProfession;
|
||||
}
|
||||
|
||||
User User::createUser(QString login, QString password,
|
||||
QString firstName, QString secondName, QString patronymic) {
|
||||
User u;
|
||||
|
||||
u.mUID = QUuid::createUuid();
|
||||
u.mLogin = login;
|
||||
u.mPassword = password;
|
||||
u.mFirstName = firstName;
|
||||
u.mSecondName = secondName;
|
||||
u.mPatronymic = patronymic;
|
||||
|
||||
return u;
|
||||
}
|
||||
|
||||
bool User::addProfession(const Profession &p) {
|
||||
if (p.pID() == mCurrentProfession) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mProfessions.contains(p)) {
|
||||
if (mProfessions.size() >= 4) {
|
||||
mProfessions.remove(0);
|
||||
}
|
||||
mProfessions.push_back(p);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool User::setCurrentProfession(const Profession &p) {
|
||||
if (!mProfessions.contains(p)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (p.pID() != mCurrentProfession) {
|
||||
mCurrentProfession = p.pID();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void User::removeProfession(const Profession &p) {
|
||||
mProfessions.removeAll(p);
|
||||
}
|
||||
44
iFacility/objects/user.h
Normal file
44
iFacility/objects/user.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QUuid>
|
||||
#include <QVector>
|
||||
|
||||
#include "profession.h"
|
||||
|
||||
typedef QUuid UID;
|
||||
typedef QVector<Profession> ProfessionsList;
|
||||
|
||||
class User {
|
||||
private:
|
||||
UID mUID;
|
||||
QString mLogin;
|
||||
QString mPassword;
|
||||
QString mFirstName;
|
||||
QString mSecondName;
|
||||
QString mPatronymic;
|
||||
ProfessionsList mProfessions;
|
||||
PID mCurrentProfession = 0;
|
||||
|
||||
User() = default;
|
||||
|
||||
public:
|
||||
UID uID() const;
|
||||
QString getLogin() const;
|
||||
bool checkPassword(const QString &password);
|
||||
QString firstName() const;
|
||||
QString secondName() const;
|
||||
QString patronymic() const;
|
||||
ProfessionsList getProfessions() const;
|
||||
PID getCurrentProfession() const;
|
||||
|
||||
static User createUser(QString login, QString password,
|
||||
QString firstName, QString secondName, QString patronymic);
|
||||
|
||||
bool addProfession(const Profession &p);
|
||||
bool setCurrentProfession(const Profession &p);
|
||||
void removeProfession(const Profession &p);
|
||||
};
|
||||
|
||||
#endif // USER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue