refact: rename Document Module structs and methods
This commit is contained in:
parent
30693ccb3a
commit
9ab224f70c
@ -1,6 +1,6 @@
|
||||
package document
|
||||
|
||||
type Document struct {
|
||||
type Entity struct {
|
||||
Id string
|
||||
GroupId string
|
||||
Name string
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -1,28 +1,28 @@
|
||||
package document
|
||||
|
||||
type DocumentGroup struct {
|
||||
type Group struct {
|
||||
Id string
|
||||
ParentId string
|
||||
ProjectId string
|
||||
Name string
|
||||
}
|
||||
|
||||
type DocumentGroupCollection struct {
|
||||
type GroupCollection struct {
|
||||
Id string
|
||||
DocumentGroups []DocumentGroup
|
||||
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)
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
4
core/Session/Organization.go
Normal file
4
core/Session/Organization.go
Normal file
@ -0,0 +1,4 @@
|
||||
package session
|
||||
|
||||
type Organization struct {
|
||||
}
|
||||
6
core/Session/Project.go
Normal file
6
core/Session/Project.go
Normal file
@ -0,0 +1,6 @@
|
||||
package session
|
||||
|
||||
type Project struct {
|
||||
Id string
|
||||
Name string
|
||||
}
|
||||
21
core/Session/Session.go
Normal file
21
core/Session/Session.go
Normal file
@ -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
|
||||
}
|
||||
8
core/Session/User.go
Normal file
8
core/Session/User.go
Normal file
@ -0,0 +1,8 @@
|
||||
package session
|
||||
|
||||
type User struct {
|
||||
Id string
|
||||
FirstName string
|
||||
LastName string
|
||||
Avatar string
|
||||
}
|
||||
@ -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}
|
||||
</ProjectProvider>
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -13,12 +13,12 @@ export function useProject() {
|
||||
type Props = { children: ReactNode, projectProps: ProjectProps }
|
||||
export function ProjectProvider({ children, projectProps }: Props) {
|
||||
const [ documents, setDocuments ] = useState<ipc.Document[]>(projectProps.documents)
|
||||
const [ groups, setGroups ] = useState<ipc.DocumentGroup[]>(projectProps.groups)
|
||||
const [ groups, setGroups ] = useState<ipc.Group[]>(projectProps.groups)
|
||||
|
||||
const updateDocuments = async () => {
|
||||
GetDocuments().then(response => {
|
||||
setDocuments(response.documents)
|
||||
setGroups(response.documentGroups)
|
||||
setGroups(response.groups)
|
||||
Promise.resolve(response)
|
||||
})
|
||||
}
|
||||
|
||||
@ -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<ipc.Document>,
|
||||
requestAddDocumentGroup: (groupName: string) => Promise<ipc.DocumentGroup>,
|
||||
requestAddDocumentGroup: (groupName: string) => Promise<ipc.Group>,
|
||||
} & ProjectProps
|
||||
2
frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts
vendored
2
frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts
vendored
@ -6,4 +6,4 @@ export function GetDocuments():Promise<ipc.GetDocumentsResponse>;
|
||||
|
||||
export function RequestAddDocument(arg1:string,arg2:string):Promise<ipc.Document>;
|
||||
|
||||
export function RequestAddDocumentGroup(arg1:string):Promise<ipc.DocumentGroup>;
|
||||
export function RequestAddDocumentGroup(arg1:string):Promise<ipc.Group>;
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -10,15 +10,15 @@ import (
|
||||
|
||||
type GetDocumentsResponse struct {
|
||||
Documents []Document `json:"documents"`
|
||||
DocumentGroups []DocumentGroup `json:"documentGroups"`
|
||||
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),
|
||||
Groups: make([]Group, 0),
|
||||
Documents: make([]Document, 0),
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
type GroupCollection struct {
|
||||
Id string `json:"id"`
|
||||
DocumentGroups []DocumentGroup `json:"groups"`
|
||||
Groups []Group `json:"groups"`
|
||||
ProjectId string `json:"projectId"`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user