Skip to content

Commit

Permalink
refactor: event_filter and do some refactorings
Browse files Browse the repository at this point in the history
and additional implementations

* try to simplify event_filter methods
  (some methods are redundant and can be removed
  for example filter or better updating votes per note),
* move some business (board, vote etc) specific structs
  and methods to new folder structure (vote specific stuff to vote),
* introduce technical helpers (should be only small methods) for
  unmarshal event data,
* reduce complexity of event_filter. use a switch case structure
  with small blocks to call the specific methods. every
  method returns a status in the form of true/false if
  the event is successful proceeded or not,
* every method have nearly the same structure now (
  easier to read and more maintainable now)
* encapsulate logic in business specific services (board, notes, votes etc),
* try to add some new unit tests,
* implement some helper methods like map and filter and add tests for them.
  • Loading branch information
wischoepke committed Jan 31, 2025
1 parent 015ffba commit e72b9a5
Show file tree
Hide file tree
Showing 29 changed files with 798 additions and 542 deletions.
25 changes: 14 additions & 11 deletions server/src/api/boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"errors"
"fmt"
"net/http"
"scrumlr.io/server/columns"
"scrumlr.io/server/notes"
"scrumlr.io/server/votes"
"strconv"

"scrumlr.io/server/identifiers"
Expand Down Expand Up @@ -315,14 +318,14 @@ func (s *Server) exportBoard(w http.ResponseWriter, r *http.Request) {
return
}

visibleColumns := []*dto.Column{}
var visibleColumns []*columns.Column
for _, column := range fullBoard.Columns {
if column.Visible {
visibleColumns = append(visibleColumns, column)
}
}

visibleNotes := []*dto.Note{}
var visibleNotes []*notes.Note
for _, note := range fullBoard.Notes {
for _, column := range visibleColumns {
if note.Position.Column == column.ID {
Expand All @@ -336,9 +339,9 @@ func (s *Server) exportBoard(w http.ResponseWriter, r *http.Request) {
render.Respond(w, r, struct {
Board *dto.Board `json:"board"`
Participants []*dto.BoardSession `json:"participants"`
Columns []*dto.Column `json:"columns"`
Notes []*dto.Note `json:"notes"`
Votings []*dto.Voting `json:"votings"`
Columns []*columns.Column `json:"columns"`
Notes []*notes.Note `json:"notes"`
Votings []*votes.Voting `json:"votings"`
}{
Board: fullBoard.Board,
Participants: fullBoard.BoardSessions,
Expand Down Expand Up @@ -459,11 +462,11 @@ func (s *Server) importBoard(w http.ResponseWriter, r *http.Request) {
}

type ParentChildNotes struct {
Parent dto.Note
Children []dto.Note
Parent notes.Note
Children []notes.Note
}
parentNotes := make(map[uuid.UUID]dto.Note)
childNotes := make(map[uuid.UUID][]dto.Note)
parentNotes := make(map[uuid.UUID]notes.Note)
childNotes := make(map[uuid.UUID][]notes.Note)

for _, note := range body.Notes {
if !note.Position.Stack.Valid {
Expand All @@ -480,7 +483,7 @@ func (s *Server) importBoard(w http.ResponseWriter, r *http.Request) {

note, err := s.notes.Import(r.Context(), dto.NoteImportRequest{
Text: parentNote.Text,
Position: dto.NotePosition{
Position: notes.NotePosition{
Column: cols[i].ID,
Stack: uuid.NullUUID{},
Rank: 0,
Expand Down Expand Up @@ -508,7 +511,7 @@ func (s *Server) importBoard(w http.ResponseWriter, r *http.Request) {
Text: note.Text,
Board: b.ID,
User: note.Author,
Position: dto.NotePosition{
Position: notes.NotePosition{
Column: node.Parent.Position.Column,
Rank: note.Position.Rank,
Stack: uuid.NullUUID{
Expand Down
21 changes: 12 additions & 9 deletions server/src/api/boards_listen_on_board.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package api
import (
"context"
"net/http"
"scrumlr.io/server/columns"
"scrumlr.io/server/notes"
"scrumlr.io/server/votes"

"scrumlr.io/server/identifiers"

Expand All @@ -18,8 +21,8 @@ type BoardSubscription struct {
clients map[uuid.UUID]*websocket.Conn
boardParticipants []*dto.BoardSession
boardSettings *dto.Board
boardColumns []*dto.Column
boardNotes []*dto.Note
boardColumns []*columns.Column
boardNotes []*notes.Note
boardReactions []*dto.Reaction
}

Expand All @@ -30,10 +33,10 @@ type InitEvent struct {

type EventData struct {
Board *dto.Board `json:"board"`
Columns []*dto.Column `json:"columns"`
Notes []*dto.Note `json:"notes"`
Columns []*columns.Column `json:"columns"`
Notes []*notes.Note `json:"notes"`
Reactions []*dto.Reaction `json:"reactions"`
Votings []*dto.Voting `json:"votings"`
Votings []*votes.Voting `json:"votings"`
Votes []*dto.Vote `json:"votes"`
Sessions []*dto.BoardSession `json:"participants"`
Requests []*dto.BoardSessionRequest `json:"requests"`
Expand Down Expand Up @@ -119,11 +122,11 @@ func (s *Server) listenOnBoard(boardID, userID uuid.UUID, conn *websocket.Conn,
}
}

func (b *BoardSubscription) startListeningOnBoard() {
for msg := range b.subscription {
func (bs *BoardSubscription) startListeningOnBoard() {
for msg := range bs.subscription {
logger.Get().Debugw("message received", "message", msg)
for id, conn := range b.clients {
filteredMsg := b.eventFilter(msg, id)
for id, conn := range bs.clients {
filteredMsg := bs.eventFilter(msg, id)
if err := conn.WriteJSON(filteredMsg); err != nil {
logger.Get().Warnw("failed to send message", "message", filteredMsg, "err", err)
}
Expand Down
Loading

0 comments on commit e72b9a5

Please sign in to comment.