mirai/external/mirai-core/src/Event.cpp

72 lines
1.3 KiB
C++
Raw Normal View History

2024-08-16 21:35:12 +02:00
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#include "Event.h"
2024-10-11 16:26:13 +02:00
#include "Task.h"
#include <string>
2024-08-16 21:35:12 +02:00
namespace mirai
{
2024-10-11 16:26:13 +02:00
int Event::id() const
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
return eventData_.id;
2024-08-16 21:35:12 +02:00
}
2024-10-11 16:26:13 +02:00
int Event::sourceId() const
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
return data_->id;
2024-08-16 21:35:12 +02:00
}
2024-10-11 16:26:13 +02:00
std::string Event::title() const
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
return eventData_.title;
2024-08-16 21:35:12 +02:00
}
2024-10-11 16:26:13 +02:00
Time Event::startsAt() const
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
return eventData_.startsAt;
2024-08-16 21:35:12 +02:00
}
2024-10-11 16:26:13 +02:00
Time Event::endsAt() const
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
return eventData_.endsAt;
2024-08-16 21:35:12 +02:00
}
2024-10-11 16:26:13 +02:00
std::vector<Task> Event::queryTasks() const
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
auto tasksData = data_->getTasksByEventId(eventData_.id);
std::vector<Task> tasks;
std::transform(
tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
[&](const TaskData &taskData) {
return Task{data_, taskData};
}
);
return tasks;
2024-08-16 21:35:12 +02:00
}
2024-10-11 16:26:13 +02:00
void Event::setTitle(const std::string &newTitle)
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
data_->updateEvent(id(), {.title = newTitle});
2024-08-16 21:35:12 +02:00
}
2024-10-11 16:26:13 +02:00
void Event::setDay(const Day &day)
2024-08-16 21:35:12 +02:00
{
2024-10-11 16:26:13 +02:00
data_->updateEvent(id(), {.dayId = day.id()});
2024-08-16 21:35:12 +02:00
}
void Event::setStartTime(const Time &time)
{
2024-10-11 16:26:13 +02:00
data_->updateEvent(id(), {.startsAt = time});
2024-08-16 21:35:12 +02:00
}
void Event::setEndTime(const Time &time)
{
2024-10-11 16:26:13 +02:00
data_->updateEvent(id(), {.endsAt = time});
2024-08-16 21:35:12 +02:00
}
} // namespace mirai