fix(prompt): disallow update if prompt is empty (#1816)
This commit is contained in:
@@ -116,24 +116,24 @@ func (d *PromptDAO) GetPromptResource(ctx context.Context, promptID int64) (*ent
|
||||
return do, nil
|
||||
}
|
||||
|
||||
func (d *PromptDAO) UpdatePromptResource(ctx context.Context, p *entity.PromptResource) error {
|
||||
func (d *PromptDAO) UpdatePromptResource(ctx context.Context, promptID int64, name, description, promptText *string) error {
|
||||
updateMap := make(map[string]any, 5)
|
||||
|
||||
if p.Name != "" {
|
||||
updateMap["name"] = p.Name
|
||||
if name != nil {
|
||||
updateMap["name"] = *name
|
||||
}
|
||||
|
||||
if p.Description != "" {
|
||||
updateMap["description"] = p.Description
|
||||
if description != nil {
|
||||
updateMap["description"] = *description
|
||||
}
|
||||
|
||||
if p.PromptText != "" {
|
||||
updateMap["prompt_text"] = p.PromptText
|
||||
if promptText != nil {
|
||||
updateMap["prompt_text"] = *promptText
|
||||
}
|
||||
|
||||
promptModel := query.PromptResource
|
||||
promptWhere := []gen.Condition{
|
||||
promptModel.ID.Eq(p.ID),
|
||||
promptModel.ID.Eq(promptID),
|
||||
}
|
||||
|
||||
_, err := promptModel.WithContext(ctx).Where(promptWhere...).Updates(updateMap)
|
||||
|
||||
@@ -33,6 +33,6 @@ func NewPromptRepo(db *gorm.DB, generator idgen.IDGenerator) PromptRepository {
|
||||
type PromptRepository interface {
|
||||
CreatePromptResource(ctx context.Context, do *entity.PromptResource) (int64, error)
|
||||
GetPromptResource(ctx context.Context, promptID int64) (*entity.PromptResource, error)
|
||||
UpdatePromptResource(ctx context.Context, p *entity.PromptResource) error
|
||||
UpdatePromptResource(ctx context.Context, promptID int64, name, description, promptText *string) error
|
||||
DeletePromptResource(ctx context.Context, ID int64) error
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
type Prompt interface {
|
||||
CreatePromptResource(ctx context.Context, p *entity.PromptResource) (int64, error)
|
||||
GetPromptResource(ctx context.Context, promptID int64) (*entity.PromptResource, error)
|
||||
UpdatePromptResource(ctx context.Context, p *entity.PromptResource) error
|
||||
UpdatePromptResource(ctx context.Context, promptID int64, name, description, promptText *string) error
|
||||
DeletePromptResource(ctx context.Context, promptID int64) error
|
||||
|
||||
ListOfficialPromptResource(ctx context.Context, keyword string) ([]*entity.PromptResource, error)
|
||||
|
||||
@@ -40,8 +40,8 @@ func (s *promptService) CreatePromptResource(ctx context.Context, p *entity.Prom
|
||||
return s.Repo.CreatePromptResource(ctx, p)
|
||||
}
|
||||
|
||||
func (s *promptService) UpdatePromptResource(ctx context.Context, p *entity.PromptResource) error {
|
||||
return s.Repo.UpdatePromptResource(ctx, p)
|
||||
func (s *promptService) UpdatePromptResource(ctx context.Context, promptID int64, name, description, promptText *string) error {
|
||||
return s.Repo.UpdatePromptResource(ctx, promptID, name, description, promptText)
|
||||
}
|
||||
|
||||
func (s *promptService) GetPromptResource(ctx context.Context, promptID int64) (*entity.PromptResource, error) {
|
||||
|
||||
Reference in New Issue
Block a user