Skip to content

Commit

Permalink
next step of work
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Dec 10, 2023
1 parent 6f99521 commit fce3e11
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 37 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/eternalcode/discordapp/DiscordApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.eternalcode.discordapp.leveling.leaderboard.LeaderboardButtonController;
import com.eternalcode.discordapp.leveling.leaderboard.LeaderboardCommand;
import com.eternalcode.discordapp.leveling.leaderboard.LeaderboardService;
import com.eternalcode.discordapp.meeting.MeetingController;
import com.eternalcode.discordapp.meeting.controller.MeetingController;
import com.eternalcode.discordapp.meeting.MeetingService;
import com.eternalcode.discordapp.meeting.command.MeetingCommand;
import com.eternalcode.discordapp.meeting.event.MeetingCreateEvent;
Expand All @@ -65,7 +65,6 @@
import java.io.File;
import java.sql.SQLException;
import java.time.Duration;
import java.time.Instant;
import java.util.EnumSet;
import java.util.Timer;

Expand Down Expand Up @@ -178,6 +177,9 @@ public static void main(String... args) throws InterruptedException {

// leaderboard
new LeaderboardButtonController(leaderboardService)

// meeting
/* new MeetingButtonController()*/
)

.setAutoReconnect(true)
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/eternalcode/discordapp/meeting/Meeting.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@

