mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-04-30 14:19:55 -05:00
Merge branch 'master' of https://github.com/DreamExposure/DisCal-Discord-Bot into feature/rsvp-role
This commit is contained in:
+16
-8
@@ -1,9 +1,8 @@
|
||||
package org.dreamexposure.discal.server.api.endpoints.v2.event;
|
||||
|
||||
import com.google.api.services.calendar.Calendar;
|
||||
import com.google.api.services.calendar.model.Calendar;
|
||||
import com.google.api.services.calendar.model.Event;
|
||||
|
||||
import org.dreamexposure.discal.core.calendar.CalendarAuth;
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.logger.LogFeed;
|
||||
import org.dreamexposure.discal.core.logger.object.LogObject;
|
||||
@@ -13,6 +12,8 @@ import org.dreamexposure.discal.core.object.web.AuthenticationState;
|
||||
import org.dreamexposure.discal.core.utils.GlobalConst;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtil;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtils;
|
||||
import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper;
|
||||
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
|
||||
import org.dreamexposure.discal.server.utils.Authentication;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -21,10 +22,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.ZoneId;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v2/events")
|
||||
@@ -46,18 +50,22 @@ public class GetEventEndpoint {
|
||||
final String guildId = requestBody.getString("guild_id");
|
||||
final int calNumber = requestBody.getInt("calendar_number");
|
||||
final String eventId = requestBody.getString("event_id");
|
||||
|
||||
final GuildSettings settings = DatabaseManager.getSettings(Snowflake.of(guildId)).block();
|
||||
final CalendarData calendarData = DatabaseManager.getCalendar(settings.getGuildID(), calNumber).block();
|
||||
Mono<CalendarData> calDataMono = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
|
||||
.cache();
|
||||
final Event event = calDataMono.flatMap(calData -> EventWrapper.getEvent(calData, eventId))
|
||||
.block();
|
||||
final ZoneId tz = calDataMono.flatMap(CalendarWrapper::getCalendar)
|
||||
.map(Calendar::getTimeZone)
|
||||
.map(ZoneId::of)
|
||||
.block();
|
||||
|
||||
//okay, get the calendar service and then the event
|
||||
final Calendar service = CalendarAuth.getCalendarService(calendarData).block();
|
||||
|
||||
final Event event = service.events().get(calendarData.getCalendarAddress(), eventId).execute();
|
||||
|
||||
response.setContentType("application/json");
|
||||
if (event != null) {
|
||||
response.setStatus(GlobalConst.STATUS_SUCCESS);
|
||||
return JsonUtils.convertEventToJson(event, settings).toString();
|
||||
return JsonUtils.convertEventToJson(event, tz, settings).block().toString();
|
||||
} else {
|
||||
response.setStatus(GlobalConst.STATUS_NOT_FOUND);
|
||||
return JsonUtils.getJsonResponseMessage("Event not Found");
|
||||
|
||||
+15
-2
@@ -1,13 +1,17 @@
|
||||
package org.dreamexposure.discal.server.api.endpoints.v2.event.list;
|
||||
|
||||
import com.google.api.services.calendar.model.Calendar;
|
||||
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.logger.LogFeed;
|
||||
import org.dreamexposure.discal.core.logger.object.LogObject;
|
||||
import org.dreamexposure.discal.core.object.GuildSettings;
|
||||
import org.dreamexposure.discal.core.object.calendar.CalendarData;
|
||||
import org.dreamexposure.discal.core.object.web.AuthenticationState;
|
||||
import org.dreamexposure.discal.core.utils.GlobalConst;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtil;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtils;
|
||||
import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper;
|
||||
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
|
||||
import org.dreamexposure.discal.server.utils.Authentication;
|
||||
import org.json.JSONException;
|
||||
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -24,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v2/events/list")
|
||||
@@ -46,13 +52,20 @@ public class ListEventDateEndpoint {
|
||||
final int calNumber = requestBody.getInt("calendar_number");
|
||||
final long startEpoch = requestBody.getLong("epoch_start");
|
||||
final long endEpoch = startEpoch + GlobalConst.oneDayMs;
|
||||
|
||||
final GuildSettings settings = DatabaseManager.getSettings(guildId).block();
|
||||
Mono<CalendarData> calDataMono = DatabaseManager.getCalendar(guildId, calNumber)
|
||||
.cache();
|
||||
final ZoneId tz = calDataMono.flatMap(CalendarWrapper::getCalendar)
|
||||
.map(Calendar::getTimeZone)
|
||||
.map(ZoneId::of)
|
||||
.block();
|
||||
|
||||
//okay, lets actually get the date's events.
|
||||
final List<JSONObject> events = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
|
||||
final List<JSONObject> events = calDataMono
|
||||
.flatMap(calData -> EventWrapper.getEvents(calData, startEpoch, endEpoch))
|
||||
.flatMapMany(Flux::fromIterable)
|
||||
.map(e -> JsonUtils.convertEventToJson(e, settings))
|
||||
.flatMap(e -> JsonUtils.convertEventToJson(e, tz, settings))
|
||||
.collectList()
|
||||
.block();
|
||||
|
||||
|
||||
+15
-2
@@ -1,13 +1,17 @@
|
||||
package org.dreamexposure.discal.server.api.endpoints.v2.event.list;
|
||||
|
||||
import com.google.api.services.calendar.model.Calendar;
|
||||
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.logger.LogFeed;
|
||||
import org.dreamexposure.discal.core.logger.object.LogObject;
|
||||
import org.dreamexposure.discal.core.object.GuildSettings;
|
||||
import org.dreamexposure.discal.core.object.calendar.CalendarData;
|
||||
import org.dreamexposure.discal.core.object.web.AuthenticationState;
|
||||
import org.dreamexposure.discal.core.utils.GlobalConst;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtil;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtils;
|
||||
import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper;
|
||||
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
|
||||
import org.dreamexposure.discal.server.utils.Authentication;
|
||||
import org.json.JSONException;
|
||||
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -24,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v2/events/list")
|
||||
@@ -47,13 +53,20 @@ public class ListEventMonthEndpoint {
|
||||
final int daysInMonth = requestBody.getInt("days_in_month");
|
||||
final long startEpoch = requestBody.getLong("epoch_start");
|
||||
final long endEpoch = startEpoch + (GlobalConst.oneDayMs * daysInMonth);
|
||||
|
||||
final GuildSettings settings = DatabaseManager.getSettings(guildId).block();
|
||||
Mono<CalendarData> calDataMono = DatabaseManager.getCalendar(guildId, calNumber)
|
||||
.cache();
|
||||
final ZoneId tz = calDataMono.flatMap(CalendarWrapper::getCalendar)
|
||||
.map(Calendar::getTimeZone)
|
||||
.map(ZoneId::of)
|
||||
.block();
|
||||
|
||||
//okay, lets actually get the month's events.
|
||||
final List<JSONObject> events = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
|
||||
final List<JSONObject> events = calDataMono
|
||||
.flatMap(calData -> EventWrapper.getEvents(calData, startEpoch, endEpoch))
|
||||
.flatMapMany(Flux::fromIterable)
|
||||
.map(e -> JsonUtils.convertEventToJson(e, settings))
|
||||
.flatMap(e -> JsonUtils.convertEventToJson(e, tz, settings))
|
||||
.collectList()
|
||||
.block();
|
||||
|
||||
|
||||
+16
-2
@@ -1,13 +1,17 @@
|
||||
package org.dreamexposure.discal.server.api.endpoints.v2.event.list;
|
||||
|
||||
import com.google.api.services.calendar.model.Calendar;
|
||||
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.logger.LogFeed;
|
||||
import org.dreamexposure.discal.core.logger.object.LogObject;
|
||||
import org.dreamexposure.discal.core.object.GuildSettings;
|
||||
import org.dreamexposure.discal.core.object.calendar.CalendarData;
|
||||
import org.dreamexposure.discal.core.object.web.AuthenticationState;
|
||||
import org.dreamexposure.discal.core.utils.GlobalConst;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtil;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtils;
|
||||
import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper;
|
||||
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
|
||||
import org.dreamexposure.discal.server.utils.Authentication;
|
||||
import org.json.JSONException;
|
||||
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -24,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v2/events/list")
|
||||
@@ -48,13 +54,21 @@ public class ListEventOngoingEndpoint {
|
||||
final long end = System.currentTimeMillis() + GlobalConst.oneDayMs; // one day from now
|
||||
final GuildSettings settings = DatabaseManager.getSettings(guildId).block();
|
||||
|
||||
Mono<CalendarData> calDataMono = DatabaseManager.getCalendar(guildId, calNumber)
|
||||
.cache();
|
||||
final ZoneId tz = calDataMono.flatMap(CalendarWrapper::getCalendar)
|
||||
.map(Calendar::getTimeZone)
|
||||
.map(ZoneId::of)
|
||||
.block();
|
||||
|
||||
|
||||
//okay, lets actually get the date's events.
|
||||
final List<JSONObject> events = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
|
||||
final List<JSONObject> events = calDataMono
|
||||
.flatMap(calData -> EventWrapper.getEvents(calData, start, end))
|
||||
.flatMapMany(Flux::fromIterable)
|
||||
.filter(e -> e.getStart().getDateTime().getValue() < System.currentTimeMillis())
|
||||
.filter(e -> e.getEnd().getDateTime().getValue() > System.currentTimeMillis())
|
||||
.map(e -> JsonUtils.convertEventToJson(e, settings))
|
||||
.flatMap(e -> JsonUtils.convertEventToJson(e, tz, settings))
|
||||
.collectList()
|
||||
.block();
|
||||
|
||||
|
||||
+17
-2
@@ -1,13 +1,17 @@
|
||||
package org.dreamexposure.discal.server.api.endpoints.v2.event.list;
|
||||
|
||||
import com.google.api.services.calendar.model.Calendar;
|
||||
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.logger.LogFeed;
|
||||
import org.dreamexposure.discal.core.logger.object.LogObject;
|
||||
import org.dreamexposure.discal.core.object.GuildSettings;
|
||||
import org.dreamexposure.discal.core.object.calendar.CalendarData;
|
||||
import org.dreamexposure.discal.core.object.web.AuthenticationState;
|
||||
import org.dreamexposure.discal.core.utils.GlobalConst;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtil;
|
||||
import org.dreamexposure.discal.core.utils.JsonUtils;
|
||||
import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper;
|
||||
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
|
||||
import org.dreamexposure.discal.server.utils.Authentication;
|
||||
import org.json.JSONException;
|
||||
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -24,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v2/events/list")
|
||||
@@ -46,13 +52,22 @@ public class ListEventRangeEndpoint {
|
||||
final int calNumber = requestBody.getInt("calendar_number");
|
||||
final long startEpoch = requestBody.getLong("epoch_start");
|
||||
final long endEpoch = requestBody.getLong("epoch_end");
|
||||
|
||||
final GuildSettings settings = DatabaseManager.getSettings(guildId).block();
|
||||
|
||||
Mono<CalendarData> calDataMono = DatabaseManager.getCalendar(guildId, calNumber)
|
||||
.cache();
|
||||
final ZoneId tz = calDataMono.flatMap(CalendarWrapper::getCalendar)
|
||||
.map(Calendar::getTimeZone)
|
||||
.map(ZoneId::of)
|
||||
.block();
|
||||
|
||||
|
||||
//okay, lets actually get the range's events.
|
||||
final List<JSONObject> events = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
|
||||
final List<JSONObject> events = calDataMono
|
||||
.flatMap(calData -> EventWrapper.getEvents(calData, startEpoch, endEpoch))
|
||||
.flatMapMany(Flux::fromIterable)
|
||||
.map(e -> JsonUtils.convertEventToJson(e, settings))
|
||||
.flatMap(e -> JsonUtils.convertEventToJson(e, tz, settings))
|
||||
.collectList()
|
||||
.block();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user