Commit 091d3974 authored by Ruben Bimberg's avatar Ruben Bimberg 💻
Browse files

Merge branch '104-implement-changes-for-brainstorming' into 'staging'

Resolve "Implement changes for brainstorming"

Closes #104

See merge request !158
parents 43334d2c 5f9cce48
Pipeline #92602 passed with stages
in 44 seconds
......@@ -47,6 +47,11 @@ public class RoomEventSource {
send(new BrainstormingVotesReset(payload, roomId));
}
public void sessionCategorizationReset(UUID sessionId, UUID roomId) {
BrainstormingCategorizationResetPayload payload = new BrainstormingCategorizationResetPayload(sessionId);
send(new BrainstormingCategorizationReset(payload, roomId));
}
public void sessionWordPatched(UUID wordId, UUID roomId, Map<String, Object> changes) {
BrainstormingWordPatchedPayload payload = new BrainstormingWordPatchedPayload(wordId, changes);
send(new BrainstormingWordPatched(payload, roomId));
......
......@@ -32,6 +32,7 @@ public class BrainstormingController extends AbstractEntityController {
private static final String DOWNVOTE_MAPPING = "/downvote";
private static final String RESET_VOTE_MAPPING = "/reset-vote";
private static final String RESET_RATING_MAPPING = "/reset-rating";
private static final String RESET_CATEGORIZATION_MAPPING = "/reset-categorization";
private static final String CATEGORY_MAPPING = "/category/{roomId}";
private static final String WORD_MAPPING = "/word/{word}";
......@@ -123,6 +124,11 @@ public class BrainstormingController extends AbstractEntityController {
return commandHandler.handle(new ResetBrainstormingVotes(payload));
}
@PostMapping(GET_MAPPING + RESET_CATEGORIZATION_MAPPING)
public Mono<Void> deleteAllCategories(@PathVariable UUID id) {
ResetBrainstormingCategorizationPayload payload = new ResetBrainstormingCategorizationPayload(id);
return commandHandler.handle(new ResetBrainstormingCategorization(payload));
}
@PostMapping(FIND_MAPPING)
public Flux<BrainstormingSession> find(@RequestBody final FindQuery<BrainstormingSession> findQuery) {
......
......@@ -63,6 +63,17 @@ public class BrainstormingCommandHandler {
.then();
}
public Mono<Void> handle(ResetBrainstormingCategorization command) {
logger.trace("got new command: " + command.toString());
ResetBrainstormingCategorizationPayload payload = command.getPayload();
return wordRepository.resetBySessionId(payload.getSessionId())
.then(service.get(payload.getSessionId()))
.switchIfEmpty(Mono.error(NotFoundException::new))
.doOnSuccess(session -> eventer.sessionCategorizationReset(session.getId(), session.getRoomId()))
.then();
}
public Mono<BrainstormingSession> handle(CreateBrainstorming command) {
logger.trace("got new command: " + command.toString());
......
package de.thm.arsnova.frag.jetzt.backend.model.command;
public class ResetBrainstormingCategorization extends WebSocketCommand<ResetBrainstormingCategorizationPayload> {
public ResetBrainstormingCategorization() {
super(ResetBrainstormingCategorization.class.getSimpleName());
}
public ResetBrainstormingCategorization(ResetBrainstormingCategorizationPayload payload) {
super(ResetBrainstormingCategorization.class.getSimpleName());
this.payload = payload;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResetBrainstormingCategorization that = (ResetBrainstormingCategorization) o;
return this.getPayload().equals(that.getPayload());
}
}
package de.thm.arsnova.frag.jetzt.backend.model.command;
import de.thm.arsnova.frag.jetzt.backend.model.WebSocketPayload;
import java.util.Objects;
import java.util.UUID;
public class ResetBrainstormingCategorizationPayload implements WebSocketPayload {
private UUID sessionId;
public ResetBrainstormingCategorizationPayload() {
}
public ResetBrainstormingCategorizationPayload(UUID sessionId) {
this.sessionId = sessionId;
}
public UUID getSessionId() {
return sessionId;
}
public void setSessionId(UUID sessionId) {
this.sessionId = sessionId;
}
@Override
public String toString() {
return "ResetBrainstormingCategorizationPayload{" +
"sessionId=" + sessionId +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResetBrainstormingCategorizationPayload that = (ResetBrainstormingCategorizationPayload) o;
return Objects.equals(sessionId, that.sessionId);
}
@Override
public int hashCode() {
return Objects.hash(sessionId);
}
}
package de.thm.arsnova.frag.jetzt.backend.model.event;
import java.util.UUID;
public class BrainstormingCategorizationReset extends WebSocketEvent<BrainstormingCategorizationResetPayload> {
public BrainstormingCategorizationReset() {
super(BrainstormingCategorizationReset.class.getSimpleName());
}
public BrainstormingCategorizationReset(BrainstormingCategorizationResetPayload payload, UUID roomId) {
super(BrainstormingCategorizationReset.class.getSimpleName());
this.payload = payload;
this.roomId = roomId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BrainstormingCategorizationReset that = (BrainstormingCategorizationReset) o;
return this.getPayload().equals(that.getPayload());
}
}
package de.thm.arsnova.frag.jetzt.backend.model.event;
import de.thm.arsnova.frag.jetzt.backend.model.WebSocketPayload;
import java.util.Objects;
import java.util.UUID;
public class BrainstormingCategorizationResetPayload implements WebSocketPayload {
private UUID sessionId;
public BrainstormingCategorizationResetPayload() {
}
public BrainstormingCategorizationResetPayload(UUID sessionId) {
this.sessionId = sessionId;
}
public UUID getSessionId() {
return sessionId;
}
public void setSessionId(UUID sessionId) {
this.sessionId = sessionId;
}
@Override
public String toString() {
return "BrainstormingCategorizationResetPayload{" +
"sessionId=" + sessionId +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BrainstormingCategorizationResetPayload that = (BrainstormingCategorizationResetPayload) o;
return Objects.equals(sessionId, that.sessionId);
}
@Override
public int hashCode() {
return Objects.hash(sessionId);
}
}
package de.thm.arsnova.frag.jetzt.backend.service.persistence;
import de.thm.arsnova.frag.jetzt.backend.model.BrainstormingWord;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
......@@ -11,5 +12,8 @@ public interface BrainstormingWordRepository extends ReactiveCrudRepository<Brai
Flux<BrainstormingWord> findBySessionId(UUID sessionId);
@Query("UPDATE brainstorming_word SET category_id = NULL WHERE session_id = :sessionId;")
Mono<Void> resetBySessionId(UUID sessionId);
Mono<BrainstormingWord> findBySessionIdAndWord(UUID sessionId, String word);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment