refactor: move backend files to backend/ directory
Reorganize project structure: - backend/cmd/openteam/ — entry point - backend/internal/ — core packages - backend/middleware/ — HTTP middleware - backend/router/ — route setup - backend/wire/ — dependency injection - backend/pkg/ — shared utilities - backend/go.mod, go.sum — Go module files Updated Makefile to work from backend/ directory. Removed old lowercase makefile.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"opencatd-open/internal/dao"
|
||||
"opencatd-open/internal/store"
|
||||
)
|
||||
|
||||
type ModelServiceImpl struct {
|
||||
modelDAO *dao.ModelDAO
|
||||
channelDAO *dao.ChannelDAO
|
||||
}
|
||||
|
||||
func NewModelService(modelDAO *dao.ModelDAO, channelDAO *dao.ChannelDAO) *ModelServiceImpl {
|
||||
return &ModelServiceImpl{
|
||||
modelDAO: modelDAO,
|
||||
channelDAO: channelDAO,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) Create(ctx context.Context, model *store.Model) error {
|
||||
return s.modelDAO.Create(model)
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) GetByID(ctx context.Context, id uint64) (*store.Model, error) {
|
||||
return s.modelDAO.GetByID(id)
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) GetByName(ctx context.Context, name string) (*store.Model, error) {
|
||||
return s.modelDAO.GetByName(name)
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) List(ctx context.Context, limit, offset int) ([]*store.Model, int64, error) {
|
||||
return s.modelDAO.List(limit, offset)
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) ListEnabled(ctx context.Context) ([]*store.Model, error) {
|
||||
return s.modelDAO.ListEnabled()
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) Update(ctx context.Context, model *store.Model) error {
|
||||
return s.modelDAO.Update(model)
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) Delete(ctx context.Context, id uint64) error {
|
||||
return s.modelDAO.Delete(id)
|
||||
}
|
||||
|
||||
func (s *ModelServiceImpl) Upsert(ctx context.Context, model *store.Model) error {
|
||||
return s.modelDAO.Upsert(model)
|
||||
}
|
||||
|
||||
// BindChannel binds a model to a channel
|
||||
func (s *ModelServiceImpl) BindChannel(ctx context.Context, modelID, channelID uint64, upstreamModel string, weight int) error {
|
||||
binding := store.ChannelModelBinding{
|
||||
ModelID: modelID,
|
||||
ChannelID: channelID,
|
||||
UpstreamModel: upstreamModel,
|
||||
Weight: weight,
|
||||
}
|
||||
return s.channelDAO.BindModels(channelID, []store.ChannelModelBinding{binding})
|
||||
}
|
||||
|
||||
// ListChannelModels lists all models bound to a channel
|
||||
func (s *ModelServiceImpl) ListChannelModels(ctx context.Context, channelID uint64) ([]store.ChannelModelBinding, error) {
|
||||
return s.channelDAO.GetChannelModels(channelID)
|
||||
}
|
||||
|
||||
// ListModelChannels lists all channels for a model
|
||||
func (s *ModelServiceImpl) ListModelChannels(ctx context.Context, modelName string) ([]*store.Channel, error) {
|
||||
return s.channelDAO.GetEnabledChannelsByModel(modelName)
|
||||
}
|
||||
Reference in New Issue
Block a user