Skip to content

Commit

Permalink
change GetAllRumors to GetAllRumorParams
Browse files Browse the repository at this point in the history
  • Loading branch information
emonnin-epfl committed Jun 26, 2024
1 parent b737c4e commit 7920204
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 42 deletions.
19 changes: 14 additions & 5 deletions be1-go/internal/database/sqlite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ func newRumor(rumorID int, sender string, messages map[string][]mmessage.Message
}
}

func newRumorParams(rumorID int, sender string, messages map[string][]mmessage.Message, timestamp mrumor.RumorTimestamp) mrumor.ParamsRumor {
return mrumor.ParamsRumor{
RumorID: rumorID,
SenderID: sender,
Messages: messages,
Timestamp: timestamp,
}
}

func (s *SQLite) GetRumorTimestampHelper(tx *sql.Tx) (mrumor.RumorTimestamp, error) {

rows, err := tx.Query(selectRumorState)
Expand Down Expand Up @@ -441,7 +450,7 @@ func (s *SQLite) GetRumorTimestamp() (mrumor.RumorTimestamp, error) {
return timestamp, nil
}

func (s *SQLite) GetAllRumors() ([]mrumor.Rumor, error) {
func (s *SQLite) GetAllRumorParams() ([]mrumor.ParamsRumor, error) {
dbLock.Lock()
defer dbLock.Unlock()

Expand All @@ -464,7 +473,7 @@ func (s *SQLite) GetAllRumors() ([]mrumor.Rumor, error) {
}
defer rows.Close()

rumors := make([]mrumor.Rumor, 0)
params := make([]mrumor.ParamsRumor, 0)
for rows.Next() {
var rumorID int
var sender string
Expand All @@ -484,15 +493,15 @@ func (s *SQLite) GetAllRumors() ([]mrumor.Rumor, error) {
if err != nil {
return nil, err
}
rumor := newRumor(rumorID, sender, messages, timestamp)
rumors = append(rumors, rumor)
param := newRumorParams(rumorID, sender, messages, timestamp)
params = append(params, param)
}

if err = rows.Err(); err != nil {
return nil, poperrors.NewDatabaseIteratorErrorMsg(err.Error())
}

return rumors, nil
return params, nil
}

func (s *SQLite) GetMessagesFromRumorHelper(tx *sql.Tx, rumorID int, sender string) (map[string][]mmessage.Message, error) {
Expand Down
12 changes: 6 additions & 6 deletions be1-go/internal/database/sqlite/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,10 @@ func Test_SQLite_GetAllRumors(t *testing.T) {
err = lite.StoreFirstRumor()
require.NoError(t, err)

rumors, err := lite.GetAllRumors()
params, err := lite.GetAllRumorParams()
require.NoError(t, err)

require.Len(t, rumors, 0)
require.Len(t, params, 0)

timestamp0 := make(mrumor.RumorTimestamp)
timestamp0["sender1"] = 0
Expand All @@ -1114,10 +1114,10 @@ func Test_SQLite_GetAllRumors(t *testing.T) {
timestamp1["sender2"] = 0
err = lite.StoreRumor(0, "sender2", timestamp1, nil, nil)

rumors, err = lite.GetAllRumors()
params, err = lite.GetAllRumorParams()
require.NoError(t, err)

require.Len(t, rumors, 2)
require.Len(t, params, 2)

msg1 := generator.NewNothingMsg(t, "client1", nil)
err = lite.StoreMessageAndData("lao", msg1)
Expand All @@ -1132,8 +1132,8 @@ func Test_SQLite_GetAllRumors(t *testing.T) {
require.True(t, ok)
require.Equal(t, map[string][]mmessage.Message{"lao": {msg1}}, rumor.Params.Messages)

rumors, err = lite.GetAllRumors()
params, err = lite.GetAllRumorParams()
require.NoError(t, err)
require.Len(t, rumors, 3)
require.Len(t, params, 3)

}
46 changes: 46 additions & 0 deletions be1-go/internal/handler/answer/hanswer/mocks/message_handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 115 additions & 0 deletions be1-go/internal/handler/answer/hanswer/mocks/queries.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions be1-go/internal/handler/answer/hanswer/mocks/rumor_handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7920204

Please sign in to comment.