Emit events on note creation

This commit is contained in:
Eli Ribble 2026-03-19 21:25:24 +00:00
parent 31a767c944
commit 6042e7d337
No known key found for this signature in database
6 changed files with 103 additions and 26 deletions

View file

@ -84,6 +84,8 @@ type ResourceType int
const (
TypeUnknown = iota
TypeFileCSV
TypeNoteAudio
TypeNoteImage
TypeReviewTask
TypeRMONuisance
TypeRMOReport
@ -120,6 +122,10 @@ func resourceString(t ResourceType) string {
switch t {
case TypeFileCSV:
return "sync:filecsv"
case TypeNoteAudio:
return "sync:note:audio"
case TypeNoteImage:
return "sync:note:image"
case TypeReviewTask:
return "sync:review_task"
case TypeRMONuisance:
@ -138,6 +144,10 @@ func makeURI(t ResourceType, id string) string {
switch t {
case TypeFileCSV:
return config.MakeURLNidus("/upload/%s", id)
case TypeNoteAudio:
return config.MakeURLNidus("/note/%s", id)
case TypeNoteImage:
return config.MakeURLNidus("/note/%s", id)
case TypeReviewTask:
return config.MakeURLNidus("/review/%s", id)
case TypeRMONuisance:

View file

@ -3,43 +3,50 @@ package platform
import (
"context"
"fmt"
"strconv"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
//"github.com/google/uuid"
//"github.com/rs/zerolog/log"
)
func NoteAudioCreate(ctx context.Context, user User, setter models.NoteAudioSetter) error {
_, err := models.NoteAudios.Insert(&setter).One(ctx, db.PGInstance.BobDB)
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
if err != nil {
return fmt.Errorf("create txn: %w", err)
}
defer txn.Rollback(ctx)
note_audio, err := models.NoteAudios.Insert(&setter).One(ctx, txn)
if err != nil {
// Just ignore this failure, it means we already have this content
if err.Error() != "insertOrganizationNoteAudios0: ERROR: duplicate key value violates unique constraint \"note_audio_pkey\" (SQLSTATE 23505)" {
return fmt.Errorf("create note_audio: %w", err)
}
}
event.Created(event.TypeNoteAudio, user.Organization.ID(), strconv.Itoa(int(note_audio.ID)))
txn.Commit(ctx)
return nil
}
func NoteAudioNormalized(uuid string) error {
return nil
}
func NoteAudioTranscodedToOgg(uuid string) error {
return nil
}
func NoteImageCreate(ctx context.Context, user User, setter models.NoteImageSetter) error {
_, err := models.NoteImages.Insert(&setter).One(ctx, db.PGInstance.BobDB)
if err == nil {
return nil
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
if err != nil {
return fmt.Errorf("create txn: %w", err)
}
// Just ignore this failure, it means we already have this content
if err.Error() == "insertOrganizationNoteImages0: ERROR: duplicate key value violates unique constraint \"note_image_pkey\" (SQLSTATE 23505)" {
return nil
defer txn.Rollback(ctx)
note_image, err := models.NoteImages.Insert(&setter).One(ctx, db.PGInstance.BobDB)
if err != nil {
// Just ignore this failure, it means we already have this content
if err.Error() != "insertOrganizationNoteImages0: ERROR: duplicate key value violates unique constraint \"note_image_pkey\" (SQLSTATE 23505)" {
return fmt.Errorf("create note_image: %w", err)
}
}
log.Warn().Err(err).Msg("Unrecognized error creating note audio")
event.Created(event.TypeNoteImage, user.Organization.ID(), strconv.Itoa(int(note_image.ID)))
txn.Commit(ctx)
return err
}
func NoteUpdate(ctx context.Context, noteUUID uuid.UUID, setter models.NoteAudioSetter) error {
return nil
}