~aleteoryx/muditaos

0802e8f954b2e0d824c82d5e1726e91f70eada5c — Paweł Joński 4 years ago 45a7216
[BH-687] Add Events to DB

Add Events table to sql database
Add EventsTable and EventsRecord
A image/user/db/events_001.sql => image/user/db/events_001.sql +12 -0
@@ 0,0 1,12 @@
-- Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-- For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

CREATE TABLE IF NOT EXISTS events(
                  _id INTEGER PRIMARY KEY,
                  name TEXT DEFAULT '',
                  startDate DATETIME,
                  endDate DATETIME,
                  duration INTEGER,
                  isAllDay BOOLEAN,
                  recurrenceRule TEXT DEFAULT ''
);

M module-db/Interface/EventRecord.hpp => module-db/Interface/EventRecord.hpp +24 -4
@@ 3,30 3,50 @@

#pragma once

#include "Tables/Record.hpp"
#include "Record.hpp"

#include <module-db/Common/Common.hpp>
#include <Tables/Record.hpp>
#include <Tables/EventsTable.hpp>

#include <time/dateCommon.hpp>

#include <utf8/UTF8.hpp>

#include <stdint.h>
#include <string>

struct EventInfo
{
    UTF8 name;
    std::chrono::time_point<std::chrono::system_clock> startDate{TIME_POINT_INVALID};
    std::chrono::time_point<std::chrono::system_clock> endDate{TIME_POINT_INVALID};
    TimePoint startDate{TIME_POINT_INVALID};
    TimePoint endDate{TIME_POINT_INVALID};
    uint32_t duration{0};
    bool isAllDay{false};

    EventInfo(UTF8 name, TimePoint startDate, TimePoint endDate, uint32_t duration, bool isAllDay)
        : name{name}, startDate{startDate}, endDate{endDate}, duration{duration}, isAllDay{isAllDay} {};
};

struct EventRecord : public Record, public EventInfo
{
    uint32_t id{0};
    std::string rrule{""};

    EventRecord() = default;
    EventRecord(uint32_t id,
                UTF8 name,
                TimePoint startDate,
                TimePoint endDate,
                uint32_t duration,
                bool isAllDay,
                std::string rrule)
        : Record{id}, EventInfo{name, startDate, endDate, duration, isAllDay}, rrule{rrule} {};
};

struct SingleEventRecord : public Record, public EventInfo
{
    std::shared_ptr<EventRecord> parent;

    SingleEventRecord(std::shared_ptr<EventRecord> parent, TimePoint startDate, TimePoint endDate)
        : EventInfo{parent->name, startDate, endDate, parent->duration, parent->isAllDay}, parent{parent} {};
};

A module-db/Tables/EventsTable.hpp => module-db/Tables/EventsTable.hpp +37 -0
@@ 0,0 1,37 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Record.hpp"
#include "Table.hpp"

#include <Common/Common.hpp>
#include <Database/Database.hpp>

#include <time/dateCommon.hpp>

#include <utf8/UTF8.hpp>

struct EventRecord;

struct EventsTableRow : public Record
{
    UTF8 name{""};
    TimePoint startDate{TIME_POINT_INVALID};
    TimePoint endDate{TIME_POINT_INVALID};
    uint32_t duration{0};
    bool isAllDay{false};
    std::string rrule{""};

    EventsTableRow() = default;
    EventsTableRow(uint32_t id,
                   UTF8 name,
                   TimePoint startDate,
                   TimePoint endDate,
                   uint32_t duration,
                   bool isAllDay,
                   std::string rrule)
        : Record{id}, name{name}, startDate{startDate}, endDate{endDate}, duration{duration}, isAllDay{isAllDay},
          rrule{rrule} {};
};