代码拉取完成,页面将自动刷新
diff --git a/calendarmanager/napi/include/napi_util.h b/calendarmanager/napi/include/napi_util.h
index f61b80d..e97f7c0 100644
--- a/calendarmanager/napi/include/napi_util.h
+++ b/calendarmanager/napi/include/napi_util.h
@@ -146,7 +146,7 @@ namespace OHOS::CalendarApi::NapiUtil {
if (status != napi_ok) {
return status;
}
- return napi_set_named_property(env, out, prop, value);
+ return napi_set_named_property(env, out, prop.c_str(), value);
}
template <typename T>
@@ -160,7 +160,7 @@ namespace OHOS::CalendarApi::NapiUtil {
if (status != napi_ok) {
return;
}
- napi_set_named_property(env, out, prop, value);
+ napi_set_named_property(env, out, prop.c_str(), value);
}
/* napi_get_named_property wrapper */
diff --git a/calendarmanager/napi/src/calendar_enum_napi.cpp b/calendarmanager/napi/src/calendar_enum_napi.cpp
index ac815f3..f935b3f 100644
--- a/calendarmanager/napi/src/calendar_enum_napi.cpp
+++ b/calendarmanager/napi/src/calendar_enum_napi.cpp
@@ -38,7 +38,7 @@ static const std::vector<struct JsEnumInt> g_eventType = {
{ "NORMAL", EventType::Normal },
};
-static const std::vector<struct JsEnumInt> g_recurrenceType = {
+static const std::vector<struct JsEnumInt> g_recurrenceFrequency = {
{ "YEARLY", RecurrenceType::YEARLY },
{ "MONTHLY", RecurrenceType::MONTHLY },
{ "WEEKLY", RecurrenceType::WEEKLY },
@@ -48,6 +48,7 @@ static const std::vector<struct JsEnumInt> g_recurrenceType = {
static const std::vector<struct JsEnumString> g_calendarTypeKey = {
{ "LOCAL", "local" },
{ "EMAIL", "email" },
+ { "BIRTHDAY", "birthday" },
{ "CALDAV", "caldav" },
{ "SUBSCRIBED", "subscribed" },
};
@@ -66,7 +67,7 @@ static const std::vector<struct JsEnumString> g_serviceType = {
static const std::map<std::string_view, const std::vector<struct JsEnumInt>&> g_intEnumClassMap = {
{ "EventType", g_eventType},
- { "RecurrenceType", g_recurrenceType},
+ { "RecurrenceFrequency", g_recurrenceFrequency},
};
static const std::map<std::string_view, const std::vector<struct JsEnumString>&> g_stringEnumClassMap = {
diff --git a/calendarmanager/napi/src/calendar_napi.cpp b/calendarmanager/napi/src/calendar_napi.cpp
index 0e41d4f..cabdc99 100644
--- a/calendarmanager/napi/src/calendar_napi.cpp
+++ b/calendarmanager/napi/src/calendar_napi.cpp
@@ -161,11 +161,7 @@ napi_value CalendarNapi::AddEvents(napi_env env, napi_callback_info info)
ctxt->status = (ctxt->count > 0) ? napi_ok : napi_generic_failure;
CHECK_STATUS_RETURN_VOID(ctxt, "AddEvent failed!");
};
- auto output = [env, ctxt](napi_value& result) {
- ctxt->status = NapiUtil::SetValue(ctxt->env, ctxt->count, result);
- CHECK_STATUS_RETURN_VOID(ctxt, "output failed");
- };
- return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output);
+ return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute);
}
napi_value CalendarNapi::DeleteEvent(napi_env env, napi_callback_info info)
@@ -190,11 +186,7 @@ napi_value CalendarNapi::DeleteEvent(napi_env env, napi_callback_info info)
CHECK_RETURN_VOID(nativeCalendar != nullptr, "nativeCalendar nullptr");
ctxt->result = nativeCalendar->DeleteEvent(ctxt->eventId);
};
- auto output = [env, ctxt](napi_value& result) {
- ctxt->status = NapiUtil::SetValue(ctxt->env, ctxt->result, result);
- CHECK_STATUS_RETURN_VOID(ctxt, "output failed");
- };
- return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output);
+ return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute);
}
napi_value CalendarNapi::DeleteEvents(napi_env env, napi_callback_info info)
@@ -219,11 +211,7 @@ napi_value CalendarNapi::DeleteEvents(napi_env env, napi_callback_info info)
CHECK_RETURN_VOID(nativeCalendar != nullptr, "nativeCalendar nullptr");
ctxt->result = nativeCalendar->DeleteEvents(ctxt->ids);
};
- auto output = [env, ctxt](napi_value& result) {
- ctxt->status = NapiUtil::SetValue(ctxt->env, ctxt->result, result);
- CHECK_STATUS_RETURN_VOID(ctxt, "output failed");
- };
- return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output);
+ return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute);
}
napi_value CalendarNapi::UpdateEvent(napi_env env, napi_callback_info info)
@@ -248,11 +236,7 @@ napi_value CalendarNapi::UpdateEvent(napi_env env, napi_callback_info info)
CHECK_RETURN_VOID(nativeCalendar != nullptr, "nativeCalendar nullptr");
ctxt->result = nativeCalendar->UpdateEvent(ctxt->event);
};
- auto output = [env, ctxt](napi_value& result) {
- ctxt->status = NapiUtil::SetValue(ctxt->env, ctxt->result, result);
- CHECK_STATUS_RETURN_VOID(ctxt, "output failed");
- };
- return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output);
+ return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute);
}
napi_value CalendarNapi::UpdateEvents(napi_env env, napi_callback_info info)
@@ -278,11 +262,7 @@ napi_value CalendarNapi::UpdateEvents(napi_env env, napi_callback_info info)
CHECK_RETURN_VOID(nativeCalendar != nullptr, "nativeCalendar nullptr");
ctxt->result = nativeCalendar->UpdateEvents(ctxt->events);
};
- auto output = [env, ctxt](napi_value& result) {
- ctxt->status = NapiUtil::SetValue(ctxt->env, ctxt->result, result);
- CHECK_STATUS_RETURN_VOID(ctxt, "output failed");
- };
- return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output);
+ return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute);
}
napi_value CalendarNapi::GetEvents(napi_env env, napi_callback_info info)
@@ -389,11 +369,7 @@ napi_value CalendarNapi::SetConfig(napi_env env, napi_callback_info info)
CHECK_RETURN_VOID(nativeCalendar != nullptr, "nativeCalendar nullptr");
ctxt->result = nativeCalendar->SetConfig(ctxt->config);
};
- auto output = [env, ctxt](napi_value& result) {
- ctxt->status = NapiUtil::SetValue(ctxt->env, ctxt->result, result);
- CHECK_STATUS_RETURN_VOID(ctxt, "output failed");
- };
- return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output);
+ return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute);
}
napi_value CalendarNapi::GetAccount(napi_env env, napi_callback_info info)
diff --git a/calendarmanager/napi/src/napi_util.cpp b/calendarmanager/napi/src/napi_util.cpp
index de66615..5c03567 100644
--- a/calendarmanager/napi/src/napi_util.cpp
+++ b/calendarmanager/napi/src/napi_util.cpp
@@ -523,7 +523,11 @@ napi_status SetValue(napi_env env, const Event& in, napi_value& out)
CHECK_RETURN((status == napi_ok), "invalid entry endTime", status);
SetNamedPropertyOptional(env, "isAllDay", in.isAllDay, out);
- SetNamedPropertyOptional(env, "attendee", in.attendees, out);
+ if (!in.attendees.empty()) {
+ status = SetNamedProperty(env, "attendee", in.attendees, out);
+ CHECK_RETURN((status == napi_ok), "invalid entry attendee", status);
+ }
+
SetNamedPropertyOptional(env, "timeZone", in.timeZone, out);
SetNamedPropertyOptional(env, "reminderTime", in.reminderTime, out);
SetNamedPropertyOptional(env, "description", in.description, out);
diff --git a/calendarmanager/native/src/native_calendar.cpp b/calendarmanager/native/src/native_calendar.cpp
index ed539d1..bad8257 100644
--- a/calendarmanager/native/src/native_calendar.cpp
+++ b/calendarmanager/native/src/native_calendar.cpp
@@ -254,8 +254,8 @@ std::vector<Event> Calendar::GetEvents(std::shared_ptr<EventFilter> filter, cons
predicates = std::make_shared<DataShare::DataSharePredicates>();
}
predicates->EqualTo("calendar_id", GetId());
- std::vector<std::string> columns = {"_id", "title", "event_calendar_type",
- "dtstart", "dtend",
+ std::vector<std::string> columns = {"_id", "title", "description", "event_calendar_type",
+ "dtstart", "dtend", "allDay", "eventTimezone",
"eventLocation", "location_longitude", "location_latitude",
"service_type", "service_cp_bz_uri", "service_description"};
DataShare::DatashareBusinessError error;
diff --git a/calendarmanager/native/src/native_util.cpp b/calendarmanager/native/src/native_util.cpp
index 97b7e19..33f1d39 100644
--- a/calendarmanager/native/src/native_util.cpp
+++ b/calendarmanager/native/src/native_util.cpp
@@ -108,7 +108,12 @@ DataShare::DataShareValuesBucket BuildValueEvent(const Event &event, int calenda
LOG_DEBUG("description %{public}s", event.description.value_or("").c_str());
valuesBucket.Put("description", event.description.value_or(""));
- valuesBucket.Put("eventTimezone", "Asia/Shanghai");
+ if (event.timeZone) {
+ valuesBucket.Put("eventTimezone", event.timeZone.value());
+ }
+ if (event.isAllDay) {
+ valuesBucket.Put("allDay", event.isAllDay.value() ? 1 : 0);
+ }
valuesBucket.Put("allDay", event.isAllDay ? (event.isAllDay.value() ? 1 : 0) : 0);
return valuesBucket;
}
@@ -262,6 +267,24 @@ std::optional<EventService> ResultSetToEventService(DataShareResultSetPtr &resul
return std::make_optional<EventService>(out);
}
+void ResultSetToEvent(Event &event, DataShareResultSetPtr &resultSet)
+{
+ GetValueOptional(resultSet, "_id", event.id);
+ int type = 0;
+ GetValue(resultSet, "event_calendar_type", type);
+ event.type = static_cast<EventType>(type);
+ GetValueOptional(resultSet, "title", event.title);
+ GetValue(resultSet, "dtstart", event.startTime);
+ GetValue(resultSet, "dtend", event.endTime);
+ int isAllDay = 0;
+ GetValue(resultSet, "allDay", isAllDay);
+ event.isAllDay = static_cast<bool>(isAllDay);
+ GetValueOptional(resultSet, "description", event.description);
+ GetValueOptional(resultSet, "eventTimezone", event.timeZone);
+ event.location = ResultSetToLocation(resultSet);
+ event.service = ResultSetToEventService(resultSet);
+}
+
int ResultSetToEvents(std::vector<Event> &events, DataShareResultSetPtr &resultSet,
const std::vector<std::string>& columns)
{
@@ -278,17 +301,7 @@ int ResultSetToEvents(std::vector<Event> &events, DataShareResultSetPtr &resultS
}
do {
Event event;
- GetValueOptional(resultSet, "_id", event.id);
- int type = 0;
- GetValue(resultSet, "event_calendar_type", type);
- event.type = static_cast<EventType>(type);
- GetValueOptional(resultSet, "title", event.title);
- GetValue(resultSet, "dtstart", event.startTime);
- GetValue(resultSet, "dtend", event.endTime);
- GetValueOptional(resultSet, "description", event.description);
- GetValueOptional(resultSet, "eventTimezone", event.timeZone);
- event.location = ResultSetToLocation(resultSet);
- event.service = ResultSetToEventService(resultSet);
+ ResultSetToEvent(event, resultSet);
events.emplace_back(event);
} while (resultSet->GoToNextRow() == DataShare::E_OK);
return 0;
diff --git a/calendarmanager/test/unittest/src/calendar_test.cpp b/calendarmanager/test/unittest/src/calendar_test.cpp
index aebe86e..dea51e2 100644
--- a/calendarmanager/test/unittest/src/calendar_test.cpp
+++ b/calendarmanager/test/unittest/src/calendar_test.cpp
@@ -123,6 +123,44 @@ HWTEST_F(CalendarTest, AddEvents_input_empty, testing::ext::TestSize.Level1)
ASSERT_EQ(count, 0);
}
+HWTEST_F(CalendarTest, GetEvent_test_1, testing::ext::TestSize.Level1)
+{
+ Event event;
+ const string title = "GetEvent_test_1";
+ event.title = title;
+ event.type = EventType::Important;
+ Location testLocation { "test", 123, 456 };
+ event.location = std::make_optional<Location>(testLocation);
+ const int startTime = 12;
+ event.startTime = startTime;
+ const int endTime = 100;
+ event.endTime = endTime;
+ event.isAllDay = true;
+ event.attendees = {
+ {"xiaoming", "xiaoming@abc.com"},
+ {"xiaoqiang", "test_attendee1@abc.com"},
+ {"abc", "test_attendee2@abc.com"}
+ };
+ event.timeZone = "shanghai";
+ event.reminderTime = {0, 1, 2};
+ event.description = "UpdateEvent_test_2_disp";
+ const auto eventId = calendar->AddEvent(event);
+ ASSERT_NE(eventId, 0);
+ const auto events = calendar->GetEvents(FilterById({eventId}), {});
+ ASSERT_EQ(1, events.size());
+ const auto newEvent = events.at(0);
+ EXPECT_EQ(newEvent.title, event.title);
+ EXPECT_EQ(newEvent.type, event.type);
+ EXPECT_EQ(newEvent.location, event.location);
+ EXPECT_EQ(newEvent.startTime, event.startTime);
+ EXPECT_EQ(newEvent.endTime, event.endTime);
+ EXPECT_EQ(newEvent.isAllDay, event.isAllDay);
+ EXPECT_EQ(newEvent.attendees, event.attendees);
+ EXPECT_EQ(newEvent.timeZone, event.timeZone);
+ EXPECT_EQ(newEvent.reminderTime, event.reminderTime);
+ EXPECT_EQ(newEvent.description, event.description);
+}
+
HWTEST_F(CalendarTest, UpdateEvent_test_1, testing::ext::TestSize.Level1)
{
Event event;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。