[MM-43781] Feature: boards insights (#3005)
* Add boilerplate functions and handlers for boards insights
* Fix function signatures to add 'duration' parameter, fix where clauses in db queries
* Fix where clause to include boards of which userId in parameter is a member
* Modify queries to work with sqlite, postgres, mysql
* Integration tests, and results of make generate
* Lint Fixes
* Add icons to board insights
* Lint fixes
* Format insights queries without squirrel to fix parameterization issues
* Add tests for sqlstore utility functions
* Improve team insights tests by creating 2 boards
* Refactor endpoints/app to adhere to developments in 7.0 release
* Refactor queries to use squirrel
* Lint fixes
* Fix client, integration tests
* Remove old integration tests
* Add storetests, refactor functions to handle authorized board_ids
* Make queries compatible with mysql, sqlite
* Add app tests
* Fix lint errors
* Revert makefile changes, fix docstring in api
* Lint fixes and doc correction suggested by @wiggin77
* Fix mock store call count error
* adding client code
* Make the following changes
- use serviceAPI to get user.Timezone
- rename licenseAndGuestUserCheck to insightPermissionGate, and handle returned error better
- validate page, perPage parameters aren't < 0
* Lint fix
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
2022-08-08 08:12:02 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
// BoardInsightsList is a response type with pagination support.
|
|
|
|
type BoardInsightsList struct {
|
|
|
|
mmModel.InsightsListData
|
|
|
|
Items []*BoardInsight `json:"items"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// BoardInsight gives insight into activities in a Board
|
|
|
|
// swagger:model
|
|
|
|
type BoardInsight struct {
|
|
|
|
// ID of the board
|
|
|
|
// required: true
|
|
|
|
BoardID string `json:"boardID"`
|
|
|
|
|
|
|
|
// icon of the board
|
|
|
|
// required: false
|
|
|
|
Icon string `json:"icon"`
|
|
|
|
|
|
|
|
// Title of the board
|
|
|
|
// required: false
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
|
|
|
// Metric of how active the board is
|
|
|
|
// required: true
|
|
|
|
ActivityCount string `json:"activityCount"`
|
|
|
|
|
|
|
|
// IDs of users active on the board
|
|
|
|
// required: true
|
2022-12-05 12:50:15 +01:00
|
|
|
ActiveUsers mmModel.StringArray `json:"activeUsers"`
|
[MM-43781] Feature: boards insights (#3005)
* Add boilerplate functions and handlers for boards insights
* Fix function signatures to add 'duration' parameter, fix where clauses in db queries
* Fix where clause to include boards of which userId in parameter is a member
* Modify queries to work with sqlite, postgres, mysql
* Integration tests, and results of make generate
* Lint Fixes
* Add icons to board insights
* Lint fixes
* Format insights queries without squirrel to fix parameterization issues
* Add tests for sqlstore utility functions
* Improve team insights tests by creating 2 boards
* Refactor endpoints/app to adhere to developments in 7.0 release
* Refactor queries to use squirrel
* Lint fixes
* Fix client, integration tests
* Remove old integration tests
* Add storetests, refactor functions to handle authorized board_ids
* Make queries compatible with mysql, sqlite
* Add app tests
* Fix lint errors
* Revert makefile changes, fix docstring in api
* Lint fixes and doc correction suggested by @wiggin77
* Fix mock store call count error
* adding client code
* Make the following changes
- use serviceAPI to get user.Timezone
- rename licenseAndGuestUserCheck to insightPermissionGate, and handle returned error better
- validate page, perPage parameters aren't < 0
* Lint fix
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
2022-08-08 08:12:02 +02:00
|
|
|
|
|
|
|
// ID of user who created the board
|
|
|
|
// required: true
|
|
|
|
CreatedBy string `json:"createdBy"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func BoardInsightsFromJSON(data io.Reader) []BoardInsight {
|
|
|
|
var boardInsights []BoardInsight
|
|
|
|
_ = json.NewDecoder(data).Decode(&boardInsights)
|
|
|
|
return boardInsights
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTopBoardInsightsListWithPagination adds a rank to each item in the given list of BoardInsight and checks if there is
|
|
|
|
// another page that can be fetched based on the given limit and offset. The given list of BoardInsight is assumed to be
|
|
|
|
// sorted by ActivityCount(score). Returns a BoardInsightsList.
|
|
|
|
func GetTopBoardInsightsListWithPagination(boards []*BoardInsight, limit int) *BoardInsightsList {
|
|
|
|
// Add pagination support
|
|
|
|
var hasNext bool
|
|
|
|
if limit != 0 && len(boards) == limit+1 {
|
|
|
|
hasNext = true
|
|
|
|
boards = boards[:len(boards)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
return &BoardInsightsList{InsightsListData: mmModel.InsightsListData{HasNext: hasNext}, Items: boards}
|
|
|
|
}
|