mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-24 03:04:21 +01:00
cleanup app, config and root
This commit is contained in:
@@ -23,22 +23,21 @@ type Session struct {
|
||||
|
||||
type Service interface {
|
||||
pubsub.Suscriber[Session]
|
||||
Create(title string) (Session, error)
|
||||
CreateTaskSession(toolCallID, parentSessionID, title string) (Session, error)
|
||||
Get(id string) (Session, error)
|
||||
List() ([]Session, error)
|
||||
Save(session Session) (Session, error)
|
||||
Delete(id string) error
|
||||
Create(ctx context.Context, title string) (Session, error)
|
||||
CreateTaskSession(ctx context.Context, toolCallID, parentSessionID, title string) (Session, error)
|
||||
Get(ctx context.Context, id string) (Session, error)
|
||||
List(ctx context.Context) ([]Session, error)
|
||||
Save(ctx context.Context, session Session) (Session, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
type service struct {
|
||||
*pubsub.Broker[Session]
|
||||
q db.Querier
|
||||
ctx context.Context
|
||||
q db.Querier
|
||||
}
|
||||
|
||||
func (s *service) Create(title string) (Session, error) {
|
||||
dbSession, err := s.q.CreateSession(s.ctx, db.CreateSessionParams{
|
||||
func (s *service) Create(ctx context.Context, title string) (Session, error) {
|
||||
dbSession, err := s.q.CreateSession(ctx, db.CreateSessionParams{
|
||||
ID: uuid.New().String(),
|
||||
Title: title,
|
||||
})
|
||||
@@ -50,8 +49,8 @@ func (s *service) Create(title string) (Session, error) {
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (s *service) CreateTaskSession(toolCallID, parentSessionID, title string) (Session, error) {
|
||||
dbSession, err := s.q.CreateSession(s.ctx, db.CreateSessionParams{
|
||||
func (s *service) CreateTaskSession(ctx context.Context, toolCallID, parentSessionID, title string) (Session, error) {
|
||||
dbSession, err := s.q.CreateSession(ctx, db.CreateSessionParams{
|
||||
ID: toolCallID,
|
||||
ParentSessionID: sql.NullString{String: parentSessionID, Valid: true},
|
||||
Title: title,
|
||||
@@ -64,12 +63,12 @@ func (s *service) CreateTaskSession(toolCallID, parentSessionID, title string) (
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (s *service) Delete(id string) error {
|
||||
session, err := s.Get(id)
|
||||
func (s *service) Delete(ctx context.Context, id string) error {
|
||||
session, err := s.Get(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.q.DeleteSession(s.ctx, session.ID)
|
||||
err = s.q.DeleteSession(ctx, session.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -77,16 +76,16 @@ func (s *service) Delete(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) Get(id string) (Session, error) {
|
||||
dbSession, err := s.q.GetSessionByID(s.ctx, id)
|
||||
func (s *service) Get(ctx context.Context, id string) (Session, error) {
|
||||
dbSession, err := s.q.GetSessionByID(ctx, id)
|
||||
if err != nil {
|
||||
return Session{}, err
|
||||
}
|
||||
return s.fromDBItem(dbSession), nil
|
||||
}
|
||||
|
||||
func (s *service) Save(session Session) (Session, error) {
|
||||
dbSession, err := s.q.UpdateSession(s.ctx, db.UpdateSessionParams{
|
||||
func (s *service) Save(ctx context.Context, session Session) (Session, error) {
|
||||
dbSession, err := s.q.UpdateSession(ctx, db.UpdateSessionParams{
|
||||
ID: session.ID,
|
||||
Title: session.Title,
|
||||
PromptTokens: session.PromptTokens,
|
||||
@@ -101,8 +100,8 @@ func (s *service) Save(session Session) (Session, error) {
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (s *service) List() ([]Session, error) {
|
||||
dbSessions, err := s.q.ListSessions(s.ctx)
|
||||
func (s *service) List(ctx context.Context) ([]Session, error) {
|
||||
dbSessions, err := s.q.ListSessions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,11 +126,10 @@ func (s service) fromDBItem(item db.Session) Session {
|
||||
}
|
||||
}
|
||||
|
||||
func NewService(ctx context.Context, q db.Querier) Service {
|
||||
func NewService(q db.Querier) Service {
|
||||
broker := pubsub.NewBroker[Session]()
|
||||
return &service{
|
||||
broker,
|
||||
q,
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user