generated from VLADIMIR/template
add crud for node
This commit is contained in:
@@ -97,18 +97,44 @@ func (s *StoryService) GetPlace(code string) *Place {
|
||||
}
|
||||
|
||||
func (s *StoryService) UpdatePlace(code string, node *GraphNode) error {
|
||||
if code != "" && node.Code == "" {
|
||||
for i := range s.story.Places {
|
||||
if s.story.Places[i].Code == code {
|
||||
s.story.Places = append(s.story.Places[:i], s.story.Places[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
s.Update()
|
||||
return nil
|
||||
}
|
||||
nodeApplications := make([]*Application, 0, len(node.Applications))
|
||||
for _, application := range node.Applications {
|
||||
nodeApplications = append(
|
||||
nodeApplications,
|
||||
&Application{
|
||||
Name: application.Name,
|
||||
},
|
||||
)
|
||||
}
|
||||
if code == "" && node.Code != "" {
|
||||
s.story.Places = append(
|
||||
s.story.Places,
|
||||
&Place{
|
||||
Code: node.Code,
|
||||
Name: node.Name,
|
||||
Text: formatText(node.Text),
|
||||
Applications: nodeApplications,
|
||||
},
|
||||
)
|
||||
s.Update()
|
||||
return nil
|
||||
}
|
||||
if code == "" || node.Code == "" {
|
||||
return nil
|
||||
}
|
||||
update := false
|
||||
for i := range s.story.Places {
|
||||
if s.story.Places[i].Code == code {
|
||||
nodeApplications := make([]*Application, 0, len(node.Applications))
|
||||
for _, application := range node.Applications {
|
||||
nodeApplications = append(
|
||||
nodeApplications,
|
||||
&Application{
|
||||
Name: application.Name,
|
||||
},
|
||||
)
|
||||
}
|
||||
s.story.Places[i] = &Place{
|
||||
Code: node.Code,
|
||||
Name: node.Name,
|
||||
@@ -122,15 +148,6 @@ func (s *StoryService) UpdatePlace(code string, node *GraphNode) error {
|
||||
if !update {
|
||||
for i := range s.story.Places {
|
||||
if s.story.Places[i].Code == node.Code {
|
||||
nodeApplications := make([]*Application, 0, len(node.Applications))
|
||||
for _, application := range node.Applications {
|
||||
nodeApplications = append(
|
||||
nodeApplications,
|
||||
&Application{
|
||||
Name: application.Name,
|
||||
},
|
||||
)
|
||||
}
|
||||
s.story.Places[i] = &Place{
|
||||
Code: code,
|
||||
Name: node.Name,
|
||||
|
||||
Reference in New Issue
Block a user