@@ -2,15 +2,12 @@ package boards
22
33import (
44 "context"
5- "errors"
65 "fmt"
76
8- "scrumlr.io/server/sessions"
97 "scrumlr.io/server/votings"
108
119 "github.com/google/uuid"
1210 "github.com/uptrace/bun"
13- "scrumlr.io/server/columns"
1411 "scrumlr.io/server/common"
1512 "scrumlr.io/server/identifiers"
1613)
@@ -26,38 +23,12 @@ func NewBoardDatabase(database *bun.DB) BoardDatabase {
2623 return db
2724}
2825
29- func (d * DB ) CreateBoard (ctx context.Context , creator uuid.UUID , board DatabaseBoardInsert , columns []columns.DatabaseColumnInsert ) (DatabaseBoard , error ) {
30- boardInsert := d .db .NewInsert ().
31- Model (& board ).
32- Returning ("*" )
33-
34- if board .AccessPolicy == ByPassphrase && (board .Passphrase == nil || board .Salt == nil ) {
35- return DatabaseBoard {}, errors .New ("passphrase or salt may not be empty" )
36- } else if board .AccessPolicy != ByPassphrase && (board .Passphrase != nil || board .Salt != nil ) {
37- return DatabaseBoard {}, errors .New ("passphrase or salt should not be set for policies except 'BY_PASSPHRASE'" )
38- }
39-
40- session := sessions.DatabaseBoardSessionInsert {User : creator , Role : common .OwnerRole }
41-
26+ func (d * DB ) CreateBoard (ctx context.Context , board DatabaseBoardInsert ) (DatabaseBoard , error ) {
4227 var b DatabaseBoard
43- query := d .db .NewSelect ().With ("createdBoard" , boardInsert )
44- if len (columns ) > 0 {
45- for index := range columns {
46- newColumnIndex := index
47- columns [index ].Index = newColumnIndex
48- }
49-
50- query = query .With ("createdColumns" , d .db .NewInsert ().
51- Model (& columns ).
52- Value ("board" , "(SELECT id FROM \" createdBoard\" )" ))
53- }
54- err := query .
55- With ("createdSession" , d .db .NewInsert ().
56- Model (& session ).
57- Value ("board" , "(SELECT id FROM \" createdBoard\" )" )).
58- Table ("createdBoard" ).
59- Column ("*" ).
60- Scan (ctx , & b )
28+ _ , err := d .db .NewInsert ().
29+ Model (& board ).
30+ Returning ("*" ).
31+ Exec (ctx , & b )
6132
6233 return b , err
6334}
@@ -86,18 +57,6 @@ func (d *DB) UpdateBoard(ctx context.Context, update DatabaseBoardUpdate) (Datab
8657 query .Column ("description" )
8758 }
8859 if update .AccessPolicy != nil {
89- if * update .AccessPolicy == ByPassphrase && (update .Passphrase == nil || update .Salt == nil ) {
90- return DatabaseBoard {}, errors .New ("passphrase and salt should be set when access policy is updated" )
91- } else if * update .AccessPolicy != ByPassphrase && (update .Passphrase != nil || update .Salt != nil ) {
92- return DatabaseBoard {}, errors .New ("passphrase and salt should not be set if access policy is defined as 'BY_PASSPHRASE'" )
93- }
94-
95- if * update .AccessPolicy == ByInvite {
96- query .Where ("access_policy = ?" , ByInvite )
97- } else {
98- query .Where ("access_policy <> ?" , ByInvite )
99- }
100-
10160 query .Column ("access_policy" , "passphrase" , "salt" )
10261 }
10362 if update .ShowAuthors != nil {
0 commit comments