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)
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user