first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 21:43:40 +03:00
commit f34e54c5a5
100 changed files with 27342 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package services
import (
"errors"
"gobeyhan/database"
"gobeyhan/database/models"
"gorm.io/gorm"
)
type SocialAccountService struct{}
func NewSocialAccountService() *SocialAccountService {
return &SocialAccountService{}
}
// GetSocialAccountsByUser retrieves all social accounts for a user
func (s *SocialAccountService) GetSocialAccountsByUser(userID uint64) ([]models.SocialAccount, error) {
var accounts []models.SocialAccount
err := database.DB.Where("user_id = ?", userID).Find(&accounts).Error
return accounts, err
}
// GetSocialAccountByID retrieves a social account by ID
func (s *SocialAccountService) GetSocialAccountByID(id uint64) (*models.SocialAccount, error) {
var account models.SocialAccount
err := database.DB.First(&account, id).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, err
}
return &account, nil
}
// CreateSocialAccount creates a new social account
func (s *SocialAccountService) CreateSocialAccount(account *models.SocialAccount) error {
return database.DB.Create(account).Error
}
// DeleteSocialAccount deletes a social account by ID
func (s *SocialAccountService) DeleteSocialAccount(id uint64) error {
result := database.DB.Delete(&models.SocialAccount{}, id)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return gorm.ErrRecordNotFound
}
return nil
}