Skip to content

Commit

Permalink
Added table for SpectatorMembers in an Ensemble
Browse files Browse the repository at this point in the history
Updated EnsembleDbo to include spectators when mapping to/from Domain and Database objects
  • Loading branch information
tedyoung committed Oct 2, 2023
1 parent 943329d commit 77ae597
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
# Later

* Rename "accept" to "participate" [in rotation]
* Change storage of Member registrations from 3 separate Sets to a single Set,
where there's an Enum for each (PARTICIPANT, SPECTATOR, and DECLINED)
* Change storage of Member registrations from 3 separate Sets to a single Set, where there's an Enum for each (PARTICIPANT, SPECTATOR, and DECLINED)
* Convert Ensemble to use the Snapshot Persistence pattern

## UI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class EnsembleDbo {
@MappedCollection(idColumn = "ensemble_id")
private Set<DeclinedMember> declinedMembers = new HashSet<>();

@MappedCollection(idColumn = "ensemble_id")
private Set<SpectatorMember> spectatorMembers = new HashSet<>();

public static EnsembleDbo from(Ensemble ensemble) {
EnsembleDbo ensembleDbo = new EnsembleDbo();
if (ensemble.getId() != null) {
Expand All @@ -55,6 +58,10 @@ public static EnsembleDbo from(Ensemble ensemble) {
ensemble.declinedMembers()
.map(DeclinedMember::toEntityId)
.collect(Collectors.toSet()));
ensembleDbo.setSpectatorMembers(
ensemble.spectators()
.map(SpectatorMember::toEntityId)
.collect(Collectors.toSet()));
return ensembleDbo;
}

Expand All @@ -75,6 +82,10 @@ public Ensemble asEnsemble() {
.map(DeclinedMember::asMemberId)
.forEach(ensemble::declinedBy);

spectatorMembers.stream()
.map(SpectatorMember::asMemberId)
.forEach(ensemble::joinAsSpectator);

if (state.equalsIgnoreCase("COMPLETED")) {
ensemble.complete();
} else if (state.equalsIgnoreCase("CANCELED")) {
Expand Down Expand Up @@ -124,6 +135,14 @@ public void setDeclinedMembers(Set<DeclinedMember> declinedMembers) {
this.declinedMembers = declinedMembers;
}

public Set<SpectatorMember> getSpectatorMembers() {
return spectatorMembers;
}

public void setSpectatorMembers(Set<SpectatorMember> spectatorMembers) {
this.spectatorMembers = spectatorMembers;
}

public String getState() {
return state;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.jitterted.mobreg.adapter.out.jdbc;

import com.jitterted.mobreg.domain.MemberId;
import org.springframework.data.annotation.Id;

//equivalent to @Table("spectator_member") -- WARNING: Case-sensitive
public class SpectatorMember {
@Id
public Long memberId;

// this constructor is necessary for Spring Data JDBC to use the name of the public Long memberId
// otherwise it'd use the name of the parameter to the single-parameter constructor (???)
public SpectatorMember() {
}

public SpectatorMember(long id) {
this.memberId = id;
}

static SpectatorMember toEntityId(MemberId memberId) {
return new SpectatorMember(memberId.id());
}

MemberId asMemberId() {
return MemberId.of(memberId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE declined_member
(
member_id BIGINT NOT NULL,
ensemble_id BIGINT NOT NULL
);
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void databaseEntityToDomainIsMappedCorrectly() throws Exception {
ensembleDbo.setConferenceStartUrl("entityStartUrl");
ensembleDbo.setAcceptedMembers(Set.of(new AcceptedMember(13L)));
ensembleDbo.setDeclinedMembers(Set.of(new DeclinedMember(29L)));
ensembleDbo.setSpectatorMembers(Set.of(new SpectatorMember(37L)));

Ensemble ensemble = ensembleDbo.asEnsemble();

Expand All @@ -48,6 +49,9 @@ public void databaseEntityToDomainIsMappedCorrectly() throws Exception {
assertThat(ensemble.declinedMembers())
.extracting(MemberId::id)
.isEqualTo(List.of(29L));
assertThat(ensemble.spectators())
.extracting(MemberId::id)
.isEqualTo(List.of(37L));
}

@Test
Expand All @@ -58,6 +62,7 @@ public void domainToDatabaseEntityIsMappedCorrectly() throws Exception {
ensemble.linkToRecordingAt(URI.create("https://recording.link/domain"));
ensemble.acceptedBy(MemberId.of(11L));
ensemble.declinedBy(MemberId.of(13L));
ensemble.joinAsSpectator(MemberId.of(19L));
ensemble.complete();

EnsembleDbo entity = EnsembleDbo.from(ensemble);
Expand All @@ -84,6 +89,10 @@ public void domainToDatabaseEntityIsMappedCorrectly() throws Exception {
.extracting(DeclinedMember::asMemberId)
.extracting(MemberId::id)
.isEqualTo(List.of(13L));
assertThat(entity.getSpectatorMembers())
.extracting(SpectatorMember::asMemberId)
.extracting(MemberId::id)
.isEqualTo(List.of(19L));
}

}

0 comments on commit 77ae597

Please sign in to comment.