Skip to content

Commit

Permalink
ajoute une compatibilité json
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Squelbut committed Sep 20, 2023
1 parent bef0b02 commit 752e11b
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 214 deletions.
37 changes: 19 additions & 18 deletions activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ package libwekan

import (
"context"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"time"
)

type ActivityID string
type Activity struct {
ID ActivityID `bson:"_id"`
UserID UserID `bson:"userId,omitempty"`
Username Username `bson:"username,omitempty"`
Type string `bson:"type,omitempty"`
MemberID UserID `bson:"memberId,omitempty"`
ActivityType string `bson:"activityType,omitempty"`
ActivityTypeID string `bson:"activityTypeID,omitempty"`
BoardID BoardID `bson:"boardId,omitempty"`
BoardLabelID BoardLabelID `bson:"labelId,omitEmpty"`
CardTitle string `bson:"cardTitle,omitempty"`
ListID ListID `bson:"listId,omitempty"`
ListName string `bson:"listName,omitempty"`
CardID CardID `bson:"cardId,omitempty"`
ID ActivityID `bson:"_id" json:"_id,omitempty"`
UserID UserID `bson:"userId,omitempty" json:"userId,omitempty,omitempty"`

Check failure on line 14 in activities.go

View workflow job for this annotation

GitHub Actions / Build & Test

SA5008: duplicate JSON option "omitempty" (staticcheck)
Username Username `bson:"username,omitempty" json:"username,omitempty,omitempty"`

Check failure on line 15 in activities.go

View workflow job for this annotation

GitHub Actions / Build & Test

SA5008: duplicate JSON option "omitempty" (staticcheck)
Type string `bson:"type,omitempty" json:"type,omitempty,omitempty"`

Check failure on line 16 in activities.go

View workflow job for this annotation

GitHub Actions / Build & Test

SA5008: duplicate JSON option "omitempty" (staticcheck)
MemberID UserID `bson:"memberId,omitempty" json:"memberId,omitempty,omitempty"`
ActivityType string `bson:"activityType,omitempty" json:"activityType,omitempty,omitempty"`
ActivityTypeID string `bson:"activityTypeID,omitempty" json:"activityTypeID,omitempty,omitempty"`
BoardID BoardID `bson:"boardId,omitempty" json:"boardId,omitempty,omitempty"`
BoardLabelID BoardLabelID `bson:"labelId,omitEmpty" json:"labelId,omitEmpty,omitempty"`

Check failure on line 21 in activities.go

View workflow job for this annotation

GitHub Actions / Build & Test

SA5008: unknown JSON option "omitEmpty" (staticcheck)
CardTitle string `bson:"cardTitle,omitempty" json:"cardTitle,omitempty,omitempty"`
ListID ListID `bson:"listId,omitempty" json:"listId,omitempty,omitempty"`
ListName string `bson:"listName,omitempty" json:"listName,omitempty,omitempty"`
CardID CardID `bson:"cardId,omitempty" json:"cardId,omitempty,omitempty"`
CommentID CommentID `bson:"commentId, omitempty"`
SwimlaneID SwimlaneID `bson:"swimlaneID,omitempty"`
SwimlaneName string `bson:"swimlaneName,omitempty"`
CreatedAt time.Time `bson:"createdAt"`
ModifiedAt time.Time `bson:"modifiedAt"`
SwimlaneID SwimlaneID `bson:"swimlaneID,omitempty" json:"swimlaneID,omitempty,omitempty"`
SwimlaneName string `bson:"swimlaneName,omitempty" json:"swimlaneName,omitempty,omitempty"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt,omitempty"`
ModifiedAt time.Time `bson:"modifiedAt" json:"modifiedAt,omitempty"`
}

