...
|
...
|
@@ -3,7 +3,6 @@ package repository |
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
...
|
...
|
@@ -15,49 +14,37 @@ type StaffAssessContentTempRepository struct { |
|
|
transactionContext *pgTransaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
// var _ domain.StaffAssessContentRepository = (*StaffAssessContentTempRepository)(nil)
|
|
|
var _ domain.StaffAssessContentTempRepository = (*StaffAssessContentTempRepository)(nil)
|
|
|
|
|
|
func NewStaffAssessContentTempRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessContentTempRepository {
|
|
|
return &StaffAssessContentTempRepository{transactionContext: transactionContext}
|
|
|
}
|
|
|
|
|
|
func (repo *StaffAssessContentTempRepository) TransformToDomain(d *models.StaffAssessContent) *domain.StaffAssessContent {
|
|
|
return &domain.StaffAssessContent{
|
|
|
func (repo *StaffAssessContentTempRepository) TransformToDomain(d *models.StaffAssessContentTemp) *domain.StaffAssessContentTemp {
|
|
|
return &domain.StaffAssessContentTemp{
|
|
|
Id: d.Id,
|
|
|
StaffAssessId: d.StaffAssessId,
|
|
|
SortBy: d.SortBy,
|
|
|
Category: d.Category,
|
|
|
Name: d.Name,
|
|
|
PromptTitle: d.PromptTitle,
|
|
|
PromptText: d.PromptText,
|
|
|
Remark: d.Remark,
|
|
|
Value: d.Value,
|
|
|
ReteResult: d.ReteResult,
|
|
|
Rule: d.Rule,
|
|
|
Weight: d.Weight,
|
|
|
CreatedAt: d.CreatedAt,
|
|
|
UpdatedAt: d.UpdatedAt,
|
|
|
DeletedAt: nil,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (repo *StaffAssessContentTempRepository) Save(d *domain.StaffAssessContent) (*domain.StaffAssessContent, error) {
|
|
|
saveModel := models.StaffAssessContent{
|
|
|
func (repo *StaffAssessContentTempRepository) Save(d *domain.StaffAssessContentTemp) (*domain.StaffAssessContentTemp, error) {
|
|
|
saveModel := models.StaffAssessContentTemp{
|
|
|
Id: d.Id,
|
|
|
StaffAssessId: d.StaffAssessId,
|
|
|
SortBy: d.SortBy,
|
|
|
Category: d.Category,
|
|
|
Name: d.Name,
|
|
|
PromptTitle: d.PromptTitle,
|
|
|
PromptText: d.PromptText,
|
|
|
Remark: d.Remark,
|
|
|
Value: d.Value,
|
|
|
ReteResult: d.ReteResult,
|
|
|
Rule: d.Rule,
|
|
|
CreatedAt: d.CreatedAt,
|
|
|
UpdatedAt: d.UpdatedAt,
|
|
|
Weight: d.Weight,
|
|
|
DeletedAt: nil,
|
|
|
}
|
|
|
tx := repo.transactionContext.PgTx
|
|
|
var err error
|
...
|
...
|
@@ -78,19 +65,15 @@ func (repo *StaffAssessContentTempRepository) Save(d *domain.StaffAssessContent) |
|
|
|
|
|
func (repo *StaffAssessContentTempRepository) Remove(id int) error {
|
|
|
tx := repo.transactionContext.PgTx
|
|
|
nowTime := time.Now()
|
|
|
_, err := tx.Model(&models.StaffAssessContent{}).
|
|
|
Where("id=?", id).
|
|
|
Set("deleted_at=?", nowTime).
|
|
|
Update()
|
|
|
_, err := tx.Model(&models.StaffAssessContentTemp{}).
|
|
|
Where("id=?", id).Delete()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (repo *StaffAssessContentTempRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessContent, error) {
|
|
|
func (repo *StaffAssessContentTempRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessContentTemp, error) {
|
|
|
tx := repo.transactionContext.PgTx
|
|
|
m := new(models.StaffAssessContent)
|
|
|
m := new(models.StaffAssessContentTemp)
|
|
|
query := tx.Model(m)
|
|
|
query.Where("deleted_at isnull")
|
|
|
if id, ok := queryOptions["id"]; ok {
|
|
|
query.Where("id=?", id)
|
|
|
}
|
...
|
...
|
@@ -105,20 +88,13 @@ func (repo *StaffAssessContentTempRepository) FindOne(queryOptions map[string]in |
|
|
return u, nil
|
|
|
}
|
|
|
|
|
|
func (repo *StaffAssessContentTempRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessContent, error) {
|
|
|
func (repo *StaffAssessContentTempRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessContentTemp, error) {
|
|
|
tx := repo.transactionContext.PgTx
|
|
|
var m []*models.StaffAssessContent
|
|
|
query := tx.Model(&m).
|
|
|
Where("deleted_at isnull")
|
|
|
var m []*models.StaffAssessContentTemp
|
|
|
query := tx.Model(&m)
|
|
|
if companyId, ok := queryOptions["companyId"]; ok {
|
|
|
query.Where("company_id = ?", companyId)
|
|
|
}
|
|
|
if v, ok := queryOptions["limit"].(int); ok {
|
|
|
query.Limit(v)
|
|
|
}
|
|
|
if v, ok := queryOptions["offset"].(int); ok {
|
|
|
query.Offset(v)
|
|
|
}
|
|
|
if v, ok := queryOptions["staffAssessId"]; ok {
|
|
|
query.Where("staff_assess_id=?", v)
|
|
|
}
|
...
|
...
|
@@ -126,7 +102,7 @@ func (repo *StaffAssessContentTempRepository) Find(queryOptions map[string]inter |
|
|
if err != nil {
|
|
|
return 0, nil, err
|
|
|
}
|
|
|
var arrays []*domain.StaffAssessContent
|
|
|
var arrays []*domain.StaffAssessContentTemp
|
|
|
for _, v := range m {
|
|
|
d := repo.TransformToDomain(v)
|
|
|
arrays = append(arrays, d)
|
...
|
...
|
|