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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"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) {
|
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) {
|
func (s *templateService) Create(ctx context.Context, userID uuid.UUID, name, content string, scope TemplateScope) (*PromptTemplate, error) {
|
||||||
if scope != TemplateScopeSystem && scope != TemplateScopeUser {
|
if scope != TemplateScopeSystem && scope != TemplateScopeUser {
|
||||||
return nil, errs.New(errs.CodeInvalidInput, "invalid scope")
|
return nil, errs.New(errs.CodeInvalidInput, "invalid scope")
|
||||||
}
|
}
|
||||||
t := &PromptTemplate{
|
params := InsertTemplateParams{
|
||||||
ID: uuid.Must(uuid.NewV7()),
|
ID: uuid.Must(uuid.NewV7()),
|
||||||
Name: name,
|
Name: name,
|
||||||
Content: content,
|
Content: content,
|
||||||
Scope: scope,
|
Scope: scope,
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}
|
}
|
||||||
if scope == TemplateScopeUser {
|
if scope == TemplateScopeUser {
|
||||||
uid := userID
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
if scope == TemplateScopeSystem {
|
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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
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) {
|
if t.Scope == TemplateScopeUser && (t.OwnerID == nil || *t.OwnerID != userID) {
|
||||||
return errs.New(errs.CodeForbidden, "not template owner")
|
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
|
return err
|
||||||
}
|
}
|
||||||
if t.Scope == TemplateScopeSystem {
|
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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
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) {
|
if t.Scope == TemplateScopeUser && (t.OwnerID == nil || *t.OwnerID != userID) {
|
||||||
return errs.New(errs.CodeForbidden, "not template owner")
|
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
|
return err
|
||||||
}
|
}
|
||||||
if t.Scope == TemplateScopeSystem {
|
if t.Scope == TemplateScopeSystem {
|
||||||
|
|||||||
Reference in New Issue
Block a user