feat: update article categories and article service
This commit is contained in:
parent
f4972268f0
commit
78e7c3f026
|
|
@ -2,6 +2,7 @@ package repository
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/article_categories/request"
|
||||
|
|
@ -11,6 +12,7 @@ import (
|
|||
|
||||
type articleCategoriesRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// ArticleCategoriesRepository define interface of IArticleCategoriesRepository
|
||||
|
|
@ -22,9 +24,10 @@ type ArticleCategoriesRepository interface {
|
|||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewArticleCategoriesRepository(db *database.Database) ArticleCategoriesRepository {
|
||||
func NewArticleCategoriesRepository(db *database.Database, log zerolog.Logger) ArticleCategoriesRepository {
|
||||
return &articleCategoriesRepository{
|
||||
DB: db,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +69,7 @@ func (_i *articleCategoriesRepository) GetAll(req request.ArticleCategoriesQuery
|
|||
req.Pagination = paginator.Paging(req.Pagination)
|
||||
|
||||
err = query.Offset(req.Pagination.Offset).Limit(req.Pagination.Limit).Find(&articleCategoriess).Error
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,18 +195,34 @@ func (_i *articlesService) Delete(id uint) error {
|
|||
|
||||
func (_i *articlesService) Viewer(c *fiber.Ctx) (err error) {
|
||||
thumbnailName := c.Params("thumbnailName")
|
||||
|
||||
emptyImage := "empty-image.jpg"
|
||||
searchThumbnail := emptyImage
|
||||
if thumbnailName != emptyImage {
|
||||
result, err := _i.Repo.FindByFilename(thumbnailName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "articlesService:Viewer").
|
||||
Interface("resultThumbnail", result.ThumbnailPath).Msg("")
|
||||
|
||||
if result.ThumbnailPath == nil {
|
||||
return nil
|
||||
if result.ThumbnailPath != nil {
|
||||
searchThumbnail = *result.ThumbnailPath
|
||||
} else {
|
||||
searchThumbnail = "articles/thumbnail/" + emptyImage
|
||||
}
|
||||
} else {
|
||||
searchThumbnail = "articles/thumbnail/" + emptyImage
|
||||
}
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "articlesService:Viewer").
|
||||
Interface("searchThumbnail", searchThumbnail).Msg("")
|
||||
|
||||
ctx := context.Background()
|
||||
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||
objectName := result.ThumbnailPath
|
||||
objectName := searchThumbnail
|
||||
|
||||
// Create minio connection.
|
||||
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||
|
|
@ -218,13 +234,13 @@ func (_i *articlesService) Viewer(c *fiber.Ctx) (err error) {
|
|||
})
|
||||
}
|
||||
|
||||
fileContent, err := minioClient.GetObject(ctx, bucketName, *objectName, minio.GetObjectOptions{})
|
||||
fileContent, err := minioClient.GetObject(ctx, bucketName, objectName, minio.GetObjectOptions{})
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer fileContent.Close()
|
||||
|
||||
contentType := mime.TypeByExtension("." + getFileExtension(*objectName))
|
||||
contentType := mime.TypeByExtension("." + getFileExtension(objectName))
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ production = false
|
|||
body-limit = 104857600 # "100 * 1024 * 1024"
|
||||
|
||||
[db.postgres]
|
||||
dsn = "postgresql://humas_user:HumasDB#2024@38.47.180.165:5432/humas_db" # <driver>://<username>:<password>@<host>:<port>/<database>
|
||||
dsn = "postgresql://humas_user:HumasDB@2024@38.47.180.165:5432/humas_db" # <driver>://<username>:<password>@<host>:<port>/<database>
|
||||
migrate = false
|
||||
seed = false
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue