1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-24 13:43:12 +02:00

Move BlockType2IDType from utils to model (#1744)

This commit is contained in:
Doug Lauder 2021-11-03 12:01:39 -04:00 committed by GitHub
parent cadbaf5724
commit 849cc5c195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 17 deletions

View File

@ -6,6 +6,8 @@ package model
import (
"errors"
"strings"
"github.com/mattermost/focalboard/server/utils"
)
// BlockType represents a block type.
@ -24,6 +26,7 @@ func (bt BlockType) String() string {
return string(bt)
}
// BlockTypeFromString returns an appropriate BlockType for the specified string.
func BlockTypeFromString(s string) (BlockType, error) {
switch strings.ToLower(s) {
case "board":
@ -40,6 +43,21 @@ func BlockTypeFromString(s string) (BlockType, error) {
return TypeUnknown, ErrInvalidBlockType{s}
}
// BlockType2IDType returns an appropriate IDType for the specified BlockType.
func BlockType2IDType(blockType BlockType) utils.IDType {
switch blockType {
case TypeBoard:
return utils.IDTypeBoard
case TypeCard:
return utils.IDTypeCard
case TypeView:
return utils.IDTypeView
case TypeText, TypeComment:
return utils.IDTypeBlock
}
return utils.IDTypeNone
}
// ErrInvalidBlockType is returned wherever an invalid block type was provided.
type ErrInvalidBlockType struct {
Type string

View File

@ -4,8 +4,6 @@ import (
"encoding/json"
"time"
"github.com/mattermost/focalboard/server/model"
mm_model "github.com/mattermost/mattermost-server/v6/model"
)
@ -31,21 +29,6 @@ func NewID(idType IDType) string {
return string(idType) + mm_model.NewId()
}
// BlockType2IDType returns an appropriate IDType for the specified BlockType.
func BlockType2IDType(blockType model.BlockType) IDType {
switch blockType {
case model.TypeBoard:
return IDTypeBoard
case model.TypeCard:
return IDTypeCard
case model.TypeView:
return IDTypeView
case model.TypeText, model.TypeComment:
return IDTypeBlock
}
return IDTypeNone
}
// GetMillis is a convenience method to get milliseconds since epoch.
func GetMillis() int64 {
return mm_model.GetMillis()