mirror of
https://github.com/mattermost/focalboard.git
synced 2024-11-27 08:31:20 +02:00
address review comments; return pointers to all structs; implement DBVersion
This commit is contained in:
parent
165d3c0fc1
commit
d1255cc76e
@ -6,10 +6,10 @@ func (a *App) GetBoardsForCompliance(opts model.QueryBoardsForComplianceOptions)
|
||||
return a.store.GetBoardsForCompliance(opts)
|
||||
}
|
||||
|
||||
func (a *App) GetBoardsComplianceHistory(opts model.QueryBoardsComplianceHistoryOptions) ([]model.BoardHistory, bool, error) {
|
||||
func (a *App) GetBoardsComplianceHistory(opts model.QueryBoardsComplianceHistoryOptions) ([]*model.BoardHistory, bool, error) {
|
||||
return a.store.GetBoardsComplianceHistory(opts)
|
||||
}
|
||||
|
||||
func (a *App) GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHistoryOptions) ([]model.BlockHistory, bool, error) {
|
||||
func (a *App) GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHistoryOptions) ([]*model.BlockHistory, bool, error) {
|
||||
return a.store.GetBlocksComplianceHistory(opts)
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func TestGetBoardsComplianceHistory(t *testing.T) {
|
||||
const perPage = 3
|
||||
_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, count)
|
||||
|
||||
boardHistory := make([]model.BoardHistory, 0, count)
|
||||
boardHistory := make([]*model.BoardHistory, 0, count)
|
||||
page := 0
|
||||
for {
|
||||
bchr, resp := clients.Admin.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, page, perPage)
|
||||
@ -319,7 +319,7 @@ func TestGetBlocksComplianceHistory(t *testing.T) {
|
||||
const perPage = 3
|
||||
board, _ := th.CreateBoardAndCards(testTeamID, model.BoardTypeOpen, count)
|
||||
|
||||
blockHistory := make([]model.BlockHistory, 0, count)
|
||||
blockHistory := make([]*model.BlockHistory, 0, count)
|
||||
page := 0
|
||||
for {
|
||||
bchr, resp := clients.Admin.GetBlocksComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, board.ID, page, perPage)
|
||||
|
@ -23,7 +23,7 @@ type BoardsComplianceHistoryResponse struct {
|
||||
|
||||
// The array of BoardHistory records.
|
||||
// required: true
|
||||
Results []BoardHistory `json:"results"`
|
||||
Results []*BoardHistory `json:"results"`
|
||||
}
|
||||
|
||||
// BlocksComplianceHistoryResponse is the response body to a request for blocks history.
|
||||
@ -35,7 +35,7 @@ type BlocksComplianceHistoryResponse struct {
|
||||
|
||||
// The array of BlockHistory records.
|
||||
// required: true
|
||||
Results []BlockHistory `json:"results"`
|
||||
Results []*BlockHistory `json:"results"`
|
||||
}
|
||||
|
||||
// BoardHistory provides information about the history of a board.
|
||||
|
50
server/model/mocks/propValueResolverMock.go
Normal file
50
server/model/mocks/propValueResolverMock.go
Normal file
@ -0,0 +1,50 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/mattermost/focalboard/server/model (interfaces: PropValueResolver)
|
||||
|
||||
// Package mocks is a generated GoMock package.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
model "github.com/mattermost/focalboard/server/model"
|
||||
)
|
||||
|
||||
// MockPropValueResolver is a mock of PropValueResolver interface.
|
||||
type MockPropValueResolver struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockPropValueResolverMockRecorder
|
||||
}
|
||||
|
||||
// MockPropValueResolverMockRecorder is the mock recorder for MockPropValueResolver.
|
||||
type MockPropValueResolverMockRecorder struct {
|
||||
mock *MockPropValueResolver
|
||||
}
|
||||
|
||||
// NewMockPropValueResolver creates a new mock instance.
|
||||
func NewMockPropValueResolver(ctrl *gomock.Controller) *MockPropValueResolver {
|
||||
mock := &MockPropValueResolver{ctrl: ctrl}
|
||||
mock.recorder = &MockPropValueResolverMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockPropValueResolver) EXPECT() *MockPropValueResolverMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetUserByID mocks base method.
|
||||
func (m *MockPropValueResolver) GetUserByID(arg0 string) (*model.User, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetUserByID", arg0)
|
||||
ret0, _ := ret[0].(*model.User)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetUserByID indicates an expected call of GetUserByID.
|
||||
func (mr *MockPropValueResolverMockRecorder) GetUserByID(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserByID", reflect.TypeOf((*MockPropValueResolver)(nil).GetUserByID), arg0)
|
||||
}
|
@ -80,8 +80,9 @@ type storeMetadata struct {
|
||||
}
|
||||
|
||||
var blacklistedStoreMethodNames = map[string]bool{
|
||||
"Shutdown": true,
|
||||
"DBType": true,
|
||||
"Shutdown": true,
|
||||
"DBType": true,
|
||||
"DBVersion": true,
|
||||
}
|
||||
|
||||
func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
|
@ -488,10 +488,10 @@ func (mr *MockStoreMockRecorder) GetBlocksByIDs(arg0 interface{}) *gomock.Call {
|
||||
}
|
||||
|
||||
// GetBlocksComplianceHistory mocks base method.
|
||||
func (m *MockStore) GetBlocksComplianceHistory(arg0 model.QueryBlocksComplianceHistoryOptions) ([]model.BlockHistory, bool, error) {
|
||||
func (m *MockStore) GetBlocksComplianceHistory(arg0 model.QueryBlocksComplianceHistoryOptions) ([]*model.BlockHistory, bool, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetBlocksComplianceHistory", arg0)
|
||||
ret0, _ := ret[0].([]model.BlockHistory)
|
||||
ret0, _ := ret[0].([]*model.BlockHistory)
|
||||
ret1, _ := ret[1].(bool)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
@ -656,10 +656,10 @@ func (mr *MockStoreMockRecorder) GetBoardMemberHistory(arg0, arg1, arg2 interfac
|
||||
}
|
||||
|
||||
// GetBoardsComplianceHistory mocks base method.
|
||||
func (m *MockStore) GetBoardsComplianceHistory(arg0 model.QueryBoardsComplianceHistoryOptions) ([]model.BoardHistory, bool, error) {
|
||||
func (m *MockStore) GetBoardsComplianceHistory(arg0 model.QueryBoardsComplianceHistoryOptions) ([]*model.BoardHistory, bool, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetBoardsComplianceHistory", arg0)
|
||||
ret0, _ := ret[0].([]model.BoardHistory)
|
||||
ret0, _ := ret[0].([]*model.BoardHistory)
|
||||
ret1, _ := ret[1].(bool)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
|
@ -47,7 +47,7 @@ func (s *SQLStore) getBoardsForCompliance(db sq.BaseRunner, opts model.QueryBoar
|
||||
return boards, hasMore, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBoardsComplianceHistory(db sq.BaseRunner, opts model.QueryBoardsComplianceHistoryOptions) ([]model.BoardHistory, bool, error) {
|
||||
func (s *SQLStore) getBoardsComplianceHistory(db sq.BaseRunner, opts model.QueryBoardsComplianceHistoryOptions) ([]*model.BoardHistory, bool, error) {
|
||||
queryDescendentLastUpdate := s.getQueryBuilder(db).
|
||||
Select("MAX(blk1.update_at)").
|
||||
From(s.tablePrefix + "blocks_history as blk1").
|
||||
@ -125,7 +125,7 @@ func (s *SQLStore) getBoardsComplianceHistory(db sq.BaseRunner, opts model.Query
|
||||
return history, hasMore, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksComplianceHistory(db sq.BaseRunner, opts model.QueryBlocksComplianceHistoryOptions) ([]model.BlockHistory, bool, error) {
|
||||
func (s *SQLStore) getBlocksComplianceHistory(db sq.BaseRunner, opts model.QueryBlocksComplianceHistoryOptions) ([]*model.BlockHistory, bool, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
Select(
|
||||
"bh.id",
|
||||
@ -188,11 +188,11 @@ func (s *SQLStore) getBlocksComplianceHistory(db sq.BaseRunner, opts model.Query
|
||||
return history, hasMore, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) boardsHistoryFromRows(rows *sql.Rows) ([]model.BoardHistory, error) {
|
||||
history := []model.BoardHistory{}
|
||||
func (s *SQLStore) boardsHistoryFromRows(rows *sql.Rows) ([]*model.BoardHistory, error) {
|
||||
history := []*model.BoardHistory{}
|
||||
|
||||
for rows.Next() {
|
||||
var boardHistory model.BoardHistory
|
||||
boardHistory := &model.BoardHistory{}
|
||||
|
||||
err := rows.Scan(
|
||||
&boardHistory.ID,
|
||||
@ -213,11 +213,11 @@ func (s *SQLStore) boardsHistoryFromRows(rows *sql.Rows) ([]model.BoardHistory,
|
||||
return history, nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) blocksHistoryFromRows(rows *sql.Rows) ([]model.BlockHistory, error) {
|
||||
history := []model.BlockHistory{}
|
||||
func (s *SQLStore) blocksHistoryFromRows(rows *sql.Rows) ([]*model.BlockHistory, error) {
|
||||
history := []*model.BlockHistory{}
|
||||
|
||||
for rows.Next() {
|
||||
var blockHistory model.BlockHistory
|
||||
blockHistory := &model.BlockHistory{}
|
||||
|
||||
err := rows.Scan(
|
||||
&blockHistory.ID,
|
||||
|
@ -143,11 +143,6 @@ func (s *SQLStore) CreateUser(user *model.User) (*model.User, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) DBVersion() string {
|
||||
return s.dBVersion()
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) DeleteBlock(blockID string, modifiedBy string) error {
|
||||
if s.dbType == model.SqliteDBType {
|
||||
return s.deleteBlock(s.db, blockID, modifiedBy)
|
||||
@ -343,7 +338,7 @@ func (s *SQLStore) GetBlocksByIDs(ids []string) ([]*model.Block, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHistoryOptions) ([]model.BlockHistory, bool, error) {
|
||||
func (s *SQLStore) GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHistoryOptions) ([]*model.BlockHistory, bool, error) {
|
||||
return s.getBlocksComplianceHistory(s.db, opts)
|
||||
|
||||
}
|
||||
@ -398,7 +393,7 @@ func (s *SQLStore) GetBoardMemberHistory(boardID string, userID string, limit ui
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetBoardsComplianceHistory(opts model.QueryBoardsComplianceHistoryOptions) ([]model.BoardHistory, bool, error) {
|
||||
func (s *SQLStore) GetBoardsComplianceHistory(opts model.QueryBoardsComplianceHistoryOptions) ([]*model.BoardHistory, bool, error) {
|
||||
return s.getBoardsComplianceHistory(s.db, opts)
|
||||
|
||||
}
|
||||
|
@ -127,6 +127,27 @@ func (s *SQLStore) DBType() string {
|
||||
return s.dbType
|
||||
}
|
||||
|
||||
// DBVersion returns the DB version used for the store.
|
||||
func (s *SQLStore) DBVersion() string {
|
||||
var sql string
|
||||
switch s.dbType {
|
||||
case model.SqliteDBType:
|
||||
sql = "SELECT sqlite_version() AS version;"
|
||||
default:
|
||||
sql = "SELECT version() AS version"
|
||||
}
|
||||
|
||||
row := s.db.QueryRow(sql)
|
||||
|
||||
var version string
|
||||
if err := row.Scan(&version); err != nil {
|
||||
s.logger.Error("error getting database version", mlog.Err(err))
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
return version
|
||||
}
|
||||
|
||||
func (s *SQLStore) getQueryBuilder(db sq.BaseRunner) sq.StatementBuilderType {
|
||||
builder := sq.StatementBuilder
|
||||
if s.dbType == model.PostgresDBType || s.dbType == model.SqliteDBType {
|
||||
|
@ -175,8 +175,8 @@ type Store interface {
|
||||
|
||||
// Compliance
|
||||
GetBoardsForCompliance(opts model.QueryBoardsForComplianceOptions) ([]*model.Board, bool, error)
|
||||
GetBoardsComplianceHistory(opts model.QueryBoardsComplianceHistoryOptions) ([]model.BoardHistory, bool, error)
|
||||
GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHistoryOptions) ([]model.BlockHistory, bool, error)
|
||||
GetBoardsComplianceHistory(opts model.QueryBoardsComplianceHistoryOptions) ([]*model.BoardHistory, bool, error)
|
||||
GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHistoryOptions) ([]*model.BlockHistory, bool, error)
|
||||
|
||||
// For unit testing only
|
||||
DeleteBoardRecord(boardID, modifiedBy string) error
|
||||
|
@ -177,7 +177,7 @@ func testGetBoardsComplianceHistory(t *testing.T, store store.Store) {
|
||||
}
|
||||
|
||||
reps := 0
|
||||
allHistories := make([]model.BoardHistory, 0)
|
||||
allHistories := make([]*model.BoardHistory, 0)
|
||||
|
||||
for {
|
||||
reps++
|
||||
@ -271,7 +271,7 @@ func testGetBlocksComplianceHistory(t *testing.T, store store.Store) {
|
||||
}
|
||||
|
||||
reps := 0
|
||||
allHistories := make([]model.BlockHistory, 0)
|
||||
allHistories := make([]*model.BlockHistory, 0)
|
||||
|
||||
for {
|
||||
reps++
|
||||
|
@ -131,7 +131,7 @@ func extractIDs(t *testing.T, arr ...any) []string {
|
||||
ids = append(ids, b.ID)
|
||||
}
|
||||
}
|
||||
case []model.BoardHistory:
|
||||
case []*model.BoardHistory:
|
||||
for _, bh := range tarr {
|
||||
ids = append(ids, bh.ID)
|
||||
}
|
||||
@ -141,7 +141,7 @@ func extractIDs(t *testing.T, arr ...any) []string {
|
||||
ids = append(ids, b.ID)
|
||||
}
|
||||
}
|
||||
case []model.BlockHistory:
|
||||
case []*model.BlockHistory:
|
||||
for _, bh := range tarr {
|
||||
ids = append(ids, bh.ID)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user