add models for MailAccount and Mail
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kontor-api-gin/internal/models"
|
||||
"log/slog"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MailAccountRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewMailAccountRepository(db *gorm.DB) *MailAccountRepository {
|
||||
repository := &MailAccountRepository{db: db}
|
||||
return repository
|
||||
}
|
||||
|
||||
func (repository *MailAccountRepository) FindAll(context context.Context) ([]models.MailAccount, error) {
|
||||
var mailaccounts []models.MailAccount
|
||||
|
||||
result := repository.db.Find(&mailaccounts)
|
||||
slog.Info("MailAccountRepository#FindAll", "count", result.RowsAffected)
|
||||
|
||||
return mailaccounts, nil
|
||||
}
|
||||
|
||||
func (repository *MailAccountRepository) GetById(context context.Context, id string) (models.MailAccount, error) {
|
||||
var mailaccount = models.MailAccount{ID: id}
|
||||
slog.Info("MailAccountRepository#GetById", "id", id)
|
||||
result := repository.db.First(&mailaccount)
|
||||
if result.Error != nil {
|
||||
slog.Info("MailAccountRepository#GetById", "error", result.Error.Error())
|
||||
}
|
||||
return mailaccount, result.Error
|
||||
}
|
||||
Reference in New Issue
Block a user