(ctx context.Context, id string, input *service_dto.EditService)
| 785 | } |
| 786 | |
| 787 | func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_dto.EditService) (*service_dto.Service, error) { |
| 788 | info, err := i.serviceService.Get(ctx, id) |
| 789 | if err != nil { |
| 790 | return nil, err |
| 791 | } |
| 792 | |
| 793 | switch info.Kind { |
| 794 | case service.AIService: |
| 795 | if input.Provider != nil { |
| 796 | info.AdditionalConfig["provider"] = *input.Provider |
| 797 | } |
| 798 | if input.Model != nil { |
| 799 | info.AdditionalConfig["model"] = *input.Model |
| 800 | } |
| 801 | } |
| 802 | err = i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 803 | serviceType := (*service.ServiceType)(input.ServiceType) |
| 804 | if serviceType != nil && *serviceType == service.PublicService { |
| 805 | if input.Catalogue == nil || *input.Catalogue == "" { |
| 806 | return fmt.Errorf("catalogue can not be empty") |
| 807 | } |
| 808 | } |
| 809 | var approvalType service.ApprovalType |
| 810 | if input.ApprovalType != nil { |
| 811 | approvalType = service.ApprovalType(*input.ApprovalType) |
| 812 | } |
| 813 | editCfg := &service.Edit{ |
| 814 | Name: input.Name, |
| 815 | Description: input.Description, |
| 816 | Logo: input.Logo, |
| 817 | ServiceType: serviceType, |
| 818 | Catalogue: input.Catalogue, |
| 819 | AdditionalConfig: &info.AdditionalConfig, |
| 820 | Prefix: input.Prefix, |
| 821 | ApprovalType: &approvalType, |
| 822 | EnableMCP: input.EnableMCP, |
| 823 | } |
| 824 | if input.State != nil { |
| 825 | state := service_dto.ServiceState(*input.State).Int() |
| 826 | editCfg.State = &state |
| 827 | } |
| 828 | |
| 829 | err = i.serviceService.Save(ctx, id, editCfg) |
| 830 | if err != nil { |
| 831 | return err |
| 832 | } |
| 833 | if input.Tags != nil { |
| 834 | tags, err := i.getTagUuids(ctx, *input.Tags) |
| 835 | if err != nil { |
| 836 | return err |
| 837 | } |
| 838 | i.serviceTagService.Delete(ctx, nil, []string{id}) |
| 839 | for _, t := range tags { |
| 840 | err = i.serviceTagService.Create(ctx, &service_tag.CreateTag{ |
| 841 | Tid: t, |
| 842 | Sid: id, |
| 843 | }) |
| 844 | if err != nil { |
nothing calls this directly
no test coverage detected