oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package library
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/kernel"
5 "slices"
6 "strings"
7)
8
9func (s *Store) SaveLegacy(actor kernel.Actor, specialist Specialist) error {
10 if !slices.Contains(DefaultKeys, specialist.Key) || specialist.MaxConcurrent <= 0 || specialist.Revision < 0 {
11 return s.deps.Invalid
12 }
13 if specialist.ModelSelection != "best_fit" && specialist.ModelSelection != "fixed" {
14 return s.deps.Invalid
15 }
16 specialist.Provider = strings.TrimSpace(specialist.Provider)
17 specialist.ModelFamily = strings.TrimSpace(specialist.ModelFamily)
18 specialist.Model = strings.TrimSpace(specialist.Model)
19 if specialist.ModelSelection == "fixed" && (specialist.Provider == "" || specialist.ModelFamily == "" || specialist.Model == "") {
20 return s.deps.Invalid
21 }
22 tx := s.tx
23 access, err := s.deps.Authorize(tx, actor)
24 if err != nil {
25 return err
26 }
27 if !access.Owner {
28 return s.deps.Forbidden
29 }
30 var old Specialist
31 if err := tx.Where("key = ? AND team_id=? AND archived=?", specialist.Key, access.TeamID, false).First(&old).Error; err != nil {
32 return err
33 }
34 if old.Revision != specialist.Revision {
35 return s.deps.Conflict
36 }
37 specialist.Revision++
38 result := tx.Model(&Specialist{}).Where("key = ? AND revision = ?", specialist.Key, old.Revision).
39 Select("ModelSelection", "Provider", "ModelFamily", "Model", "StandingInstructions", "MaxConcurrent", "Revision").Updates(&specialist)
40 if result.Error != nil {
41 return result.Error
42 }
43 if result.RowsAffected != 1 {
44 return s.deps.Conflict
45 }
46 return s.deps.Audit(tx, actor, "specialist.save", specialist.Key)
47}
48