74 lines
2.5 KiB
Go
74 lines
2.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
channelmodel "github.com/gochat/gochat/internal/model/channel"
|
|
"github.com/gochat/gochat/internal/repository"
|
|
applogger "github.com/gochat/gochat/pkg/logger"
|
|
)
|
|
|
|
// ChannelLINEService implements business logic for LINE channel operations.
|
|
// Reference: LINE Messaging API — https://developers.line.biz/en/docs/messaging-api/
|
|
//
|
|
// LINE Official Account channels use the LINE Messaging API to send/receive
|
|
// messages via a connected LINE Official Account. The Channel Access Token grants
|
|
// messaging permissions for LINE interactions.
|
|
type ChannelLINEService struct {
|
|
repo *repository.ChannelLINERepo
|
|
}
|
|
|
|
// NewChannelLINEService creates a new ChannelLINE service.
|
|
func NewChannelLINEService(repo *repository.ChannelLINERepo) *ChannelLINEService {
|
|
return &ChannelLINEService{repo: repo}
|
|
}
|
|
|
|
// GetByID retrieves a LINE channel by ID.
|
|
func (s *ChannelLINEService) GetByID(ctx context.Context, id uint) (*channelmodel.ChannelLINE, error) {
|
|
return s.repo.FindByID(ctx, id)
|
|
}
|
|
|
|
// GetByChannelID retrieves a LINE channel by LINE Channel ID.
|
|
func (s *ChannelLINEService) GetByChannelID(ctx context.Context, channelID string) (*channelmodel.ChannelLINE, error) {
|
|
return s.repo.FindByChannelID(ctx, channelID)
|
|
}
|
|
|
|
// Create inserts a new LINE channel record.
|
|
func (s *ChannelLINEService) Create(ctx context.Context, ch *channelmodel.ChannelLINE) error {
|
|
if err := s.repo.Create(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to create LINE channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("LINE channel created: id=%d channel_id=%s", ch.ID, ch.ChannelID)
|
|
return nil
|
|
}
|
|
|
|
// Update modifies an existing LINE channel.
|
|
func (s *ChannelLINEService) Update(ctx context.Context, ch *channelmodel.ChannelLINE) error {
|
|
if err := s.repo.Update(ctx, ch); err != nil {
|
|
applogger.L().Errorf("Failed to update LINE channel: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete soft-deletes a LINE channel.
|
|
func (s *ChannelLINEService) Delete(ctx context.Context, id uint) error {
|
|
if err := s.repo.Delete(ctx, id); err != nil {
|
|
applogger.L().Errorf("Failed to delete LINE channel: %v", err)
|
|
return err
|
|
}
|
|
applogger.L().Infof("LINE channel deleted: id=%d", id)
|
|
return nil
|
|
}
|
|
|
|
// List retrieves all LINE channels.
|
|
func (s *ChannelLINEService) List(ctx context.Context) ([]channelmodel.ChannelLINE, error) {
|
|
return s.repo.List(ctx)
|
|
}
|
|
|
|
// ListByAccount retrieves all LINE channels for a given account.
|
|
func (s *ChannelLINEService) ListByAccount(ctx context.Context, accountID uint) ([]channelmodel.ChannelLINE, error) {
|
|
return s.repo.ListByAccount(ctx, accountID)
|
|
}
|