feat: init project

This commit is contained in:
Steven
2022-09-11 16:38:06 +08:00
commit 5f48be3b7a
48 changed files with 4585 additions and 0 deletions

21
api/api.go Normal file
View File

@ -0,0 +1,21 @@
package api
// RowStatus is the status for a row.
type RowStatus string
const (
// Normal is the status for a normal row.
Normal RowStatus = "NORMAL"
// Archived is the status for an archived row.
Archived RowStatus = "ARCHIVED"
)
func (e RowStatus) String() string {
switch e {
case Normal:
return "NORMAL"
case Archived:
return "ARCHIVED"
}
return ""
}

12
api/auth.go Normal file
View File

@ -0,0 +1,12 @@
package api
type Signup struct {
Email string `json:"email"`
Name string `json:"name"`
Password string `json:"password"`
}
type Signin struct {
Email string `json:"email"`
Password string `json:"password"`
}

20
api/cache.go Normal file
View File

@ -0,0 +1,20 @@
package api
// CacheNamespace is the type of a cache.
type CacheNamespace string
const (
// UserCache is the cache type of workspaces.
WorkspaceCache CacheNamespace = "w"
// UserCache is the cache type of users.
UserCache CacheNamespace = "u"
// ShortcutCache is the cache type of shortcuts.
ShortcutCache CacheNamespace = "s"
)
// CacheService is the service for caches.
type CacheService interface {
FindCache(namespace CacheNamespace, id int, entry interface{}) (bool, error)
UpsertCache(namespace CacheNamespace, id int, entry interface{}) error
DeleteCache(namespace CacheNamespace, id int)
}

77
api/shortcut.go Normal file
View File

@ -0,0 +1,77 @@
package api
// Visibility is the type of a visibility.
type Visibility string
const (
// VisibilityWorkspace is the WORKSPACE visibility.
VisibilityWorkspace Visibility = "WORKSPACE"
// VisibilityPrivite is the PRIVATE visibility.
VisibilityPrivite Visibility = "PRIVATE"
)
func (e Visibility) String() string {
switch e {
case VisibilityWorkspace:
return "WORKSPACE"
case VisibilityPrivite:
return "PRIVATE"
}
return "PRIVATE"
}
type Shortcut struct {
ID int `json:"id"`
// Standard fields
CreatorID int `json:"creatorId"`
CreatedTs int64 `json:"createdTs"`
UpdatedTs int64 `json:"updatedTs"`
WorkspaceID int `json:"workspaceId"`
RowStatus RowStatus `json:"rowStatus"`
// Domain specific fields
Name string `json:"name"`
Link string `json:"link"`
Visibility Visibility `json:"visibility"`
}
type ShortcutCreate struct {
// Standard fields
CreatorID int
WorkspaceID int `json:"workspaceId"`
// Domain specific fields
Name string `json:"name"`
Link string `json:"link"`
Visibility Visibility `json:"visibility"`
}
type ShortcutPatch struct {
ID int
// Standard fields
RowStatus *RowStatus `json:"rowStatus"`
// Domain specific fields
Name *string `json:"name"`
Link *string `json:"link"`
Visibility *Visibility `json:"visibility"`
}
type ShortcutFind struct {
ID *int
// Standard fields
CreatorID *int `json:"creatorId"`
WorkspaceID *int `json:"workspaceId"`
// Domain specific fields
Name *string `json:"name"`
Link *string `json:"link"`
Visibility *Visibility `json:"visibility"`
}
type ShortcutDelete struct {
ID int
}

18
api/shortcut_organizer.go Normal file
View File

@ -0,0 +1,18 @@
package api
type ShortcutOrganizer struct {
ShortcutID int
UserID int
Pinned bool
}
type ShortcutOrganizerFind struct {
ShortcutID int
UserID int
}
type ShortcutOrganizerUpsert struct {
ShortcutID int
UserID int
Pinned bool `json:"pinned"`
}

7
api/system.go Normal file
View File

@ -0,0 +1,7 @@
package api
import "github.com/boojack/corgi/server/profile"
type SystemStatus struct {
Profile *profile.Profile `json:"profile"`
}

71
api/user.go Normal file
View File

