1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package file
- import (
- "git.andreafazzi.eu/andrea/probo/pkg/models"
- "git.andreafazzi.eu/andrea/probo/pkg/store"
- )
- type ParticipantFileStore struct {
- *FileStore[*models.Participant, *store.ParticipantStore]
- }
- func NewParticipantFileStore(config *FileStoreConfig[*models.Participant, *store.ParticipantStore]) (*ParticipantFileStore, error) {
- var err error
- pStore := new(ParticipantFileStore)
- pStore.FileStore, err = NewFileStore[*models.Participant, *store.ParticipantStore](config, store.NewParticipantStore())
- if err != nil {
- return nil, err
- }
- return pStore, nil
- }
- func NewDefaultParticipantFileStore() (*ParticipantFileStore, error) {
- return NewParticipantFileStore(
- &FileStoreConfig[*models.Participant, *store.ParticipantStore]{
- FilePathConfig: FilePathConfig{GetDefaultParticipantsDir(), "participant", ".json"},
- IndexDirFunc: DefaultIndexDirFunc[*models.Participant, *store.ParticipantStore],
- CreateEntityFunc: func() *models.Participant {
- return &models.Participant{
- Attributes: make(map[string]string),
- }
- },
- },
- )
- }
- func (ps *ParticipantFileStore) ImportCSV(path string) ([]*models.Participant, error) {
- participants, err := ps.FileStore.Storer.ImportCSV(path)
- if err != nil {
- return nil, err
- }
- for _, p := range participants {
- _, err := ps.Create(p)
- if err != nil {
- return nil, err
- }
- }
- return participants, nil
- }
|