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