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 MailRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewMailRepository(db *gorm.DB) *MailRepository {
|
||||
repository := &MailRepository{db: db}
|
||||
return repository
|
||||
}
|
||||
|
||||
func (repository *MailRepository) FindAll(context context.Context) ([]models.Mail, error) {
|
||||
var mails []models.Mail
|
||||
|
||||
result := repository.db.Find(&mails)
|
||||
slog.Info("MailRepository#FindAll", "count", result.RowsAffected)
|
||||
|
||||
return mails, nil
|
||||
}
|
||||
|
||||
func (repository *MailRepository) GetById(context context.Context, id string) (models.Mail, error) {
|
||||
var mail = models.Mail{ID: id}
|
||||
slog.Info("MailRepository#GetById", "id", id)
|
||||
result := repository.db.First(&mail)
|
||||
if result.Error != nil {
|
||||
slog.Info("MailRepository#GetById", "error", result.Error.Error())
|
||||
}
|
||||
return mail, result.Error
|
||||
}
|
||||
Reference in New Issue
Block a user