func (activityID ActivityID) Check(ctx context.Context, wekan *Wekan) error {
Expand Down
64 changes: 32 additions & 32 deletions boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ import (

// Board représente un objet de la collection `boards`
type Board struct {
ID BoardID `bson:"_id"`
Title BoardTitle `bson:"title"`
Permission string `bson:"permission"`
Sort float64 `bson:"sort"`
Archived bool `bson:"archived"`
CreatedAt time.Time `bson:"createdAt"`
ModifiedAt time.Time `bson:"modifiedAt"`
Stars int `bson:"stars"`
Labels []BoardLabel `bson:"labels"`
Members []BoardMember `bson:"members"`
Color string `bson:"color"`
SubtasksDefaultBoardId *string `bson:"subtasksDefaultBoardId"`
SubtasksDefaultListId *string `bson:"subtasksDefaultListId"`
DateSettingsDefaultBoardId *string `bson:"dateSettingsDefaultBoardId"`
DateSettingsDefaultListId *string `bson:"dateSettingsDefaultListId"`
AllowsSubtasks bool `bson:"allowsSubtasks"`
ID BoardID `bson:"_id" json:"_id,omitempty"`
Title BoardTitle `bson:"title" json:"title,omitempty"`
Permission string `bson:"permission" json:"permission,omitempty"`
Sort float64 `bson:"sort" json:"sort,omitempty"`
Archived bool `bson:"archived" json:"archived,omitempty"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt,omitempty"`
ModifiedAt time.Time `bson:"modifiedAt" json:"modifiedAt,omitempty"`
Stars int `bson:"stars" json:"stars,omitempty"`
Labels []BoardLabel `bson:"labels" json:"labels,omitempty"`
Members []BoardMember `bson:"members" json:"members,omitempty"`
Color string `bson:"color" json:"color,omitempty"`
SubtasksDefaultBoardId *string `bson:"subtasksDefaultBoardId" json:"subtasksDefaultBoardId,omitempty"`
SubtasksDefaultListId *string `bson:"subtasksDefaultListId" json:"subtasksDefaultListId,omitempty"`
DateSettingsDefaultBoardId *string `bson:"dateSettingsDefaultBoardId" json:"dateSettingsDefaultBoardId,omitempty"`
DateSettingsDefaultListId *string `bson:"dateSettingsDefaultListId" json:"dateSettingsDefaultListId,omitempty"`
AllowsSubtasks bool `bson:"allowsSubtasks" json:"allowsSubtasks,omitempty"`
AllowsAttachments bool `json:"allowsAttachments"`
AllowsChecklists bool `json:"allowsChecklists"`
AllowsComments bool `json:"allowsComments"`
Expand All @@ -44,30 +44,30 @@ type Board struct {
AllowsStartDate bool `json:"allowsStartDate"`
AllowsEndDate bool `json:"allowsEndDate"`
AllowsDueDate bool `json:"allowsDueDate"`
PresentParentTask string `bson:"presentParentTask"`
IsOvertime bool `bson:"isOvertime"`
Type string `bson:"type"`
Slug BoardSlug `bson:"slug"`
Watchers []interface{} `bson:"watchers"`
AllowsCardNumber bool `bson:"allowsCardNumber"`
AllowsShowLists bool `bson:"allowsShowLists"`
PresentParentTask string `bson:"presentParentTask" json:"presentParentTask,omitempty"`
IsOvertime bool `bson:"isOvertime" json:"isOvertime,omitempty"`
Type string `bson:"type" json:"type,omitempty"`
Slug BoardSlug `bson:"slug" json:"slug,omitempty"`
Watchers []interface{} `bson:"watchers" json:"watchers,omitempty"`
AllowsCardNumber bool `bson:"allowsCardNumber" json:"allowsCardNumber,omitempty"`
AllowsShowLists bool `bson:"allowsShowLists" json:"allowsShowLists,omitempty"`
}

type BoardLabelID string
type BoardLabelName string
type BoardLabel struct {
ID BoardLabelID `bson:"_id"`
Name BoardLabelName `bson:"name"`
Color string `bson:"color"`
ID BoardLabelID `bson:"_id" json:"_id,omitempty"`
Name BoardLabelName `bson:"name" json:"name,omitempty"`
Color string `bson:"color" json:"color,omitempty"`
}

type BoardMember struct {
UserID UserID `bson:"userId"`
IsAdmin bool `bson:"isAdmin"`
IsActive bool `bson:"isActive"`
IsNoComments bool `bson:"isNoComments"`
IsCommentOnly bool `bson:"isCommentOnly"`
IsWorker bool `bson:"isWorker"`
UserID UserID `bson:"userId" json:"userId,omitempty"`
IsAdmin bool `bson:"isAdmin" json:"isAdmin,omitempty"`
IsActive bool `bson:"isActive" json:"isActive,omitempty"`
IsNoComments bool `bson:"isNoComments" json:"isNoComments,omitempty"`
IsCommentOnly bool `bson:"isCommentOnly" json:"isCommentOnly,omitempty"`
IsWorker bool `bson:"isWorker" json:"isWorker,omitempty"`
}

type BoardID string
Expand Down
113 changes: 57 additions & 56 deletions cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,84 @@ import (
"context"
"errors"
"fmt"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)

type CardID string

type Poker struct {
Question bool `bson:"question"`
One []string `bson:"one"`
Two []string `bson:"two"`
Three []string `bson:"three"`
Five []string `bson:"five"`
Eight []string `bson:"eight"`
Thirteen []string `bson:"thirteen"`
Twenty []string `bson:"twenty"`
Forty []string `bson:"forty"`
OneHundred []string `bson:"oneHundred"`
Unsure []string `bson:"unsure"`
End *bool `bson:"end"`
AllowNonBoardMembers bool `bson:"allowNonBoardMembers"`
Question bool `bson:"question" json:"question,omitempty"`
One []string `bson:"one" json:"one,omitempty"`
Two []string `bson:"two" json:"two,omitempty"`
Three []string `bson:"three" json:"three,omitempty"`
Five []string `bson:"five" json:"five,omitempty"`
Eight []string `bson:"eight" json:"eight,omitempty"`
Thirteen []string `bson:"thirteen" json:"thirteen,omitempty"`
Twenty []string `bson:"twenty" json:"twenty,omitempty"`
Forty []string `bson:"forty" json:"forty,omitempty"`
OneHundred []string `bson:"oneHundred" json:"oneHundred,omitempty"`
Unsure []string `bson:"unsure" json:"unsure,omitempty"`
End *bool `bson:"end" json:"end,omitempty"`
AllowNonBoardMembers bool `bson:"allowNonBoardMembers" json:"allowNonBoardMembers,omitempty"`
}

type Vote struct {
Question string `bson:"question"`
Positive []string `bson:"positive"`
Negative []string `bson:"negative"`
End *bool `bson:"end"`
Public bool `bson:"public"`
AllowNonBoardMembers bool `bson:"allowNonBoardMembers"`
Question string `bson:"question" json:"question,omitempty"`
Positive []string `bson:"positive" json:"positive,omitempty"`
Negative []string `bson:"negative" json:"negative,omitempty"`
End *bool `bson:"end" json:"end,omitempty"`
Public bool `bson:"public" json:"public,omitempty"`
AllowNonBoardMembers bool `bson:"allowNonBoardMembers" json:"allowNonBoardMembers,omitempty"`
}

type CardCustomFieldID string

type CardCustomField struct {
ID CardCustomFieldID `bson:"_id"`
Value string `bson:"value"`
ID CardCustomFieldID `bson:"_id" json:"_id,omitempty"`
Value string `bson:"value" json:"value,omitempty"`
}

type Card struct {
ID CardID `bson:"_id"`
Title string `bson:"title"`
Members []UserID `bson:"members"`
LabelIDs []BoardLabelID `bson:"labelIds"`
CustomFields []CardCustomField `bson:"customFields"`
ListID ListID `bson:"listId"`
BoardID BoardID `bson:"boardId"`
Sort float64 `bson:"sort"`
SwimlaneID SwimlaneID `bson:"swimlaneId"`
Type string `bson:"type"`
Archived bool `bson:"archived"`
ParentID CardID `bson:"parentId,omitempty"`
CoverID string `bson:"coverId"`
CreatedAt time.Time `bson:"createdAt"`
ModifiedAt time.Time `bson:"modifiedAt"`
DateLastActivity time.Time `bson:"dateLastActivity"`
Description string `bson:"description"`
RequestedBy UserID `bson:"requestedBy"`
AssignedBy UserID `bson:"assignedBy"`
Assignees []UserID `bson:"assignees"`
SpentTime int `bson:"spentTime"`
IsOverTime bool `bson:"isOvertime"`
UserID UserID `bson:"userId"`
SubtaskSort int `bson:"subtaskSort"`
LinkedID CardID `bson:"linkedId"`
Vote Vote `bson:"vote"`
Poker Poker `bson:"poker"`
TargetIDGantt []string `bson:"targetId_gantt"`
LinkTypeGantt []string `bson:"linkType_gantt"`
LinkIDGantt []string `bson:"linkId_gantt"`
StartAt time.Time `bson:"startAt"`
EndAt *time.Time `bson:"endAt"`
ID CardID `bson:"_id" json:"_id,omitempty"`
Title string `bson:"title" json:"title,omitempty"`
Members []UserID `bson:"members" json:"members,omitempty"`
LabelIDs []BoardLabelID `bson:"labelIds" json:"labelIds,omitempty"`
CustomFields []CardCustomField `bson:"customFields" json:"customFields,omitempty"`
ListID ListID `bson:"listId" json:"listId,omitempty"`
BoardID BoardID `bson:"boardId" json:"boardId,omitempty"`
Sort float64 `bson:"sort" json:"sort,omitempty"`
SwimlaneID SwimlaneID `bson:"swimlaneId" json:"swimlaneId,omitempty"`
Type string `bson:"type" json:"type,omitempty"`
Archived bool `bson:"archived" json:"archived,omitempty"`
ParentID CardID `bson:"parentId,omitempty" json:"parentId,omitempty,omitempty"`
CoverID string `bson:"coverId" json:"coverId,omitempty"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt,omitempty"`
ModifiedAt time.Time `bson:"modifiedAt" json:"modifiedAt,omitempty"`
DateLastActivity time.Time `bson:"dateLastActivity" json:"dateLastActivity,omitempty"`
Description string `bson:"description" json:"description,omitempty"`
RequestedBy UserID `bson:"requestedBy" json:"requestedBy,omitempty"`
AssignedBy UserID `bson:"assignedBy" json:"assignedBy,omitempty"`
Assignees []UserID `bson:"assignees" json:"assignees,omitempty"`
SpentTime int `bson:"spentTime" json:"spentTime,omitempty"`
IsOverTime bool `bson:"isOvertime" json:"isOvertime,omitempty"`
UserID UserID `bson:"userId" json:"userId,omitempty"`
SubtaskSort int `bson:"subtaskSort" json:"subtaskSort,omitempty"`
LinkedID CardID `bson:"linkedId" json:"linkedId,omitempty"`
Vote Vote `bson:"vote" json:"vote,omitempty"`
Poker Poker `bson:"poker" json:"poker,omitempty"`
TargetIDGantt []string `bson:"targetId_gantt" json:"targetId_gantt,omitempty"`
LinkTypeGantt []string `bson:"linkType_gantt" json:"linkType_gantt,omitempty"`
LinkIDGantt []string `bson:"linkId_gantt" json:"linkId_gantt,omitempty"`
StartAt time.Time `bson:"startAt" json:"startAt,omitempty"`
EndAt *time.Time `bson:"endAt" json:"endAt,omitempty"`
}

type CardWithComments struct {
Card Card `bson:"card"`
Comments []Comment `bson:"comments"`
Card Card `bson:"card" json:"card,omitempty"`
Comments []Comment `bson:"comments" json:"comments,omitempty"`
}

func BuildCard(boardID BoardID, listID ListID, swimlaneID SwimlaneID, title string, description string, userID UserID) Card {
Expand Down
14 changes: 7 additions & 7 deletions comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "time"
type CommentID string

type Comment struct {
ID CommentID `bson:"_id"`
BoardID BoardID `bson:"boardId"`
CardID CardID `bson:"cardId"`
CreatedAt time.Time `bson:"createdAt"`
ModifiedAt time.Time `bson:"modifiedAt"`
Text string `bson:"text"`
UserID UserID `bson:"userId"`
ID CommentID `bson:"_id" json:"_id,omitempty"`
BoardID BoardID `bson:"boardId" json:"boardId,omitempty"`
CardID CardID `bson:"cardId" json:"cardId,omitempty"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt,omitempty"`
ModifiedAt time.Time `bson:"modifiedAt" json:"modifiedAt,omitempty"`
Text string `bson:"text" json:"text,omitempty"`
UserID UserID `bson:"userId" json:"userId,omitempty"`
}
13 changes: 7 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ package libwekan
import (
"context"
"fmt"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type ConfigCustomFields map[CardCustomFieldID]CustomField

type ConfigBoard struct {
Board Board `bson:"board"`
Swimlanes map[SwimlaneID]Swimlane `bson:"swimlanes"`
Lists map[ListID]List `bson:"lists"`
CustomFields ConfigCustomFields `bson:"customFields"`
Board Board `bson:"board" json:"board,omitempty"`
Swimlanes map[SwimlaneID]Swimlane `bson:"swimlanes" json:"swimlanes,omitempty"`
Lists map[ListID]List `bson:"lists" json:"lists,omitempty"`
CustomFields ConfigCustomFields `bson:"customFields" json:"customFields,omitempty"`
}

type Config struct {
Boards map[BoardID]ConfigBoard `bson:"boards"`
Users map[UserID]User `bson:"users"`
Boards map[BoardID]ConfigBoard `bson:"boards" json:"boards,omitempty"`
Users map[UserID]User `bson:"users" json:"users,omitempty"`
}

func (fields ConfigCustomFields) CustomFieldID(fieldName string) CardCustomFieldID {
Expand Down
8 changes: 4 additions & 4 deletions custom_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package libwekan
import "time"

type CustomField struct {
ID CardCustomFieldID `bson:"_id"`
ID CardCustomFieldID `bson:"_id" json:"_id,omitempty"`
Name string
Type string
Settings CustomFieldSettings
Expand All @@ -18,7 +18,7 @@ type CustomField struct {

type CustomFieldSettings struct {
DropdownItems []struct {
ID string `bson:"_id"`
Name string `bson:"name"`
} `bson:"dropdownItems"`
ID string `bson:"_id" json:"_id,omitempty"`
Name string `bson:"name" json:"name,omitempty"`
} `bson:"dropdownItems" json:"dropdownItems,omitempty"`
}
35 changes: 18 additions & 17 deletions lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@ package libwekan

import (
"context"
"go.mongodb.org/mongo-driver/bson"
"time"

"go.mongodb.org/mongo-driver/bson"
)

// ListID porte bien son nom
type ListID string

type ListWipLimit struct {
Value int `bson:"value"`
Enabled bool `bson:"enabled"`
Soft bool `bson:"soft"`
Value int `bson:"value" json:"value,omitempty"`
Enabled bool `bson:"enabled" json:"enabled,omitempty"`
Soft bool `bson:"soft" json:"soft,omitempty"`
}

type List struct {
ID ListID `bson:"_id"`
Title string `bson:"title"`
BoardID BoardID `bson:"boardId"`
Sort float64 `bson:"sort"`
Type string `bson:"type"`
Starred bool `bson:"starred"`
Archived bool `bson:"archived"`
SwimlaneID string `bson:"swimlaneId"`
Width string `bson:"width"`
CreatedAt time.Time `bson:"createdAt"`
UpdatedAt time.Time `bson:"updatedAt"`
ModifiedAt time.Time `bson:"modifiedAt"`
WipLimit ListWipLimit `bson:"wipLimit"`
ID ListID `bson:"_id" json:"_id,omitempty"`
Title string `bson:"title" json:"title,omitempty"`
BoardID BoardID `bson:"boardId" json:"boardId,omitempty"`
Sort float64 `bson:"sort" json:"sort,omitempty"`
Type string `bson:"type" json:"type,omitempty"`
Starred bool `bson:"starred" json:"starred,omitempty"`
Archived bool `bson:"archived" json:"archived,omitempty"`
SwimlaneID string `bson:"swimlaneId" json:"swimlaneId,omitempty"`
Width string `bson:"width" json:"width,omitempty"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt,omitempty"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt,omitempty"`
ModifiedAt time.Time `bson:"modifiedAt" json:"modifiedAt,omitempty"`
WipLimit ListWipLimit `bson:"wipLimit" json:"wipLimit,omitempty"`
}

func BuildList(boardID BoardID, title string, sort float64) List {
Expand Down
Loading

0 comments on commit 752e11b

Please sign in to comment.