From 9ab224f70c9bee4ac9f446359a432f586e85c5ac Mon Sep 17 00:00:00 2001 From: Joshua Shoemaker Date: Tue, 13 Dec 2022 13:03:26 -0600 Subject: [PATCH] refact: rename Document Module structs and methods --- core/Document/Document.go | 2 +- core/Document/DocumentCollection.go | 4 +-- core/Document/DocumentGroup.go | 24 ++++++------- core/Document/Initialize.go | 8 ++--- core/Session/Organization.go | 4 +++ core/Session/Project.go | 6 ++++ core/Session/Session.go | 21 ++++++++++++ core/Session/User.go | 8 +++++ frontend/app/layout.tsx | 2 +- frontend/components/workspace/Sidebar.tsx | 2 +- .../context/Project/makeDefaultProject.ts | 4 +-- frontend/context/Project/provider.tsx | 4 +-- frontend/context/Project/types.ts | 4 +-- frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts | 2 +- frontend/wailsjs/wailsjs/go/models.ts | 8 ++--- ipc/Documents.go | 34 +++++++++---------- ipc/JsonEntities.go | 10 +++--- 17 files changed, 93 insertions(+), 54 deletions(-) create mode 100644 core/Session/Organization.go create mode 100644 core/Session/Project.go create mode 100644 core/Session/Session.go create mode 100644 core/Session/User.go diff --git a/core/Document/Document.go b/core/Document/Document.go index 8f623b2..8cd1980 100644 --- a/core/Document/Document.go +++ b/core/Document/Document.go @@ -1,6 +1,6 @@ package document -type Document struct { +type Entity struct { Id string GroupId string Name string diff --git a/core/Document/DocumentCollection.go b/core/Document/DocumentCollection.go index 09f756a..58023f7 100644 --- a/core/Document/DocumentCollection.go +++ b/core/Document/DocumentCollection.go @@ -1,7 +1,7 @@ package document type DocumentCollection struct { - Documents []Document + Documents []Entity ProjectId string } @@ -15,6 +15,6 @@ func GetDocumentCollection() *DocumentCollection { return documentCollectionInstance } -func (collection *DocumentCollection) AddDocument(document Document) { +func (collection *DocumentCollection) AddDocument(document Entity) { collection.Documents = append(collection.Documents, document) } diff --git a/core/Document/DocumentGroup.go b/core/Document/DocumentGroup.go index 2d34c62..71244c1 100644 --- a/core/Document/DocumentGroup.go +++ b/core/Document/DocumentGroup.go @@ -1,28 +1,28 @@ package document -type DocumentGroup struct { +type Group struct { Id string ParentId string ProjectId string Name string } -type DocumentGroupCollection struct { - Id string - DocumentGroups []DocumentGroup - ProjectId string +type GroupCollection struct { + Id string + Groups []Group + ProjectId string } -var documentGroupCollectionInstance *DocumentGroupCollection +var groupCollectionInstance *GroupCollection -func GetDocumentGroupCollection() *DocumentGroupCollection { - if documentGroupCollectionInstance == nil { - documentGroupCollectionInstance = &DocumentGroupCollection{} +func GetGroupCollection() *GroupCollection { + if groupCollectionInstance == nil { + groupCollectionInstance = &GroupCollection{} } - return documentGroupCollectionInstance + return groupCollectionInstance } -func (collection *DocumentGroupCollection) AddDocumentGroup(group DocumentGroup) { - collection.DocumentGroups = append(collection.DocumentGroups, group) +func (collection *GroupCollection) AddDocumentGroup(group Group) { + collection.Groups = append(collection.Groups, group) } diff --git a/core/Document/Initialize.go b/core/Document/Initialize.go index f5dbc60..a3e074c 100644 --- a/core/Document/Initialize.go +++ b/core/Document/Initialize.go @@ -2,19 +2,19 @@ package document func InitizeModule() { GetDocumentCollection() - GetDocumentGroupCollection() + GetGroupCollection() } func createTestData() { documentCollection := GetDocumentCollection() - documentGroupCollection := GetDocumentGroupCollection() + documentGroupCollection := GetGroupCollection() - documentGroupCollection.AddDocumentGroup(DocumentGroup{ + documentGroupCollection.AddDocumentGroup(Group{ Id: "XYZ", Name: "Test Group One", }) - documentCollection.AddDocument(Document{ + documentCollection.AddDocument(Entity{ Id: "ABC", GroupId: "XYZ", Name: "My First Document", diff --git a/core/Session/Organization.go b/core/Session/Organization.go new file mode 100644 index 0000000..b906155 --- /dev/null +++ b/core/Session/Organization.go @@ -0,0 +1,4 @@ +package session + +type Organization struct { +} diff --git a/core/Session/Project.go b/core/Session/Project.go new file mode 100644 index 0000000..17b069c --- /dev/null +++ b/core/Session/Project.go @@ -0,0 +1,6 @@ +package session + +type Project struct { + Id string + Name string +} diff --git a/core/Session/Session.go b/core/Session/Session.go new file mode 100644 index 0000000..f504029 --- /dev/null +++ b/core/Session/Session.go @@ -0,0 +1,21 @@ +package session + +type session struct { + Project Project + Organization Organization + User User +} + +var sessionInstance *session + +func GetInstance() *session { + if sessionInstance == nil { + sessionInstance = &session{} + } + return sessionInstance +} + +func InitializeModule(newSession session) *session { + sessionInstance = &newSession + return sessionInstance +} diff --git a/core/Session/User.go b/core/Session/User.go new file mode 100644 index 0000000..c5410e4 --- /dev/null +++ b/core/Session/User.go @@ -0,0 +1,8 @@ +package session + +type User struct { + Id string + FirstName string + LastName string + Avatar string +} diff --git a/frontend/app/layout.tsx b/frontend/app/layout.tsx index 989e123..5aeaeab 100644 --- a/frontend/app/layout.tsx +++ b/frontend/app/layout.tsx @@ -15,7 +15,7 @@ export default function MainAppLayout({ children }: AppLayoutProps) { projectProps={{ id: '', documents: [] as ipc.Document[], - groups: [] as ipc.DocumentGroup[] + groups: [] as ipc.Group[] }}> {children} diff --git a/frontend/components/workspace/Sidebar.tsx b/frontend/components/workspace/Sidebar.tsx index 325afd4..ab0b041 100644 --- a/frontend/components/workspace/Sidebar.tsx +++ b/frontend/components/workspace/Sidebar.tsx @@ -11,7 +11,7 @@ type NavigationItem = { children: { id: string, name: string }[] } -const getNavigationProps = (documents: ipc.Document[], groups: ipc.DocumentGroup[]): NavigationItem[] => { +const getNavigationProps = (documents: ipc.Document[], groups: ipc.Group[]): NavigationItem[] => { const groupsWithDocuments = groups.map(g => { const childrenDocuments = documents .filter(d => d.groupId === g.id) diff --git a/frontend/context/Project/makeDefaultProject.ts b/frontend/context/Project/makeDefaultProject.ts index 60370c7..72fc63d 100644 --- a/frontend/context/Project/makeDefaultProject.ts +++ b/frontend/context/Project/makeDefaultProject.ts @@ -4,9 +4,9 @@ import { ProjectContextType } from "./types" const makeDefaultProject = (): ProjectContextType => ({ id: '', documents: [] as ipc.Document[], - groups: [] as ipc.DocumentGroup[], + groups: [] as ipc.Group[], requestAddDocument: (groupId: string, documentName: string) => Promise.resolve(new ipc.Document()), - requestAddDocumentGroup: (groupName: string) => Promise.resolve(new ipc.DocumentGroup()) + requestAddDocumentGroup: (groupName: string) => Promise.resolve(new ipc.Group()) }) export default makeDefaultProject diff --git a/frontend/context/Project/provider.tsx b/frontend/context/Project/provider.tsx index af928cb..405df32 100644 --- a/frontend/context/Project/provider.tsx +++ b/frontend/context/Project/provider.tsx @@ -13,12 +13,12 @@ export function useProject() { type Props = { children: ReactNode, projectProps: ProjectProps } export function ProjectProvider({ children, projectProps }: Props) { const [ documents, setDocuments ] = useState(projectProps.documents) - const [ groups, setGroups ] = useState(projectProps.groups) + const [ groups, setGroups ] = useState(projectProps.groups) const updateDocuments = async () => { GetDocuments().then(response => { setDocuments(response.documents) - setGroups(response.documentGroups) + setGroups(response.groups) Promise.resolve(response) }) } diff --git a/frontend/context/Project/types.ts b/frontend/context/Project/types.ts index e6859cd..cd6401e 100644 --- a/frontend/context/Project/types.ts +++ b/frontend/context/Project/types.ts @@ -3,10 +3,10 @@ import { ipc } from "../../wailsjs/wailsjs/go/models" export type ProjectProps = { id: string, documents: ipc.Document[], - groups: ipc.DocumentGroup[], + groups: ipc.Group[], } export type ProjectContextType = { requestAddDocument: (groupId: string, documentName: string) => Promise, - requestAddDocumentGroup: (groupName: string) => Promise, + requestAddDocumentGroup: (groupName: string) => Promise, } & ProjectProps \ No newline at end of file diff --git a/frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts b/frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts index 3bd9f61..07d9c3d 100755 --- a/frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts +++ b/frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts @@ -6,4 +6,4 @@ export function GetDocuments():Promise; export function RequestAddDocument(arg1:string,arg2:string):Promise; -export function RequestAddDocumentGroup(arg1:string):Promise; +export function RequestAddDocumentGroup(arg1:string):Promise; diff --git a/frontend/wailsjs/wailsjs/go/models.ts b/frontend/wailsjs/wailsjs/go/models.ts index 749c195..4e1aff5 100755 --- a/frontend/wailsjs/wailsjs/go/models.ts +++ b/frontend/wailsjs/wailsjs/go/models.ts @@ -20,14 +20,14 @@ export namespace ipc { this.projectId = source["projectId"]; } } - export class DocumentGroup { + export class Group { id: string; parentId: string; projectId: string; name: string; static createFrom(source: any = {}) { - return new DocumentGroup(source); + return new Group(source); } constructor(source: any = {}) { @@ -40,7 +40,7 @@ export namespace ipc { } export class GetDocumentsResponse { documents: Document[]; - documentGroups: DocumentGroup[]; + groups: Group[]; static createFrom(source: any = {}) { return new GetDocumentsResponse(source); @@ -49,7 +49,7 @@ export namespace ipc { constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); this.documents = this.convertValues(source["documents"], Document); - this.documentGroups = this.convertValues(source["documentGroups"], DocumentGroup); + this.groups = this.convertValues(source["groups"], Group); } convertValues(a: any, classs: any, asMap: boolean = false): any { diff --git a/ipc/Documents.go b/ipc/Documents.go index 314e857..4aa597f 100644 --- a/ipc/Documents.go +++ b/ipc/Documents.go @@ -9,17 +9,17 @@ import ( ) type GetDocumentsResponse struct { - Documents []Document `json:"documents"` - DocumentGroups []DocumentGroup `json:"documentGroups"` + Documents []Document `json:"documents"` + Groups []Group `json:"groups"` } func (c *Channel) GetDocuments() GetDocumentsResponse { documents := document.GetDocumentCollection().Documents - documentGroups := document.GetDocumentGroupCollection().DocumentGroups + groups := document.GetGroupCollection().Groups response := GetDocumentsResponse{ - DocumentGroups: make([]DocumentGroup, 0), - Documents: make([]Document, 0), + Groups: make([]Group, 0), + Documents: make([]Document, 0), } for _, d := range documents { @@ -33,14 +33,14 @@ func (c *Channel) GetDocuments() GetDocumentsResponse { response.Documents = append(response.Documents, jsonDocument) } - for _, g := range documentGroups { - jsonGroup := DocumentGroup{ + for _, g := range groups { + jsonGroup := Group{ Id: g.Id, ParentId: g.ParentId, ProjectId: g.ProjectId, Name: g.Name, } - response.DocumentGroups = append(response.DocumentGroups, jsonGroup) + response.Groups = append(response.Groups, jsonGroup) } return response @@ -62,7 +62,7 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume return Document{} } - newDocument := document.Document{ + newDocument := document.Entity{ Id: uuid.NewString(), Name: documentName, Path: filePath, @@ -83,20 +83,20 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume return documentResponse } -func (c *Channel) RequestAddDocumentGroup(name string) DocumentGroup { - newDocumentGroup := document.DocumentGroup{ +func (c *Channel) RequestAddDocumentGroup(name string) Group { + newGroup := document.Group{ Id: uuid.NewString(), Name: name, ProjectId: "something else", } - document.GetDocumentGroupCollection().AddDocumentGroup(newDocumentGroup) + document.GetGroupCollection().AddDocumentGroup(newGroup) - response := DocumentGroup{ - Id: newDocumentGroup.Id, - Name: newDocumentGroup.Name, - ParentId: newDocumentGroup.ParentId, - ProjectId: newDocumentGroup.ProjectId, + response := Group{ + Id: newGroup.Id, + Name: newGroup.Name, + ParentId: newGroup.ParentId, + ProjectId: newGroup.ProjectId, } return response diff --git a/ipc/JsonEntities.go b/ipc/JsonEntities.go index f33266b..b7da0a9 100644 --- a/ipc/JsonEntities.go +++ b/ipc/JsonEntities.go @@ -13,15 +13,15 @@ type DocumentCollection struct { ProjectId string `json:"projectId"` } -type DocumentGroup struct { +type Group struct { Id string `json:"id"` ParentId string `json:"parentId"` ProjectId string `json:"projectId"` Name string `json:"name"` } -type DocumentGroupCollection struct { - Id string `json:"id"` - DocumentGroups []DocumentGroup `json:"groups"` - ProjectId string `json:"projectId"` +type GroupCollection struct { + Id string `json:"id"` + Groups []Group `json:"groups"` + ProjectId string `json:"projectId"` }