You've already forked agentic-coding-workflow
fix(chat): align template service with actual repo method names
This commit is contained in:
@@ -3,7 +3,6 @@ package chat
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -25,26 +24,25 @@ func NewTemplateService(repo Repository, a audit.Recorder, log *slog.Logger) Tem
|
||||
}
|
||||
|
||||
func (s *templateService) List(ctx context.Context, userID uuid.UUID) ([]PromptTemplate, error) {
|
||||
return s.repo.ListTemplatesForUser(ctx, userID)
|
||||
return s.repo.ListPromptTemplatesForUser(ctx, userID)
|
||||
}
|
||||
|
||||
func (s *templateService) Create(ctx context.Context, userID uuid.UUID, name, content string, scope TemplateScope) (*PromptTemplate, error) {
|
||||
if scope != TemplateScopeSystem && scope != TemplateScopeUser {
|
||||
return nil, errs.New(errs.CodeInvalidInput, "invalid scope")
|
||||
}
|
||||
t := &PromptTemplate{
|
||||
ID: uuid.Must(uuid.NewV7()),
|
||||
Name: name,
|
||||
Content: content,
|
||||
Scope: scope,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
params := InsertTemplateParams{
|
||||
ID: uuid.Must(uuid.NewV7()),
|
||||
Name: name,
|
||||
Content: content,
|
||||
Scope: scope,
|
||||
}
|
||||
if scope == TemplateScopeUser {
|
||||
uid := userID
|
||||
t.OwnerID = &uid
|
||||
params.OwnerID = &uid
|
||||
}
|
||||
if err := s.repo.InsertTemplate(ctx, t); err != nil {
|
||||
t, err := s.repo.InsertPromptTemplate(ctx, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if scope == TemplateScopeSystem {
|
||||
@@ -57,7 +55,7 @@ func (s *templateService) Create(ctx context.Context, userID uuid.UUID, name, co
|
||||
}
|
||||
|
||||
func (s *templateService) Update(ctx context.Context, userID, id uuid.UUID, name, content string) error {
|
||||
t, err := s.repo.GetTemplate(ctx, id)
|
||||
t, err := s.repo.GetPromptTemplate(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -67,7 +65,7 @@ func (s *templateService) Update(ctx context.Context, userID, id uuid.UUID, name
|
||||
if t.Scope == TemplateScopeUser && (t.OwnerID == nil || *t.OwnerID != userID) {
|
||||
return errs.New(errs.CodeForbidden, "not template owner")
|
||||
}
|
||||
if err := s.repo.UpdateTemplate(ctx, id, name, content); err != nil {
|
||||
if err := s.repo.UpdatePromptTemplate(ctx, id, name, content); err != nil {
|
||||
return err
|
||||
}
|
||||
if t.Scope == TemplateScopeSystem {
|
||||
@@ -80,7 +78,7 @@ func (s *templateService) Update(ctx context.Context, userID, id uuid.UUID, name
|
||||
}
|
||||
|
||||
func (s *templateService) Delete(ctx context.Context, userID, id uuid.UUID) error {
|
||||
t, err := s.repo.GetTemplate(ctx, id)
|
||||
t, err := s.repo.GetPromptTemplate(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -90,7 +88,7 @@ func (s *templateService) Delete(ctx context.Context, userID, id uuid.UUID) erro
|
||||
if t.Scope == TemplateScopeUser && (t.OwnerID == nil || *t.OwnerID != userID) {
|
||||
return errs.New(errs.CodeForbidden, "not template owner")
|
||||
}
|
||||
if err := s.repo.DeleteTemplate(ctx, id); err != nil {
|
||||
if err := s.repo.DeletePromptTemplate(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
if t.Scope == TemplateScopeSystem {
|
||||
|
||||
Reference in New Issue
Block a user