feat (patient): crud untested yet
This commit is contained in:
No files matched your search
@@ -1,9 +1,11 @@
|
||||
package person
|
||||
|
||||
import (
|
||||
"errors"
|
||||
e "simrs-vx/internal/domain/main-entities/person"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
"strconv"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
gh "github.com/karincake/getuk"
|
||||
@@ -155,3 +157,35 @@ func DeleteData(data *e.Person, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateOrUpdatePerson(input *e.UpdateDto, event *pl.Event, tx *gorm.DB) (*uint, error) {
|
||||
if input.Id == 0 {
|
||||
person, err := CreateData(input.CreateDto, event, tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &person.Id, nil
|
||||
}
|
||||
|
||||
person, err := ReadDetailData(e.ReadDetailDto{Id: input.Id}, event, tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if person == nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-notFound",
|
||||
Detail: "person with ID " + strconv.Itoa(int(input.Id)) + " not found",
|
||||
Raw: errors.New("person with ID " + strconv.Itoa(int(input.Id)) + " not found"),
|
||||
}
|
||||
return nil, pl.SetLogError(event, input)
|
||||
}
|
||||
|
||||
if err := UpdateData(e.UpdateDto{CreateDto: input.CreateDto}, person, event, tx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &person.Id, nil
|
||||
}
|
||||
Reference in New Issue
Block a user