2023-12-12 18:42:50 +01:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2024-01-29 13:54:50 +01:00
|
|
|
"fmt"
|
|
|
|
|
2023-12-12 18:42:50 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AddClient creates a new client and returns it if successful.
|
|
|
|
func AddClient(frm form.Client) (client *Client, err error) {
|
2024-01-29 13:54:50 +01:00
|
|
|
if found := FindClientByUID(frm.ID()); found != nil {
|
2024-01-29 21:08:01 +01:00
|
|
|
return found, fmt.Errorf("client %s already exists", found.ClientUID)
|
2024-01-29 13:54:50 +01:00
|
|
|
}
|
|
|
|
|
2023-12-12 18:42:50 +01:00
|
|
|
client = NewClient().SetFormValues(frm)
|
|
|
|
|
|
|
|
if err = client.Validate(); err != nil {
|
|
|
|
return client, err
|
|
|
|
} else if err = client.Create(); err != nil {
|
|
|
|
return client, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|