feat: update fixing publish scheduling
This commit is contained in:
parent
5699c1b7fa
commit
e5666ef452
|
|
@ -3,6 +3,7 @@ package repository
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
"web-medols-be/app/database"
|
||||
"web-medols-be/app/database/entity"
|
||||
"web-medols-be/app/module/article_files/request"
|
||||
|
|
@ -10,10 +11,12 @@ import (
|
|||
utilSvc "web-medols-be/utils/service"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type articleFilesRepository struct {
|
||||
DB *database.Database
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// ArticleFilesRepository define interface of IArticleFilesRepository
|
||||
|
|
@ -27,9 +30,10 @@ type ArticleFilesRepository interface {
|
|||
Delete(clientId *uuid.UUID, id uint) (err error)
|
||||
}
|
||||
|
||||
func NewArticleFilesRepository(db *database.Database) ArticleFilesRepository {
|
||||
func NewArticleFilesRepository(db *database.Database, log zerolog.Logger) ArticleFilesRepository {
|
||||
return &articleFilesRepository{
|
||||
DB: db,
|
||||
DB: db,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +162,7 @@ func (_i *articleFilesRepository) Update(clientId *uuid.UUID, id uint, articleFi
|
|||
ClientId: articleFiles.ClientId,
|
||||
IsActive: articleFiles.IsActive,
|
||||
CreatedAt: articleFiles.CreatedAt,
|
||||
UpdatedAt: articleFiles.UpdatedAt,
|
||||
UpdatedAt: time.Time{},
|
||||
// Exclude Article relation field
|
||||
}
|
||||
|
||||
|
|
@ -166,6 +170,12 @@ func (_i *articleFilesRepository) Update(clientId *uuid.UUID, id uint, articleFi
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Remove any relation fields that might have been included
|
||||
delete(articleFilesMap, "article")
|
||||
|
||||
_i.Log.Info().Interface("articleFilesMap : ", articleFilesMap).Msg("")
|
||||
|
||||
return _i.DB.DB.Model(&entity.ArticleFiles{}).
|
||||
Where(&entity.ArticleFiles{ID: id}).
|
||||
Updates(articleFilesMap).Error
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import (
|
|||
"web-medols-be/app/module/article_files/request"
|
||||
"web-medols-be/app/module/article_files/response"
|
||||
config "web-medols-be/config/config"
|
||||
minioStorage "web-medols-be/config/config"
|
||||
"web-medols-be/utils/paginator"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
|
@ -33,7 +32,7 @@ type articleFilesService struct {
|
|||
Repo repository.ArticleFilesRepository
|
||||
Log zerolog.Logger
|
||||
Cfg *config.Config
|
||||
MinioStorage *minioStorage.MinioStorage
|
||||
MinioStorage *config.MinioStorage
|
||||
}
|
||||
|
||||
// ArticleFilesService define interface of IArticleFilesService
|
||||
|
|
@ -49,7 +48,7 @@ type ArticleFilesService interface {
|
|||
}
|
||||
|
||||
// NewArticleFilesService init ArticleFilesService
|
||||
func NewArticleFilesService(repo repository.ArticleFilesRepository, log zerolog.Logger, cfg *config.Config, minioStorage *minioStorage.MinioStorage) ArticleFilesService {
|
||||
func NewArticleFilesService(repo repository.ArticleFilesRepository, log zerolog.Logger, cfg *config.Config, minioStorage *config.MinioStorage) ArticleFilesService {
|
||||
|
||||
return &articleFilesService{
|
||||
Repo: repo,
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ func (_i *articlesRepository) GetAll(clientId *uuid.UUID, userLevelId *uint, req
|
|||
}
|
||||
|
||||
func (_i *articlesRepository) GetAllPublishSchedule(clientId *uuid.UUID) (articles []*entity.Articles, err error) {
|
||||
query := _i.DB.DB.Where("publish_schedule IS NOT NULL")
|
||||
query := _i.DB.DB.Where("publish_schedule IS NOT NULL and is_publish = false")
|
||||
if clientId != nil {
|
||||
query = query.Where("client_id = ?", clientId)
|
||||
}
|
||||
|
|
@ -300,7 +300,7 @@ func (_i *articlesRepository) UpdateSkipNull(clientId *uuid.UUID, id uint, artic
|
|||
// Clear fields that could cause foreign key constraint violations
|
||||
updateData.WorkflowId = nil
|
||||
updateData.ID = 0
|
||||
updateData.CreatedAt = time.Time{}
|
||||
updateData.UpdatedAt = time.Time{}
|
||||
|
||||
return _i.DB.DB.Model(&entity.Articles{}).
|
||||
Where(&entity.Articles{ID: id}).
|
||||
|
|
|
|||
|
|
@ -723,8 +723,12 @@ func (_i *articlesService) ExecuteScheduling() error {
|
|||
Interface("Article ID", article.ID).Msg("")
|
||||
continue
|
||||
}
|
||||
// If parsed as date only, set time to start of day (00:00:00)
|
||||
scheduledTime = scheduledTime.Truncate(24 * time.Hour)
|
||||
// If parsed as date only, set time to start of day (00:00:00) in local timezone
|
||||
scheduledTime = time.Date(scheduledTime.Year(), scheduledTime.Month(), scheduledTime.Day(), 0, 0, 0, 0, now.Location())
|
||||
} else {
|
||||
// For datetime format, parse in local timezone
|
||||
scheduledTime = time.Date(scheduledTime.Year(), scheduledTime.Month(), scheduledTime.Day(),
|
||||
scheduledTime.Hour(), scheduledTime.Minute(), scheduledTime.Second(), 0, now.Location())
|
||||
}
|
||||
|
||||
// Check if the scheduled time has passed (for datetime) or if it's today (for date only)
|
||||
|
|
@ -735,7 +739,8 @@ func (_i *articlesService) ExecuteScheduling() error {
|
|||
} else {
|
||||
// For date-only format, check if it's today
|
||||
today := now.Truncate(24 * time.Hour)
|
||||
shouldPublish = scheduledTime.Equal(today)
|
||||
scheduledDate := scheduledTime.Truncate(24 * time.Hour)
|
||||
shouldPublish = scheduledDate.Equal(today) || scheduledDate.Before(today)
|
||||
}
|
||||
|
||||
if shouldPublish {
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue