Browse Source

Merge branch 'master' of ssh+git://git.aiterp.net/rpdata/api

master 2.1.0
Gisle Aune 4 years ago
parent
commit
c4eabd69ac
  1. 3
      .gitignore
  2. 52
      services/logs.go

3
.gitignore

@ -10,6 +10,9 @@ rpdata-*
.vscode .vscode
.idea .idea
/main
/main.exe
/graph2/graphcore/*_gen.go /graph2/graphcore/*_gen.go
generated.gql generated.gql
generated.go generated.go

52
services/logs.go

@ -145,26 +145,33 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da
parsed.Log.EventName = eventName parsed.Log.EventName = eventName
parsed.Log.ChannelName = channelName parsed.Log.ChannelName = channelName
log, err := s.logs.Insert(ctx, parsed.Log)
newLog, err := s.logs.Insert(ctx, parsed.Log)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, post := range parsed.Posts { for _, post := range parsed.Posts {
post.LogID = log.ShortID
post.LogID = newLog.ShortID
} }
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) posts, err := s.posts.InsertMany(ctx, parsed.Posts...)
if err != nil { if err != nil {
_ = s.logs.Delete(ctx, *log)
_ = s.logs.Delete(ctx, *newLog)
return nil, err return nil, err
} }
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(log), log)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(log, posts), log, posts)
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(newLog), newLog)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(newLog, posts), newLog, posts)
results = append(results, log)
refreshedLog, err := s.refreshLogCharacters(ctx, *newLog, nil, false)
if err != nil {
log.Printf("Failed to update characters in newLog %s: %s", newLog.ID, err)
} else {
newLog = refreshedLog
}
results = append(results, newLog)
} }
case models.LogImporterForumLog: case models.LogImporterForumLog:
{ {
@ -177,26 +184,26 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da
parsed.Log.EventName = eventName parsed.Log.EventName = eventName
parsed.Log.ChannelName = channelName parsed.Log.ChannelName = channelName
log, err := s.logs.Insert(ctx, parsed.Log)
newLog, err := s.logs.Insert(ctx, parsed.Log)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, post := range parsed.Posts { for _, post := range parsed.Posts {
post.LogID = log.ShortID
post.LogID = newLog.ShortID
} }
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) posts, err := s.posts.InsertMany(ctx, parsed.Posts...)
if err != nil { if err != nil {
_ = s.logs.Delete(ctx, *log)
_ = s.logs.Delete(ctx, *newLog)
return nil, err return nil, err
} }
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(log), log)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(log, posts), log, posts)
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(newLog), newLog)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(newLog, posts), newLog, posts)
results = append(results, log)
results = append(results, newLog)
} }
} }
@ -211,26 +218,33 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da
parsed.Log.EventName = eventName parsed.Log.EventName = eventName
parsed.Log.ChannelName = channelName parsed.Log.ChannelName = channelName
log, err := s.logs.Insert(ctx, parsed.Log)
newLog, err := s.logs.Insert(ctx, parsed.Log)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, post := range parsed.Posts { for _, post := range parsed.Posts {
post.LogID = log.ShortID
post.LogID = newLog.ShortID
} }
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) posts, err := s.posts.InsertMany(ctx, parsed.Posts...)
if err != nil { if err != nil {
_ = s.logs.Delete(ctx, *log)
_ = s.logs.Delete(ctx, *newLog)
return nil, err
return results, err
} }
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(log), log)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(log, posts), log, posts)
refreshedLog, err := s.refreshLogCharacters(ctx, *newLog, nil, false)
if err != nil {
log.Printf("Failed to update characters in newLog %s: %s", newLog.ID, err)
} else {
newLog = refreshedLog
}
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(newLog), newLog)
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(newLog, posts), newLog, posts)
results = append(results, log)
results = append(results, newLog)
} }
} }

Loading…
Cancel
Save