correction des pb de space : le spaceId est maintenant dans l'url uniquement
This commit is contained in:
1 parent
c52460bac0
commit
0bb8d1cb46
41 files changed
+1463
-121
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
repo domain.AgentRepository
|
||||
repoUser domain.UserRepository
|
||||
}
|
||||
|
||||
func NewService(
|
||||
repo domain.AgentRepository,
|
||||
repoUser domain.UserRepository,
|
||||
) *Service {
|
||||
return &Service{
|
||||
repo,
|
||||
repoUser,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) ListAgents(userID string, teamID string) ([]*domain.Agent, error) {
|
||||
return s.repo.ListAgents(userID, teamID)
|
||||
}
|
||||
|
||||
func (s *Service) GetAgent(userID string, teamID string, id string) (*domain.Agent, error) {
|
||||
return s.repo.GetAgent(userID, teamID, id)
|
||||
}
|
||||
|
||||
func (s *Service) CreateAgent(userID string, Agent *domain.Agent) (*domain.Agent, error) {
|
||||
|
||||
if _, err := s.repoUser.FindUserTeam(userID, Agent.TeamID); err != nil {
|
||||
return nil, fmt.Errorf("error finding user in team: %s", err)
|
||||
}
|
||||
|
||||
return s.repo.CreateAgent(userID, Agent)
|
||||
}
|
||||
|
||||
func (s *Service) UpdateAgent(userID string, Agent *domain.Agent) (*domain.Agent, error) {
|
||||
if _, err := s.repoUser.FindUserTeam(userID, Agent.TeamID); err != nil {
|
||||
return nil, fmt.Errorf("error finding user in team: %s", err)
|
||||
}
|
||||
|
||||
if _, err := s.repo.GetAgent(userID, Agent.TeamID, Agent.ID); err != nil {
|
||||
return nil, fmt.Errorf("error finding Agent: %s", err)
|
||||
}
|
||||
|
||||
return s.repo.UpdateAgent(userID, Agent)
|
||||
}
|
||||
|
||||
func (s *Service) DeleteAgent(userID string, teamID string, id string) error {
|
||||
if _, err := s.repoUser.FindUserTeam(userID, teamID); err != nil {
|
||||
return fmt.Errorf("error finding user in team: %s", err)
|
||||
}
|
||||
|
||||
if _, err := s.repo.GetAgent(userID, teamID, id); err != nil {
|
||||
return fmt.Errorf("error finding Agent: %s", err)
|
||||
}
|
||||
|
||||
return s.repo.DeleteAgent(userID, teamID, id)
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package provider
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
@@ -33,6 +34,28 @@ func (s *Service) ListProviders(userID string, teamID string) ([]*domain.Provide
|
||||
return s.repo.ListProviders(userID, teamID)
|
||||
}
|
||||
|
||||
func (s *Service) ListProvidersModels(userID string, teamID string) ([]*domain.ComplexItem, error) {
|
||||
|
||||
items := make([]*domain.ComplexItem, 0)
|
||||
|
||||
providers, err := s.repo.ListProviders(userID, teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, provider := range providers {
|
||||
models := strings.Split(provider.Models, "|")
|
||||
for _, m := range models {
|
||||
items = append(items, &domain.ComplexItem{
|
||||
Group: provider.Name,
|
||||
Value: provider.ID + "|" + m,
|
||||
Label: m,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetProvider(userID string, teamID string, id string) (*domain.Provider, error) {
|
||||
return s.repo.GetProvider(userID, teamID, id)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user