refact: rename Document Module structs and methods
This commit is contained in:
parent
30693ccb3a
commit
9ab224f70c
@ -1,6 +1,6 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
type Document struct {
|
type Entity struct {
|
||||||
Id string
|
Id string
|
||||||
GroupId string
|
GroupId string
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
type DocumentCollection struct {
|
type DocumentCollection struct {
|
||||||
Documents []Document
|
Documents []Entity
|
||||||
ProjectId string
|
ProjectId string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,6 +15,6 @@ func GetDocumentCollection() *DocumentCollection {
|
|||||||
return documentCollectionInstance
|
return documentCollectionInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *DocumentCollection) AddDocument(document Document) {
|
func (collection *DocumentCollection) AddDocument(document Entity) {
|
||||||
collection.Documents = append(collection.Documents, document)
|
collection.Documents = append(collection.Documents, document)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,28 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
type DocumentGroup struct {
|
type Group struct {
|
||||||
Id string
|
Id string
|
||||||
ParentId string
|
ParentId string
|
||||||
ProjectId string
|
ProjectId string
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentGroupCollection struct {
|
type GroupCollection struct {
|
||||||
Id string
|
Id string
|
||||||
DocumentGroups []DocumentGroup
|
Groups []Group
|
||||||
ProjectId string
|
ProjectId string
|
||||||
}
|
}
|
||||||
|
|
||||||
var documentGroupCollectionInstance *DocumentGroupCollection
|
var groupCollectionInstance *GroupCollection
|
||||||
|
|
||||||
func GetDocumentGroupCollection() *DocumentGroupCollection {
|
func GetGroupCollection() *GroupCollection {
|
||||||
if documentGroupCollectionInstance == nil {
|
if groupCollectionInstance == nil {
|
||||||
documentGroupCollectionInstance = &DocumentGroupCollection{}
|
groupCollectionInstance = &GroupCollection{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return documentGroupCollectionInstance
|
return groupCollectionInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *DocumentGroupCollection) AddDocumentGroup(group DocumentGroup) {
|
func (collection *GroupCollection) AddDocumentGroup(group Group) {
|
||||||
collection.DocumentGroups = append(collection.DocumentGroups, group)
|
collection.Groups = append(collection.Groups, group)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,19 +2,19 @@ package document
|
|||||||
|
|
||||||
func InitizeModule() {
|
func InitizeModule() {
|
||||||
GetDocumentCollection()
|
GetDocumentCollection()
|
||||||
GetDocumentGroupCollection()
|
GetGroupCollection()
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestData() {
|
func createTestData() {
|
||||||
documentCollection := GetDocumentCollection()
|
documentCollection := GetDocumentCollection()
|
||||||
documentGroupCollection := GetDocumentGroupCollection()
|
documentGroupCollection := GetGroupCollection()
|
||||||
|
|
||||||
documentGroupCollection.AddDocumentGroup(DocumentGroup{
|
documentGroupCollection.AddDocumentGroup(Group{
|
||||||
Id: "XYZ",
|
Id: "XYZ",
|
||||||
Name: "Test Group One",
|
Name: "Test Group One",
|
||||||
})
|
})
|
||||||
|
|
||||||
documentCollection.AddDocument(Document{
|
documentCollection.AddDocument(Entity{
|
||||||
Id: "ABC",
|
Id: "ABC",
|
||||||
GroupId: "XYZ",
|
GroupId: "XYZ",
|
||||||
Name: "My First Document",
|
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={{
|
projectProps={{
|
||||||
id: '',
|
id: '',
|
||||||
documents: [] as ipc.Document[],
|
documents: [] as ipc.Document[],
|
||||||
groups: [] as ipc.DocumentGroup[]
|
groups: [] as ipc.Group[]
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</ProjectProvider>
|
</ProjectProvider>
|
||||||
|
|||||||
@ -11,7 +11,7 @@ type NavigationItem = {
|
|||||||
children: { id: string, name: string }[]
|
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 groupsWithDocuments = groups.map(g => {
|
||||||
const childrenDocuments = documents
|
const childrenDocuments = documents
|
||||||
.filter(d => d.groupId === g.id)
|
.filter(d => d.groupId === g.id)
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import { ProjectContextType } from "./types"
|
|||||||
const makeDefaultProject = (): ProjectContextType => ({
|
const makeDefaultProject = (): ProjectContextType => ({
|
||||||
id: '',
|
id: '',
|
||||||
documents: [] as ipc.Document[],
|
documents: [] as ipc.Document[],
|
||||||
groups: [] as ipc.DocumentGroup[],
|
groups: [] as ipc.Group[],
|
||||||
requestAddDocument: (groupId: string, documentName: string) => Promise.resolve(new ipc.Document()),
|
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
|
export default makeDefaultProject
|
||||||
|
|||||||
@ -13,12 +13,12 @@ export function useProject() {
|
|||||||
type Props = { children: ReactNode, projectProps: ProjectProps }
|
type Props = { children: ReactNode, projectProps: ProjectProps }
|
||||||
export function ProjectProvider({ children, projectProps }: Props) {
|
export function ProjectProvider({ children, projectProps }: Props) {
|
||||||
const [ documents, setDocuments ] = useState<ipc.Document[]>(projectProps.documents)
|
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 () => {
|
const updateDocuments = async () => {
|
||||||
GetDocuments().then(response => {
|
GetDocuments().then(response => {
|
||||||
setDocuments(response.documents)
|
setDocuments(response.documents)
|
||||||
setGroups(response.documentGroups)
|
setGroups(response.groups)
|
||||||
Promise.resolve(response)
|
Promise.resolve(response)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,10 @@ import { ipc } from "../../wailsjs/wailsjs/go/models"
|
|||||||
export type ProjectProps = {
|
export type ProjectProps = {
|
||||||
id: string,
|
id: string,
|
||||||
documents: ipc.Document[],
|
documents: ipc.Document[],
|
||||||
groups: ipc.DocumentGroup[],
|
groups: ipc.Group[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProjectContextType = {
|
export type ProjectContextType = {
|
||||||
requestAddDocument: (groupId: string, documentName: string) => Promise<ipc.Document>,
|
requestAddDocument: (groupId: string, documentName: string) => Promise<ipc.Document>,
|
||||||
requestAddDocumentGroup: (groupName: string) => Promise<ipc.DocumentGroup>,
|
requestAddDocumentGroup: (groupName: string) => Promise<ipc.Group>,
|
||||||
} & ProjectProps
|
} & 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 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"];
|
this.projectId = source["projectId"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class DocumentGroup {
|
export class Group {
|
||||||
id: string;
|
id: string;
|
||||||
parentId: string;
|
parentId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
static createFrom(source: any = {}) {
|
static createFrom(source: any = {}) {
|
||||||
return new DocumentGroup(source);
|
return new Group(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(source: any = {}) {
|
constructor(source: any = {}) {
|
||||||
@ -40,7 +40,7 @@ export namespace ipc {
|
|||||||
}
|
}
|
||||||
export class GetDocumentsResponse {
|
export class GetDocumentsResponse {
|
||||||
documents: Document[];
|
documents: Document[];
|
||||||
documentGroups: DocumentGroup[];
|
groups: Group[];
|
||||||
|
|
||||||
static createFrom(source: any = {}) {
|
static createFrom(source: any = {}) {
|
||||||
return new GetDocumentsResponse(source);
|
return new GetDocumentsResponse(source);
|
||||||
@ -49,7 +49,7 @@ export namespace ipc {
|
|||||||
constructor(source: any = {}) {
|
constructor(source: any = {}) {
|
||||||
if ('string' === typeof source) source = JSON.parse(source);
|
if ('string' === typeof source) source = JSON.parse(source);
|
||||||
this.documents = this.convertValues(source["documents"], Document);
|
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 {
|
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||||
|
|||||||
@ -9,17 +9,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GetDocumentsResponse struct {
|
type GetDocumentsResponse struct {
|
||||||
Documents []Document `json:"documents"`
|
Documents []Document `json:"documents"`
|
||||||
DocumentGroups []DocumentGroup `json:"documentGroups"`
|
Groups []Group `json:"groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetDocuments() GetDocumentsResponse {
|
func (c *Channel) GetDocuments() GetDocumentsResponse {
|
||||||
documents := document.GetDocumentCollection().Documents
|
documents := document.GetDocumentCollection().Documents
|
||||||
documentGroups := document.GetDocumentGroupCollection().DocumentGroups
|
groups := document.GetGroupCollection().Groups
|
||||||
|
|
||||||
response := GetDocumentsResponse{
|
response := GetDocumentsResponse{
|
||||||
DocumentGroups: make([]DocumentGroup, 0),
|
Groups: make([]Group, 0),
|
||||||
Documents: make([]Document, 0),
|
Documents: make([]Document, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range documents {
|
for _, d := range documents {
|
||||||
@ -33,14 +33,14 @@ func (c *Channel) GetDocuments() GetDocumentsResponse {
|
|||||||
response.Documents = append(response.Documents, jsonDocument)
|
response.Documents = append(response.Documents, jsonDocument)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, g := range documentGroups {
|
for _, g := range groups {
|
||||||
jsonGroup := DocumentGroup{
|
jsonGroup := Group{
|
||||||
Id: g.Id,
|
Id: g.Id,
|
||||||
ParentId: g.ParentId,
|
ParentId: g.ParentId,
|
||||||
ProjectId: g.ProjectId,
|
ProjectId: g.ProjectId,
|
||||||
Name: g.Name,
|
Name: g.Name,
|
||||||
}
|
}
|
||||||
response.DocumentGroups = append(response.DocumentGroups, jsonGroup)
|
response.Groups = append(response.Groups, jsonGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
@ -62,7 +62,7 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume
|
|||||||
return Document{}
|
return Document{}
|
||||||
}
|
}
|
||||||
|
|
||||||
newDocument := document.Document{
|
newDocument := document.Entity{
|
||||||
Id: uuid.NewString(),
|
Id: uuid.NewString(),
|
||||||
Name: documentName,
|
Name: documentName,
|
||||||
Path: filePath,
|
Path: filePath,
|
||||||
@ -83,20 +83,20 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume
|
|||||||
return documentResponse
|
return documentResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestAddDocumentGroup(name string) DocumentGroup {
|
func (c *Channel) RequestAddDocumentGroup(name string) Group {
|
||||||
newDocumentGroup := document.DocumentGroup{
|
newGroup := document.Group{
|
||||||
Id: uuid.NewString(),
|
Id: uuid.NewString(),
|
||||||
Name: name,
|
Name: name,
|
||||||
ProjectId: "something else",
|
ProjectId: "something else",
|
||||||
}
|
}
|
||||||
|
|
||||||
document.GetDocumentGroupCollection().AddDocumentGroup(newDocumentGroup)
|
document.GetGroupCollection().AddDocumentGroup(newGroup)
|
||||||
|
|
||||||
response := DocumentGroup{
|
response := Group{
|
||||||
Id: newDocumentGroup.Id,
|
Id: newGroup.Id,
|
||||||
Name: newDocumentGroup.Name,
|
Name: newGroup.Name,
|
||||||
ParentId: newDocumentGroup.ParentId,
|
ParentId: newGroup.ParentId,
|
||||||
ProjectId: newDocumentGroup.ProjectId,
|
ProjectId: newGroup.ProjectId,
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
@ -13,15 +13,15 @@ type DocumentCollection struct {
|
|||||||
ProjectId string `json:"projectId"`
|
ProjectId string `json:"projectId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentGroup struct {
|
type Group struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
ParentId string `json:"parentId"`
|
ParentId string `json:"parentId"`
|
||||||
ProjectId string `json:"projectId"`
|
ProjectId string `json:"projectId"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentGroupCollection struct {
|
type GroupCollection struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
DocumentGroups []DocumentGroup `json:"groups"`
|
Groups []Group `json:"groups"`
|
||||||
ProjectId string `json:"projectId"`
|
ProjectId string `json:"projectId"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user