@ -0,0 +1,71 @@
package api
import (
"fmt"
"github.com/boojack/corgi/common"
)
type User struct {
ID int `json:"id"`
// Standard fields
CreatedTs int64 `json:"createdTs"`
UpdatedTs int64 `json:"updatedTs"`
RowStatus RowStatus `json:"rowStatus"`
// Domain specific fields
Email string `json:"email"`
Name string `json:"name"`
PasswordHash string `json:"-"`
UserSettingList []*UserSetting `json:"userSettingList"`
}
type UserCreate struct {
Email string `json:"email"`
Name string `json:"name"`
Password string `json:"password"`
PasswordHash string
}
func (create UserCreate) Validate() error {
if !common.ValidateEmail(create.Email) {
return fmt.Errorf("invalid email format")
}
if len(create.Email) < 6 {
return fmt.Errorf("email is too short, minimum length is 6")
}
if len(create.Password) < 6 {
return fmt.Errorf("password is too short, minimum length is 6")
}
return nil
}
type UserPatch struct {
ID int
// Standard fields
RowStatus *RowStatus `json:"rowStatus"`
// Domain specific fields
Email *string `json:"email"`
Name *string `json:"name"`
Password *string `json:"password"`
PasswordHash *string
}
type UserFind struct {
ID *int `json:"id"`
// Standard fields
RowStatus *RowStatus `json:"rowStatus"`
// Domain specific fields
Email *string `json:"email"`
Name *string `json:"name"`
}
type UserDelete struct {
ID int
}

70
api/user_setting.go Normal file
View File

@ -0,0 +1,70 @@
package api
import (
"encoding/json"
"fmt"
)
type UserSettingKey string
const (
// UserSettingLocaleKey is the key type for user locale.
UserSettingLocaleKey UserSettingKey = "locale"
)
// String returns the string format of UserSettingKey type.
func (key UserSettingKey) String() string {
switch key {
case UserSettingLocaleKey:
return "locale"
}
return ""
}
var (
UserSettingLocaleValue = []string{"en", "zh"}
)
type UserSetting struct {
UserID int
Key UserSettingKey `json:"key"`
// Value is a JSON string with basic value
Value string `json:"value"`
}
type UserSettingUpsert struct {
UserID int
Key UserSettingKey `json:"key"`
Value string `json:"value"`
}
func (upsert UserSettingUpsert) Validate() error {
if upsert.Key == UserSettingLocaleKey {
localeValue := "en"
err := json.Unmarshal([]byte(upsert.Value), &localeValue)
if err != nil {
return fmt.Errorf("failed to unmarshal user setting locale value")
}
invalid := true
for _, value := range UserSettingLocaleValue {
if localeValue == value {
invalid = false
break
}
}
if invalid {
return fmt.Errorf("invalid user setting locale value")
}
} else {
return fmt.Errorf("invalid user setting key")
}
return nil
}
type UserSettingFind struct {
UserID int
Key *UserSettingKey `json:"key"`
}

50
api/workspace.go Normal file
View File

@ -0,0 +1,50 @@
package api
type Workspace struct {
ID int `json:"id"`
// Standard fields
CreatorID int `json:"creatorId"`
CreatedTs int64 `json:"createdTs"`
UpdatedTs int64 `json:"updatedTs"`
RowStatus RowStatus `json:"rowStatus"`
// Domain specific fields
Name string `json:"name"`
Description string `json:"description"`
}
type WorkspaceCreate struct {
CreatorID int
Name string `json:"name"`
Description string `json:"description"`
}
type WorkspacePatch struct {
ID int
// Standard fields
RowStatus *RowStatus `json:"rowStatus"`
// Domain specific fields
Name *string `json:"name"`
Description *string `json:"description"`
}
type WorkspaceFind struct {
ID *int `json:"id"`
// Standard fields
RowStatus *RowStatus `json:"rowStatus"`
// Domain specific fields
Name *string `json:"name"`
// Related fields
MemberID *int
}
type WorkspaceDelete struct {
ID int
}

46
api/workspace_user.go Normal file
View File

@ -0,0 +1,46 @@
package api
// Role is the type of a role.
type Role string
const (
// RoleAdmin is the ADMIN role.
RoleAdmin Role = "ADMIN"
// RoleUser is the USER role.
RoleUser Role = "USER"
)
func (e Role) String() string {
switch e {
case RoleAdmin:
return "ADMIN"
case RoleUser:
return "USER"
}
return "USER"
}
type WorkspaceUser struct {
WorkspaceID int `json:"workspaceId"`
UserID int `json:"userId"`
Role Role `json:"role"`
CreatedTs int64 `json:"createdTs"`
UpdatedTs int64 `json:"updatedTs"`
}
type WorkspaceUserUpsert struct {
WorkspaceID int `json:"workspaceId"`
UserID int `json:"userId"`
Role Role `json:"role"`
UpdatedTs int64 `json:"updatedTs"`
}
type WorkspaceUserFind struct {
WorkspaceID *int `json:"workspaceId"`
UserID *int `json:"userId"`
}
type WorkspaceUserDelete struct {
WorkspaceID int `json:"workspaceId"`
UserID int `json:"userId"`
}