public class Meeting {

private Set<Long> presentMembers = new HashSet<>();
private Set<Long> absentMembers = new HashSet<>();
private final Set<Long> presentMembers = new HashSet<>();
private final Set<Long> absentMembers = new HashSet<>();

private Long requesterId;
private final Long requesterId;

private Instant issuedAt;
private Instant startTime;
private final Instant issuedAt;
private final Instant startTime;

public Meeting(Long requesterId, Instant issuedAt, Instant startTime) {
public Meeting(Long requesterId, Instant issuedAt, Instant startTime, Set<Long> presentMembers, Set<Long> absentMembers) {
this.requesterId = requesterId;
this.issuedAt = issuedAt;
this.startTime = startTime;
this.presentMembers.addAll(presentMembers);
this.absentMembers.addAll(absentMembers);
}

public Instant getIssuedAt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,15 @@ public MeetingService(DatabaseManager databaseManager, ObserverRegistry observer
}

public void createMeeting(Instant issuedAt, Instant startTime, Long requester, Long channelId) {
Meeting meeting = new Meeting(requester, issuedAt, startTime);
Meeting meeting = new Meeting(requester, issuedAt, startTime, null, null);

this.meetingRepository.saveMeeting(meeting);
this.observerRegistry.publish(new MeetingCreateEvent(meeting, requester, channelId));
}

public void deleteMeeting(Instant issuedAt, Instant startTime, Long requester) {
Meeting meeting = new Meeting(requester, issuedAt, startTime);

this.meetingRepository.deleteMeeting(meeting);
}

public void findMeeting(Instant issuedAt, Instant startTime, Long requester) {
Meeting meeting = new Meeting(requester, issuedAt, startTime);

this.meetingRepository.findMeeting(meeting);
}

//zw
// TODO; tutaj sie zrobi metode od update i create embed, a z obiektu z bazy bedzie sie pobierac absent i present osoby
// TODO: i bedzie sie je dodawac do embeda, a potem edytowac embed juz wczesniej wyslany za pomoca metody od update
// TODO: i sa eventy MeetinbMemberAbsentEvent ii MeetingMemberPresent i bedzie sie je nasluchiwac i dodawac do listy albo present albo absent
// TODO: ten kod co napisalem juz to troche sensu w niektorych momentach nie ma, ale ogolnie to jest to co trzeba zrobic ^^, jak ktos chce to niech zrobi

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.eternalcode.discordapp.meeting.controller;

import com.eternalcode.discordapp.meeting.database.MeetingRepository;
import com.eternalcode.discordapp.meeting.database.MeetingRepositoryImpl;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class MeetingButtonController extends ListenerAdapter {

private final MeetingRepository meetingRepository;

public MeetingButtonController(MeetingRepository meetingRepository) {
this.meetingRepository = meetingRepository;
}

@Override
public void onButtonInteraction(ButtonInteractionEvent event) {

}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eternalcode.discordapp.meeting;
package com.eternalcode.discordapp.meeting.controller;

import com.eternalcode.discordapp.config.AppConfig;
import com.eternalcode.discordapp.meeting.Meeting;
import com.eternalcode.discordapp.meeting.event.MeetingCreateEvent;
import com.eternalcode.discordapp.observer.Observer;
import com.eternalcode.discordapp.util.DiscordTagFormat;
Expand All @@ -10,6 +11,7 @@
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.buttons.Button;

import java.awt.*;
Expand Down Expand Up @@ -70,8 +72,10 @@ public void update(MeetingCreateEvent event) {
.setTimestamp(meeting.getIssuedAt())
.build();

Button presentButton = Button.primary("meeting:present:" + meeting.getIssuedAt().toEpochMilli(), "Present");
Button absentButton = Button.danger("meeting:absent:" + meeting.getIssuedAt().toEpochMilli(), "Absent");
Button presentButton = Button.primary("meeting:present:" + meeting.getIssuedAt().toEpochMilli(), "Present")
.withEmoji(Emoji.fromUnicode("✅"));
Button absentButton = Button.danger("meeting:absent:" + meeting.getIssuedAt().toEpochMilli(), "Absent")
.withEmoji(Emoji.fromUnicode("✖"));

textChannelById
.sendMessageEmbeds(embed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.sentry.Sentry;

import java.sql.SQLException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

public class MeetingRepositoryImpl extends AbstractRepository<Meeting, Long> implements MeetingRepository {
Expand All @@ -25,23 +26,21 @@ public static MeetingRepository create(DatabaseManager databaseManager) {
throw new DataAccessException("Failed to create table", sqlException);
}


return new MeetingRepositoryImpl(databaseManager);
}

@Override
public CompletableFuture<Meeting> findMeeting(Meeting meeting) {
return null;
return this.select(meeting.getRequesterId()).thenApply(Optional::get);
}

@Override
public CompletableFuture<Meeting> saveMeeting(Meeting meeting) {
return null;
return this.save(meeting).thenApply(status -> meeting);
}

@Override
public CompletableFuture<Meeting> deleteMeeting(Meeting meeting) {
return null;
return this.delete(meeting).thenApply(deleted -> meeting);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.j256.ormlite.table.DatabaseTable;

import java.time.Instant;
import java.util.HashSet;
import java.util.Set;

@DatabaseTable(tableName = "officer_meetings")
class MeetingWrapper {
Expand All @@ -21,14 +23,15 @@ class MeetingWrapper {

@DatabaseField(columnName = "startTime", dataType = DataType.SERIALIZABLE)
private Instant startTime;
/*
@DatabaseField(dataType = DataType.SERIALIZABLE)

@DatabaseField(columnName = "presentMembers", dataType = DataType.SERIALIZABLE)
private final Set<Long> presentMembers = new HashSet<>();

@DatabaseField(dataType = DataType.SERIALIZABLE)
private final Set<Long> absentMembers = new HashSet<>();*/
@DatabaseField(columnName = "absentMembers", dataType = DataType.SERIALIZABLE)
private final Set<Long> absentMembers = new HashSet<>();

public MeetingWrapper(Instant issuedAt, Instant startTime) {
public MeetingWrapper(long requesterId, Instant issuedAt, Instant startTime) {
this.requesterId = requesterId;
this.issuedAt = issuedAt;
this.startTime = startTime;
}
Expand All @@ -37,11 +40,11 @@ public MeetingWrapper() {
}

public static MeetingWrapper from(Meeting meeting) {
return new MeetingWrapper(meeting.getIssuedAt(), meeting.getStartTime());
return new MeetingWrapper(meeting.getRequesterId(), meeting.getIssuedAt(), meeting.getStartTime());
}

public Meeting toMeeting() {
return new Meeting(this.requesterId, this.issuedAt, this.startTime);
return new Meeting(this.requesterId, this.issuedAt, this.startTime, this.presentMembers, this.absentMembers);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.eternalcode.discordapp.meeting.event;

public record MeetingMemberAbsentEvent(Long absentUserId) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.eternalcode.discordapp.meeting.event;

public record MeetingMemberPresentEvent(Long presentUserId) {
}

0 comments on commit fce3e11

Please sign in to comment.