Skip to content

Commit aca404e

Browse files
authored
Handle TODO within (#157)
1 parent 7e75728 commit aca404e

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

api/src/main/java/com/javadiscord/jdi/core/api/GuildScheduledEventRequest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import java.util.List;
44

5-
import com.javadiscord.jdi.core.api.builders.CreateScheduledEventBuilder;
6-
import com.javadiscord.jdi.core.api.builders.GetScheduledEventBuilder;
7-
import com.javadiscord.jdi.core.api.builders.GetScheduledEventUsersBuilder;
8-
import com.javadiscord.jdi.core.api.builders.ListScheduledEventsBuilder;
5+
import com.javadiscord.jdi.core.api.builders.*;
96
import com.javadiscord.jdi.core.models.scheduled_event.EventUser;
107
import com.javadiscord.jdi.core.models.scheduled_event.ScheduledEvent;
118
import com.javadiscord.jdi.internal.api.guild_scheduled_event.*;
@@ -23,6 +20,10 @@ public AsyncResponse<ScheduledEvent> createScheduledEvent(CreateScheduledEventBu
2320
return responseParser.callAndParse(ScheduledEvent.class, builder.guildId(guildId).build());
2421
}
2522

23+
public AsyncResponse<ScheduledEvent> modifyScheduledEvent(ModifyScheduledEventBuilder builder) {
24+
return responseParser.callAndParse(ScheduledEvent.class, builder.build());
25+
}
26+
2627
public AsyncResponse<ScheduledEvent> deleteScheduledEvent(long scheduledEventId) {
2728
return responseParser.callAndParse(
2829
ScheduledEvent.class, new DeleteScheduledEventRequest(guildId, scheduledEventId)

api/src/main/java/com/javadiscord/jdi/core/api/builders/ModifyScheduledEventBuilder.java

+23-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.javadiscord.jdi.core.models.guild.EntityMetadata;
66
import com.javadiscord.jdi.core.models.guild.PrivacyLevel;
7+
import com.javadiscord.jdi.core.models.scheduled_event.ScheduledEntityType;
78
import com.javadiscord.jdi.internal.api.guild_scheduled_event.ModifyScheduledEventRequest;
89

910
public class ModifyScheduledEventBuilder {
@@ -14,9 +15,9 @@ public class ModifyScheduledEventBuilder {
1415
private Optional<String> name;
1516
private Optional<Integer> privacyLevel;
1617
private Optional<Long> scheduledStartTime;
17-
private Optional<Long> scheduledEndTim;
18+
private Optional<Long> scheduledEndTime;
1819
private Optional<String> description;
19-
private Optional<Integer> entityType;
20+
private Optional<ScheduledEntityType> entityType;
2021
private Optional<Integer> status;
2122
private Optional<String> image;
2223

@@ -28,7 +29,7 @@ public ModifyScheduledEventBuilder(long guildId, long scheduledEventId) {
2829
this.name = Optional.empty();
2930
this.privacyLevel = Optional.empty();
3031
this.scheduledStartTime = Optional.empty();
31-
this.scheduledEndTim = Optional.empty();
32+
this.scheduledEndTime = Optional.empty();
3233
this.description = Optional.empty();
3334
this.entityType = Optional.empty();
3435
this.status = Optional.empty();
@@ -60,8 +61,8 @@ public ModifyScheduledEventBuilder scheduledStartTime(long scheduledStartTime) {
6061
return this;
6162
}
6263

63-
public ModifyScheduledEventBuilder scheduledEndTim(long scheduledEndTim) {
64-
this.scheduledEndTim = Optional.of(scheduledEndTim);
64+
public ModifyScheduledEventBuilder scheduledEndTime(long scheduledEndTim) {
65+
this.scheduledEndTime = Optional.of(scheduledEndTim);
6566
return this;
6667
}
6768

@@ -70,12 +71,12 @@ public ModifyScheduledEventBuilder description(String description) {
7071
return this;
7172
}
7273

73-
public ModifyScheduledEventBuilder entityType(Integer entityType) {
74+
public ModifyScheduledEventBuilder entityType(ScheduledEntityType entityType) {
7475
this.entityType = Optional.of(entityType);
7576
return this;
7677
}
7778

78-
public ModifyScheduledEventBuilder status(Integer status) {
79+
public ModifyScheduledEventBuilder status(int status) {
7980
this.status = Optional.of(status);
8081
return this;
8182
}
@@ -86,6 +87,20 @@ public ModifyScheduledEventBuilder image(String image) {
8687
}
8788

8889
public ModifyScheduledEventRequest build() {
90+
if (entityType.isPresent() && entityType.get() == ScheduledEntityType.EXTERNAL) {
91+
if (entityMetadata.isEmpty() || scheduledEndTime.isEmpty()) {
92+
throw new IllegalArgumentException(
93+
"When entityType is EXTERNAL, both entityMetadata and scheduledEndTime must"
94+
+ " be provided"
95+
);
96+
}
97+
if (channelId.isPresent()) {
98+
throw new IllegalArgumentException(
99+
"When entityType is EXTERNAL, channelId must not be provided"
100+
);
101+
}
102+
}
103+
89104
return new ModifyScheduledEventRequest(
90105
guildId,
91106
scheduledEventId,
@@ -94,7 +109,7 @@ public ModifyScheduledEventRequest build() {
94109
name,
95110
privacyLevel,
96111
scheduledStartTime,
97-
scheduledEndTim,
112+
scheduledEndTime,
98113
description,
99114
entityType,
100115
status,

api/src/main/java/com/javadiscord/jdi/internal/api/guild_scheduled_event/ModifyScheduledEventRequest.java

+3-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Optional;
66

77
import com.javadiscord.jdi.core.models.guild.EntityMetadata;
8+
import com.javadiscord.jdi.core.models.scheduled_event.ScheduledEntityType;
89
import com.javadiscord.jdi.internal.api.DiscordRequest;
910
import com.javadiscord.jdi.internal.api.DiscordRequestBuilder;
1011

@@ -18,30 +19,14 @@ public record ModifyScheduledEventRequest(
1819
Optional<Long> scheduledStartTime,
1920
Optional<Long> scheduledEndTime,
2021
Optional<String> description,
21-
Optional<Integer> entityType,
22+
Optional<ScheduledEntityType> entityType,
2223
Optional<Integer> status,
2324
Optional<String> image
2425
) implements DiscordRequest {
2526
@Override
2627
public DiscordRequestBuilder create() {
2728
Map<String, Object> body = new HashMap<>();
28-
29-
// check if entityType = 3 (EXTERNAL)
30-
// channelId must be set to null
31-
// entityMetadata (entity_metadata), scheduledEndTime are all required
32-
if (entityType.isPresent() && entityType.get() == 3) {
33-
if (entityMetadata.isEmpty() || scheduledEndTime.isEmpty()) {
34-
throw new IllegalArgumentException(
35-
"When entityType is EXTERNAL, both entityMetadata and scheduledEndTime must"
36-
+ " be provided"
37-
);
38-
}
39-
40-
body.put("channel_id", null);
41-
} else {
42-
channelId.ifPresent(val -> body.put("channel_id", val));
43-
}
44-
29+
channelId.ifPresent(val -> body.put("channel_id", val));
4530
entityMetadata.ifPresent(val -> body.put("entity_metadata", val));
4631
name.ifPresent(val -> body.put("name", val));
4732
privacyLevel.ifPresent(val -> body.put("privacy_level", val));
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
package com.javadiscord.jdi.core.models.scheduled_event;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
36
public enum ScheduledEntityType {
47
STAGE_INSTANCE,
58
VOICE,
6-
EXTERNAL
9+
EXTERNAL;
10+
11+
@JsonCreator
12+
public static ScheduledEntityType fromIndex(int index) {
13+
return ScheduledEntityType.values()[index - 1];
14+
}
15+
16+
@JsonValue
17+
public int toValue() {
18+
return ordinal() + 1;
19+
}
20+
721
}

models/src/main/java/com/javadiscord/jdi/core/models/scheduled_event/ScheduledEvent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public record ScheduledEvent(
2020
@JsonProperty("privacy_level") PrivacyLevel privacyLevel,
2121
@JsonProperty("status") EventStatus status,
2222
@JsonProperty("entity_type") ScheduledEntityType entityType,
23-
@JsonProperty("entity_id") Long entityId,
23+
@JsonProperty("entity_id") long entityId,
2424
@JsonProperty("entity_metadata") EntityMetadata entityMetadata,
2525
@JsonProperty("creator") User creator,
2626
@JsonProperty("user_count") int userCount,

0 commit comments

Comments
 (0)