This should in theory fix the bad auth when getting events by API

Google is returning a 400 code saying we are using a bad key. Hopefully by using the same methods that are already working elsewhere in the software (specifically the abstracted reactive wrappers I made), this should at least help narrow down where/what is causing the issue or outright solve the issue.

This marks a point where I realize I need to go through the API and make sure its more in line with how other parts of the program gets the same data.
This commit is contained in:
NovaFox161
2020-08-07 03:43:10 -05:00
parent c4ad36a735
commit 9f20bd9970
4 changed files with 44 additions and 62 deletions

View File

@@ -44,7 +44,8 @@ public class EventWrapper {
).onErrorResume(e -> Mono.empty()); //Can ignore this, the event just doesn't exist.
}
public static Mono<List<Event>> getEvents(final CalendarData data, final GuildSettings settings, final int amount, final long start) {
public static Mono<List<Event>> getEvents(final CalendarData data, final GuildSettings settings, final int amount,
final long start) {
return CalendarAuth.getCalendarService(settings).flatMap(service ->
Mono.fromCallable(() ->
service.events().list(data.getCalendarId())
@@ -58,7 +59,8 @@ public class EventWrapper {
).onErrorResume(e -> Mono.empty());
}
public static Mono<List<Event>> getEvents(final CalendarData data, final Calendar service, final int amount, final long start) {
public static Mono<List<Event>> getEvents(final CalendarData data, final Calendar service, final int amount,
final long start) {
return Mono.fromCallable(() ->
service.events().list(data.getCalendarId())
.setMaxResults(amount)
@@ -71,8 +73,8 @@ public class EventWrapper {
.onErrorResume(e -> Mono.empty());
}
public static Mono<List<Event>> getEvents(final CalendarData data, final GuildSettings settings, final int amount, final long start,
final long end) {
public static Mono<List<Event>> getEvents(final CalendarData data, final GuildSettings settings, final int amount,
final long start, final long end) {
return CalendarAuth.getCalendarService(settings).flatMap(service ->
Mono.fromCallable(() ->
service.events().list(data.getCalendarId())
@@ -87,6 +89,21 @@ public class EventWrapper {
).onErrorResume(e -> Mono.empty());
}
public static Mono<List<Event>> getEvents(final CalendarData data, final GuildSettings settings, final long start,
final long end) {
return CalendarAuth.getCalendarService(settings).flatMap(service ->
Mono.fromCallable(() ->
service.events().list(data.getCalendarId())
.setTimeMin(new DateTime(start))
.setTimeMax(new DateTime(end))
.setOrderBy("startTime")
.setSingleEvents(true)
.setShowDeleted(false)
.execute().getItems()
).subscribeOn(Schedulers.boundedElastic())
).onErrorResume(e -> Mono.empty());
}
public static Mono<Void> deleteEvent(final CalendarData data, final GuildSettings settings, final String id) {
return CalendarAuth.getCalendarService(settings).flatMap(service ->
Mono.fromCallable(() ->

View File

@@ -1,21 +1,16 @@
package org.dreamexposure.discal.server.api.endpoints.v2.event.list;
import com.google.api.client.util.DateTime;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.Events;
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;
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.JsonUtils;
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
import org.dreamexposure.discal.server.utils.Authentication;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
@@ -23,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@@ -54,21 +50,14 @@ public class ListEventDateEndpoint {
final GuildSettings settings = DatabaseManager.getSettings(guildId).block();
//okay, lets actually get the date's events.
final Calendar service = CalendarAuth.getCalendarService(settings).block();
final List<Event> events = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
.flatMap(calData -> EventWrapper.getEvents(calData, settings, startEpoch, endEpoch))
.block();
final CalendarData calendarData = DatabaseManager.getCalendar(settings.getGuildID(), calNumber).block();
final Events events = service.events().list(calendarData.getCalendarAddress())
.setTimeMin(new DateTime(startEpoch))
.setTimeMax(new DateTime(endEpoch))
.setOrderBy("startTime")
.setSingleEvents(true)
.setShowDeleted(false)
.execute();
final List<Event> items = events.getItems();
final JSONArray jEvents = new JSONArray();
for (final Event e : items)
jEvents.put(JsonUtils.convertEventToJson(e, settings));
final List<JSONObject> jEvents = new ArrayList<>();
for (final Event e : events) {
jEvents.add(JsonUtils.convertEventToJson(e, settings));
}
final JSONObject body = new JSONObject();
body.put("events", jEvents);

View File

@@ -1,19 +1,15 @@
package org.dreamexposure.discal.server.api.endpoints.v2.event.list;
import com.google.api.client.util.DateTime;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.Events;
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;
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.JsonUtils;
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
import org.dreamexposure.discal.server.utils.Authentication;
import org.json.JSONException;
import org.json.JSONObject;
@@ -55,21 +51,12 @@ public class ListEventMonthEndpoint {
final GuildSettings settings = DatabaseManager.getSettings(guildId).block();
//okay, lets actually get the month's events.
final Calendar service = CalendarAuth.getCalendarService(settings).block();
final CalendarData calendarData = DatabaseManager.getCalendar(settings.getGuildID(), calNumber).block();
final Events events = service.events().list(calendarData.getCalendarAddress())
.setTimeMin(new DateTime(startEpoch))
.setTimeMax(new DateTime(endEpoch))
.setOrderBy("startTime")
.setSingleEvents(true)
.setShowDeleted(false)
.execute();
final List<Event> items = events.getItems();
final List<Event> events = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
.flatMap(calData -> EventWrapper.getEvents(calData, settings, startEpoch, endEpoch))
.block();
final List<JSONObject> jEvents = new ArrayList<>();
for (final Event e : items) {
for (final Event e : events) {
jEvents.add(JsonUtils.convertEventToJson(e, settings));
}

View File

@@ -1,21 +1,16 @@
package org.dreamexposure.discal.server.api.endpoints.v2.event.list;
import com.google.api.client.util.DateTime;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.Events;
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;
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.JsonUtils;
import org.dreamexposure.discal.core.wrapper.google.EventWrapper;
import org.dreamexposure.discal.server.utils.Authentication;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
@@ -23,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@@ -54,21 +50,14 @@ public class ListEventRangeEndpoint {
final GuildSettings settings = DatabaseManager.getSettings(guildId).block();
//okay, lets actually get the range's events.
final Calendar service = CalendarAuth.getCalendarService(settings).block();
final List<Event> events = DatabaseManager.getCalendar(settings.getGuildID(), calNumber)
.flatMap(calData -> EventWrapper.getEvents(calData, settings, startEpoch, endEpoch))
.block();
final CalendarData calendarData = DatabaseManager.getCalendar(settings.getGuildID(), calNumber).block();
final Events events = service.events().list(calendarData.getCalendarAddress())
.setTimeMin(new DateTime(startEpoch))
.setTimeMax(new DateTime(endEpoch))
.setOrderBy("startTime")
.setSingleEvents(true)
.setShowDeleted(false)
.execute();
final List<Event> items = events.getItems();
final JSONArray jEvents = new JSONArray();
for (final Event e : items)
jEvents.put(JsonUtils.convertEventToJson(e, settings));
final List<JSONObject> jEvents = new ArrayList<>();
for (final Event e : events) {
jEvents.add(JsonUtils.convertEventToJson(e, settings));
}
final JSONObject body = new JSONObject();
body.put("events", jEvents);