Compare commits
26
Commits
24f0fe6efa
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
211f0154be | ||
|
|
136c4634c8 | ||
|
|
987ac2fe4a | ||
|
|
02d8a509ff | ||
|
|
e29bd7986f | ||
|
|
4bf318a9c2 | ||
|
|
52085a5be0 | ||
|
|
21c4c1efba | ||
|
|
c17540cc20 | ||
|
|
714b1ff4eb | ||
|
|
abc3ce8d2b | ||
|
|
cd1097d3d0 | ||
|
|
52991059c6 | ||
|
|
a7ef3f8ca2 | ||
|
|
6f1ac37915 | ||
|
|
e20c63e694 | ||
|
|
abcbc014a2 | ||
|
|
98b871a5ed | ||
|
|
3311b80943 | ||
|
|
16fef8706a | ||
|
|
4fbfa9c2c9 | ||
|
|
a68780f09e | ||
|
|
49dc0e4a7b | ||
|
|
09d9c4efb8 | ||
|
|
990026cece | ||
|
|
11051ae89c |
+5
-4
@@ -12,14 +12,15 @@ import (
|
|||||||
const (
|
const (
|
||||||
YAML_PATH = "env/%s"
|
YAML_PATH = "env/%s"
|
||||||
ENV_MODE = "ENV_MODE"
|
ENV_MODE = "ENV_MODE"
|
||||||
DEFAULT_ENV_MODE = "development"
|
DEFAULT_ENV_MODE = "local"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
validEnvMode = map[string]struct{}{
|
validEnvMode = map[string]struct{}{
|
||||||
"local": {},
|
"local": {},
|
||||||
"development": {},
|
"staging": {},
|
||||||
"production": {},
|
"production": {},
|
||||||
|
"debug": {},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ type Redis struct {
|
|||||||
DB int `mapstructure:"db"`
|
DB int `mapstructure:"db"`
|
||||||
Username string `mapstructure:"username"`
|
Username string `mapstructure:"username"`
|
||||||
Password string `mapstructure:"password"`
|
Password string `mapstructure:"password"`
|
||||||
SslMode string `mapstructure:"ssl-mode"`
|
SSL bool `mapstructure:"ssl"`
|
||||||
Debug bool `mapstructure:"debug"`
|
Debug bool `mapstructure:"debug"`
|
||||||
MaxIdleConnectionsInSecond int `mapstructure:"max-idle-connections-in-second"`
|
MaxIdleConnectionsInSecond int `mapstructure:"max-idle-connections-in-second"`
|
||||||
MaxOpenConnectionsInSecond int `mapstructure:"max-open-connections-in-second"`
|
MaxOpenConnectionsInSecond int `mapstructure:"max-open-connections-in-second"`
|
||||||
|
|||||||
+2
-1
@@ -15,12 +15,13 @@ type DB struct {
|
|||||||
|
|
||||||
func NewDB(cfg *config.Config) (*DB, error) {
|
func NewDB(cfg *config.Config) (*DB, error) {
|
||||||
dsn := fmt.Sprintf(
|
dsn := fmt.Sprintf(
|
||||||
"host=%s user=%s password=%s dbname=%s port=%v sslmode=disable",
|
"host=%s user=%s password=%s dbname=%s port=%v sslmode=%s",
|
||||||
cfg.Database.Host,
|
cfg.Database.Host,
|
||||||
cfg.Database.Username,
|
cfg.Database.Username,
|
||||||
cfg.Database.Password,
|
cfg.Database.Password,
|
||||||
cfg.Database.DB,
|
cfg.Database.DB,
|
||||||
cfg.Database.Port,
|
cfg.Database.Port,
|
||||||
|
cfg.Database.SslMode,
|
||||||
)
|
)
|
||||||
|
|
||||||
if dsn == "" {
|
if dsn == "" {
|
||||||
|
|||||||
Vendored
+43
@@ -0,0 +1,43 @@
|
|||||||
|
server:
|
||||||
|
base-url: https://api.legalgo.id/core
|
||||||
|
local-url: http://localhost:3300
|
||||||
|
port: 3300
|
||||||
|
|
||||||
|
jwt:
|
||||||
|
token:
|
||||||
|
expires-ttl: 1440
|
||||||
|
secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs"
|
||||||
|
|
||||||
|
postgresql:
|
||||||
|
host: dpg-d046h549c44c739arfv0-a.singapore-postgres.render.com
|
||||||
|
port: 5432
|
||||||
|
driver: postgres
|
||||||
|
db: legalgonews_prod
|
||||||
|
username: legalgo_admin
|
||||||
|
password: "656ogwc0JlLEVQyHnT5RrrYa7762iBQQ"
|
||||||
|
ssl-mode: require
|
||||||
|
max-idle-connections-in-second: 600
|
||||||
|
max-open-connections-in-second: 600
|
||||||
|
connection-max-life-time-in-second: 600
|
||||||
|
debug: false
|
||||||
|
|
||||||
|
oss:
|
||||||
|
access_key_id: GTK7i3SVy9llQeGH0Htv
|
||||||
|
access_key_secret: 2psmKXZFpevA9n5ntSDRMqFBpZuSz32dvtXjYclf
|
||||||
|
endpoint: news-cdn.legalgo.id
|
||||||
|
bucket_name: uploads
|
||||||
|
log_level: Error
|
||||||
|
host_url: https://news-cdn.legalgo.id
|
||||||
|
public_url: https://news-cdn.legalgo.id
|
||||||
|
|
||||||
|
redis:
|
||||||
|
host: singapore-keyvalue.render.com
|
||||||
|
port: 6379
|
||||||
|
username: red-d046l42dbo4c73ea9iag
|
||||||
|
password: 7cZvu08JKuO9MPNxBb97tZCVNj0ZGNp2
|
||||||
|
db: 5
|
||||||
|
ssl: true
|
||||||
|
max-idle-connections-in-second: 600
|
||||||
|
max-open-connections-in-second: 600
|
||||||
|
connection-max-life-time-in-second: 600
|
||||||
|
debug: false
|
||||||
Vendored
+43
@@ -0,0 +1,43 @@
|
|||||||
|
server:
|
||||||
|
base-url: https://api.legalgo.id/core
|
||||||
|
local-url: http://localhost:3300
|
||||||
|
port: 3300
|
||||||
|
|
||||||
|
jwt:
|
||||||
|
token:
|
||||||
|
expires-ttl: 1440
|
||||||
|
secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs"
|
||||||
|
|
||||||
|
postgresql:
|
||||||
|
host: dpg-d04bi9juibrs73augcc0-a.singapore-postgres.render.com
|
||||||
|
port: 5432
|
||||||
|
driver: postgres
|
||||||
|
db: legalgonews_dev
|
||||||
|
username: legalgo_admin
|
||||||
|
password: "5h7DCBR1T8pug6AlbrHXqIDAr9o2vnky"
|
||||||
|
ssl-mode: require
|
||||||
|
max-idle-connections-in-second: 600
|
||||||
|
max-open-connections-in-second: 600
|
||||||
|
connection-max-life-time-in-second: 600
|
||||||
|
debug: false
|
||||||
|
|
||||||
|
oss:
|
||||||
|
access_key_id: GTK7i3SVy9llQeGH0Htv
|
||||||
|
access_key_secret: 2psmKXZFpevA9n5ntSDRMqFBpZuSz32dvtXjYclf
|
||||||
|
endpoint: news-cdn.legalgo.id
|
||||||
|
bucket_name: uploads-staging
|
||||||
|
log_level: Error
|
||||||
|
host_url: https://news-cdn.legalgo.id
|
||||||
|
public_url: https://news-cdn.legalgo.id
|
||||||
|
|
||||||
|
redis:
|
||||||
|
host: singapore-keyvalue.render.com
|
||||||
|
port: 6379
|
||||||
|
username: red-d04c8k49c44c739ga8dg
|
||||||
|
password: ItPzniHv94yr8vY4HTrhCfKoibqBh61T
|
||||||
|
db: 5
|
||||||
|
ssl: true
|
||||||
|
max-idle-connections-in-second: 600
|
||||||
|
max-open-connections-in-second: 600
|
||||||
|
connection-max-life-time-in-second: 600
|
||||||
|
debug: false
|
||||||
+13
-13
@@ -9,12 +9,12 @@ jwt:
|
|||||||
secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs"
|
secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs"
|
||||||
|
|
||||||
postgresql:
|
postgresql:
|
||||||
host: 62.72.45.250
|
host: dpg-d046h549c44c739arfv0-a
|
||||||
port: 20826
|
port: 5432
|
||||||
driver: postgres
|
driver: postgres
|
||||||
db: legalgonews-dev
|
db: legalgonews_prod
|
||||||
username: legalgo_admin
|
username: legalgo_admin
|
||||||
password: "K4K!2Kg7c@KW6H&4A2aBy2dFCRY3Sh"
|
password: "656ogwc0JlLEVQyHnT5RrrYa7762iBQQ"
|
||||||
ssl-mode: disable
|
ssl-mode: disable
|
||||||
max-idle-connections-in-second: 600
|
max-idle-connections-in-second: 600
|
||||||
max-open-connections-in-second: 600
|
max-open-connections-in-second: 600
|
||||||
@@ -22,18 +22,18 @@ postgresql:
|
|||||||
debug: false
|
debug: false
|
||||||
|
|
||||||
oss:
|
oss:
|
||||||
access_key_id: cf9a475e18bc7626cbdbf09709d82a64
|
access_key_id: GTK7i3SVy9llQeGH0Htv
|
||||||
access_key_secret: 91f3321294d3e23035427a0ecb893ada
|
access_key_secret: 2psmKXZFpevA9n5ntSDRMqFBpZuSz32dvtXjYclf
|
||||||
endpoint: sin1.contabostorage.com
|
endpoint: news-cdn.legalgo.id
|
||||||
bucket_name: legalgonews-dev
|
bucket_name: uploads
|
||||||
log_level: Error
|
log_level: Error
|
||||||
host_url: https://sin1.contabostorage.com
|
host_url: https://news-cdn.legalgo.id
|
||||||
public_url: https://sin1.contabostorage.com/fda98c2228f246f29a7e466b86b3b9e7
|
public_url: https://news-cdn.legalgo.id
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
host: 62.72.45.250
|
host: red-d046l42dbo4c73ea9iag
|
||||||
port: 26379
|
port: 6379
|
||||||
password: mDtpsyEW8W26vwLhglpO
|
password: 7cZvu08JKuO9MPNxBb97tZCVNj0ZGNp2
|
||||||
db: 5
|
db: 5
|
||||||
ssl: false
|
ssl: false
|
||||||
max-idle-connections-in-second: 600
|
max-idle-connections-in-second: 600
|
||||||
Vendored
+42
@@ -0,0 +1,42 @@
|
|||||||
|
server:
|
||||||
|
base-url: https://api.legalgo.id/core
|
||||||
|
local-url: http://localhost:3300
|
||||||
|
port: 3300
|
||||||
|
|
||||||
|
jwt:
|
||||||
|
token:
|
||||||
|
expires-ttl: 1440
|
||||||
|
secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs"
|
||||||
|
|
||||||
|
postgresql:
|
||||||
|
host: dpg-d04bi9juibrs73augcc0-a
|
||||||
|
port: 5432
|
||||||
|
driver: postgres
|
||||||
|
db: legalgonews_dev
|
||||||
|
username: legalgo_admin
|
||||||
|
password: "5h7DCBR1T8pug6AlbrHXqIDAr9o2vnky"
|
||||||
|
ssl-mode: disable
|
||||||
|
max-idle-connections-in-second: 600
|
||||||
|
max-open-connections-in-second: 600
|
||||||
|
connection-max-life-time-in-second: 600
|
||||||
|
debug: false
|
||||||
|
|
||||||
|
oss:
|
||||||
|
access_key_id: GTK7i3SVy9llQeGH0Htv
|
||||||
|
access_key_secret: 2psmKXZFpevA9n5ntSDRMqFBpZuSz32dvtXjYclf
|
||||||
|
endpoint: news-cdn.legalgo.id
|
||||||
|
bucket_name: uploads-staging
|
||||||
|
log_level: Error
|
||||||
|
host_url: https://news-cdn.legalgo.id
|
||||||
|
public_url: https://news-cdn.legalgo.id
|
||||||
|
|
||||||
|
redis:
|
||||||
|
host: red-d04c8k49c44c739ga8dg
|
||||||
|
port: 6379
|
||||||
|
password: ItPzniHv94yr8vY4HTrhCfKoibqBh61T
|
||||||
|
db: 5
|
||||||
|
ssl: false
|
||||||
|
max-idle-connections-in-second: 600
|
||||||
|
max-open-connections-in-second: 600
|
||||||
|
connection-max-life-time-in-second: 600
|
||||||
|
debug: false
|
||||||
@@ -12,9 +12,9 @@ const (
|
|||||||
notActive is_active = "false"
|
notActive is_active = "false"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, error) {
|
func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.NewsResponse, error) {
|
||||||
var news []newsdomain.News
|
var news []newsdomain.NewsResponse
|
||||||
query := a.db.
|
query := a.db.Table("news").
|
||||||
Preload("Tags").
|
Preload("Tags").
|
||||||
Preload("Categories").
|
Preload("Categories").
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
@@ -34,8 +34,12 @@ func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, erro
|
|||||||
query = query.Where("news.live_at <= ?", timeutils.Now())
|
query = query.Where("news.live_at <= ?", timeutils.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.Search != "" {
|
||||||
|
query = query.Where("news.title ILIKE ?", "%"+filter.Search+"%")
|
||||||
|
}
|
||||||
|
|
||||||
query.
|
query.
|
||||||
Select("news.*, COUNT(content_logs.content_id) as clicked").
|
Select("news.*, COUNT(content_logs.content_id) as views").
|
||||||
Group("news.id").
|
Group("news.id").
|
||||||
Order("news.created_at DESC")
|
Order("news.created_at DESC")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package newsrepository
|
||||||
|
|
||||||
|
import newsdomain "legalgo-BE-go/internal/domain/news"
|
||||||
|
|
||||||
|
func (a *accessor) GetByID(id string) (*newsdomain.News, error) {
|
||||||
|
var news newsdomain.News
|
||||||
|
|
||||||
|
if err := a.db.
|
||||||
|
Preload("Tags").
|
||||||
|
Preload("Categories").
|
||||||
|
Preload("Author").
|
||||||
|
First(&news, "id = ?", id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &news, nil
|
||||||
|
}
|
||||||
@@ -10,8 +10,9 @@ type accessor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type News interface {
|
type News interface {
|
||||||
GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, error)
|
GetAll(filter newsdomain.NewsFilter) ([]newsdomain.NewsResponse, error)
|
||||||
GetBySlug(string) (*newsdomain.News, error)
|
GetBySlug(string) (*newsdomain.News, error)
|
||||||
|
GetByID(string) (*newsdomain.News, error)
|
||||||
Create(newsdomain.News) error
|
Create(newsdomain.News) error
|
||||||
Update(newsdomain.News) error
|
Update(newsdomain.News) error
|
||||||
Delete(string) error
|
Delete(string) error
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func (r *OssRepositoryImpl) GetPublicURL(fileName string) string {
|
|||||||
if fileName == "" {
|
if fileName == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s:%s%s", r.cfg.GetPublicURL(), r.cfg.GetBucketName(), fileName)
|
return fmt.Sprintf("%s/%s%s", r.cfg.GetPublicURL(), r.cfg.GetBucketName(), fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *OssRepositoryImpl) DeleteObject(ctx context.Context, fileName string) error {
|
func (r *OssRepositoryImpl) DeleteObject(ctx context.Context, fileName string) error {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package redisaccessor
|
package redisaccessor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"legalgo-BE-go/config"
|
"legalgo-BE-go/config"
|
||||||
|
|
||||||
@@ -16,11 +17,19 @@ func Get() *redis.Client {
|
|||||||
func New(cfg *config.Config) *redis.Client {
|
func New(cfg *config.Config) *redis.Client {
|
||||||
addr := fmt.Sprintf("%s:%s", cfg.Redis.Host, cfg.Redis.Port)
|
addr := fmt.Sprintf("%s:%s", cfg.Redis.Host, cfg.Redis.Port)
|
||||||
|
|
||||||
redisClient = redis.NewClient(&redis.Options{
|
options := &redis.Options{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Password: cfg.Redis.Password,
|
Password: cfg.Redis.Password,
|
||||||
DB: cfg.Redis.DB,
|
DB: cfg.Redis.DB,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if cfg.Redis.Username != "" {
|
||||||
|
options.Username = cfg.Redis.Username
|
||||||
|
}
|
||||||
|
if cfg.Redis.SSL {
|
||||||
|
options.TLSConfig = &tls.Config{}
|
||||||
|
}
|
||||||
|
|
||||||
|
redisClient = redis.NewClient(options)
|
||||||
return redisClient
|
return redisClient
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package staffrepository
|
||||||
|
|
||||||
|
import staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||||
|
|
||||||
|
func (a *accessor) GetStaffs() ([]staffdomain.StaffProfile, error) {
|
||||||
|
var staffs []staffdomain.StaffProfile
|
||||||
|
|
||||||
|
if err := a.db.Table("staffs").Find(&staffs).Error; err != nil {
|
||||||
|
return staffs, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return staffs, nil
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ type Staff interface {
|
|||||||
GetStaffByEmail(string) (*staffdomain.Staff, error)
|
GetStaffByEmail(string) (*staffdomain.Staff, error)
|
||||||
GetStaffByID(string) (*staffdomain.Staff, error)
|
GetStaffByID(string) (*staffdomain.Staff, error)
|
||||||
GetUsers() ([]userdomain.UserProfile, error)
|
GetUsers() ([]userdomain.UserProfile, error)
|
||||||
|
GetStaffs() ([]staffdomain.StaffProfile, error)
|
||||||
Create(staffdomain.Staff) error
|
Create(staffdomain.Staff) error
|
||||||
Update(staffdomain.Staff) error
|
Update(staffdomain.Staff) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func GetAll(
|
|||||||
) {
|
) {
|
||||||
router.Get("/news", func(w http.ResponseWriter, r *http.Request) {
|
router.Get("/news", func(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
news []newsdomain.News
|
news []newsdomain.NewsResponse
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
@@ -24,11 +24,13 @@ func GetAll(
|
|||||||
category := query.Get("categories")
|
category := query.Get("categories")
|
||||||
tags := query.Get("tags")
|
tags := query.Get("tags")
|
||||||
activeOnly := query.Get("active")
|
activeOnly := query.Get("active")
|
||||||
|
search := query.Get("q")
|
||||||
|
|
||||||
news, err = newsSvc.GetAll(newsdomain.Filter{
|
news, err = newsSvc.GetAll(newsdomain.Filter{
|
||||||
Category: category,
|
Category: category,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Active: activeOnly,
|
Active: activeOnly,
|
||||||
|
Search: search,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package newshttp
|
||||||
|
|
||||||
|
import (
|
||||||
|
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||||
|
logssvc "legalgo-BE-go/internal/services/logs"
|
||||||
|
newssvc "legalgo-BE-go/internal/services/news"
|
||||||
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetByID(
|
||||||
|
router chi.Router,
|
||||||
|
newsSvc newssvc.News,
|
||||||
|
logSvc logssvc.Log,
|
||||||
|
) {
|
||||||
|
router.With(authmiddleware.Authorize()).Get("/staff/news/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := r.Context()
|
||||||
|
id := chi.URLParam(r, "id")
|
||||||
|
|
||||||
|
token, err := utils.GetToken(r)
|
||||||
|
if err != nil {
|
||||||
|
response.ResponseWithErrorCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrBadRequest.Code,
|
||||||
|
response.ErrBadRequest.HttpCode,
|
||||||
|
err.Error(),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
staffDetail, err := utils.DestructToken(token)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
response.ResponseWithErrorCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrBadRequest.Code,
|
||||||
|
response.ErrBadRequest.HttpCode,
|
||||||
|
err.Error(),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if staffDetail.Role != "staff" {
|
||||||
|
response.ResponseWithErrorCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrUnauthorized.Code,
|
||||||
|
response.ErrUnauthorized.HttpCode,
|
||||||
|
"unauthorized",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
news, err := newsSvc.GetByID(id)
|
||||||
|
if err != nil {
|
||||||
|
response.ResponseWithErrorCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrBadRequest.Code,
|
||||||
|
response.ErrBadRequest.HttpCode,
|
||||||
|
err.Error(),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.RespondJsonSuccess(ctx, w, news)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import "go.uber.org/fx"
|
|||||||
var Module = fx.Module("news", fx.Invoke(
|
var Module = fx.Module("news", fx.Invoke(
|
||||||
GetAll,
|
GetAll,
|
||||||
GetBySlug,
|
GetBySlug,
|
||||||
|
GetByID,
|
||||||
Create,
|
Create,
|
||||||
Update,
|
Update,
|
||||||
Delete,
|
Delete,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||||
newsdomain "legalgo-BE-go/internal/domain/news"
|
newsdomain "legalgo-BE-go/internal/domain/news"
|
||||||
newssvc "legalgo-BE-go/internal/services/news"
|
newssvc "legalgo-BE-go/internal/services/news"
|
||||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package staffhttp
|
||||||
|
|
||||||
|
import (
|
||||||
|
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||||
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetStaffs(
|
||||||
|
router chi.Router,
|
||||||
|
staffSvc staffsvc.Auth,
|
||||||
|
) {
|
||||||
|
router.With(authmiddleware.Authorize()).Get("/staff/get-all", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := r.Context()
|
||||||
|
staffDetail, err := utils.GetTokenDetail(r)
|
||||||
|
if err != nil {
|
||||||
|
response.RespondJsonErrorWithCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrBadRequest.Code,
|
||||||
|
response.ErrBadRequest.HttpCode,
|
||||||
|
"failed to get staff token",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if staffDetail.Role != "staff" {
|
||||||
|
response.RespondJsonErrorWithCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrUnauthorized.Code,
|
||||||
|
response.ErrUnauthorized.HttpCode,
|
||||||
|
"unauthorized",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
staffs, err := staffSvc.GetStaffs()
|
||||||
|
if err != nil {
|
||||||
|
response.RespondJsonErrorWithCode(
|
||||||
|
ctx,
|
||||||
|
w,
|
||||||
|
err,
|
||||||
|
response.ErrBadRequest.Code,
|
||||||
|
response.ErrBadRequest.HttpCode,
|
||||||
|
err.Error(),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.RespondJsonSuccess(ctx, w, staffs)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package staffhttp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
responsedomain "legalgo-BE-go/internal/domain/reponse"
|
responsedomain "legalgo-BE-go/internal/domain/reponse"
|
||||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
|
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ var Module = fx.Module("auth-api",
|
|||||||
Update,
|
Update,
|
||||||
GetProfile,
|
GetProfile,
|
||||||
GetUsers,
|
GetUsers,
|
||||||
|
GetStaffs,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package staffhttp
|
package staffhttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package staffhttp
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
responsedomain "legalgo-BE-go/internal/domain/reponse"
|
|
||||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ func Register(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := authSvc.Register(spec)
|
_, err := authSvc.Register(spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ResponseWithErrorCode(
|
response.ResponseWithErrorCode(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -62,21 +61,10 @@ func Register(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.StoreTokenRedis(ctx, rdb, token, spec.Email); err != nil {
|
response.RespondJsonSuccess(ctx, w, struct {
|
||||||
response.ResponseWithErrorCode(
|
Message string
|
||||||
ctx,
|
}{
|
||||||
w,
|
Message: "staff created successfully.",
|
||||||
err,
|
})
|
||||||
response.ErrBadRequest.Code,
|
|
||||||
response.ErrBadRequest.HttpCode,
|
|
||||||
err.Error(),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
responsePayload := &responsedomain.Auth{
|
|
||||||
Token: token,
|
|
||||||
}
|
|
||||||
response.RespondJsonSuccess(ctx, w, responsePayload)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package staffhttp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|||||||
@@ -27,19 +27,23 @@ type News struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
FeaturedImage string `json:"featured_image"`
|
FeaturedImage string `json:"featured_image"`
|
||||||
Tags []tagdomain.Tag `gorm:"many2many:news_tags" json:"tags"`
|
Tags []tagdomain.Tag `gorm:"many2many:news_tags;foreignKey:ID;joinForeignKey:news_id;References:ID;joinReferences:tag_id" json:"tags"`
|
||||||
Categories []categorydomain.Category `gorm:"many2many:news_categories" json:"categories"`
|
Categories []categorydomain.Category `gorm:"many2many:news_categories;foreignKey:ID;joinForeignKey:news_id;References:ID;joinReferences:category_id" json:"categories"`
|
||||||
IsPremium bool `json:"is_premium"`
|
IsPremium bool `json:"is_premium"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
AuthorID string `json:"author_id"`
|
AuthorID string `json:"author_id"`
|
||||||
LiveAt time.Time `json:"live_at"`
|
LiveAt time.Time `json:"live_at"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
Clicked int64 `json:"clicked"`
|
|
||||||
|
|
||||||
Author Staff `json:"author"`
|
Author Staff `json:"author"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NewsResponse struct {
|
||||||
|
News
|
||||||
|
Views int64 `json:"views"`
|
||||||
|
}
|
||||||
|
|
||||||
type NewsUpdate struct {
|
type NewsUpdate struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
@@ -52,11 +56,12 @@ type NewsUpdate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
Category, Tags, Active string
|
Category, Tags, Active, Search string
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewsFilter struct {
|
type NewsFilter struct {
|
||||||
Tags []string
|
Tags []string
|
||||||
Category []string
|
Category []string
|
||||||
Active string
|
Active string
|
||||||
|
Search string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
logssvc "legalgo-BE-go/internal/services/logs"
|
logssvc "legalgo-BE-go/internal/services/logs"
|
||||||
newssvc "legalgo-BE-go/internal/services/news"
|
newssvc "legalgo-BE-go/internal/services/news"
|
||||||
"legalgo-BE-go/internal/services/oss"
|
"legalgo-BE-go/internal/services/oss"
|
||||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||||
subscribesvc "legalgo-BE-go/internal/services/subscribe"
|
subscribesvc "legalgo-BE-go/internal/services/subscribe"
|
||||||
subscribeplansvc "legalgo-BE-go/internal/services/subscribe_plan"
|
subscribeplansvc "legalgo-BE-go/internal/services/subscribe_plan"
|
||||||
tagsvc "legalgo-BE-go/internal/services/tag"
|
tagsvc "legalgo-BE-go/internal/services/tag"
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.News, error) {
|
func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.NewsResponse, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
categories := []string{}
|
categories := []string{}
|
||||||
tags := []string{}
|
tags := []string{}
|
||||||
news := []newsdomain.News{}
|
news := []newsdomain.NewsResponse{}
|
||||||
|
|
||||||
tagCodeArr := strings.Split(filter.Tags, " ")
|
tagCodeArr := strings.Split(filter.Tags, " ")
|
||||||
categoryCodeArr := strings.Split(filter.Category, " ")
|
categoryCodeArr := strings.Split(filter.Category, " ")
|
||||||
@@ -41,6 +41,7 @@ func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.News, error) {
|
|||||||
Tags: tags,
|
Tags: tags,
|
||||||
Category: categories,
|
Category: categories,
|
||||||
Active: filter.Active,
|
Active: filter.Active,
|
||||||
|
Search: filter.Search,
|
||||||
}
|
}
|
||||||
return i.newsRepo.GetAll(filterSpec)
|
return i.newsRepo.GetAll(filterSpec)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package newssvc
|
||||||
|
|
||||||
|
import newsdomain "legalgo-BE-go/internal/domain/news"
|
||||||
|
|
||||||
|
func (i *impl) GetByID(id string) (*newsdomain.News, error) {
|
||||||
|
return i.newsRepo.GetByID(id)
|
||||||
|
}
|
||||||
@@ -16,8 +16,9 @@ type impl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type News interface {
|
type News interface {
|
||||||
GetAll(filter newsdomain.Filter) ([]newsdomain.News, error)
|
GetAll(filter newsdomain.Filter) ([]newsdomain.NewsResponse, error)
|
||||||
GetBySlug(string) (*newsdomain.News, error)
|
GetBySlug(string) (*newsdomain.News, error)
|
||||||
|
GetByID(string) (*newsdomain.News, error)
|
||||||
Create(newsdomain.NewsReq, string) error
|
Create(newsdomain.NewsReq, string) error
|
||||||
Update(string, newsdomain.NewsUpdate) error
|
Update(string, newsdomain.NewsUpdate) error
|
||||||
Delete(string) error
|
Delete(string) error
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package staffsvc
|
||||||
|
|
||||||
|
import staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||||
|
|
||||||
|
func (i *impl) GetStaffs() ([]staffdomain.StaffProfile, error) {
|
||||||
|
return i.staffRepo.GetStaffs()
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ type Auth interface {
|
|||||||
Login(staffdomain.StaffLogin) (string, error)
|
Login(staffdomain.StaffLogin) (string, error)
|
||||||
Register(staffdomain.StaffRegister) (string, error)
|
Register(staffdomain.StaffRegister) (string, error)
|
||||||
GetProfile(string) (*staffdomain.StaffProfile, error)
|
GetProfile(string) (*staffdomain.StaffProfile, error)
|
||||||
|
GetStaffs() ([]staffdomain.StaffProfile, error)
|
||||||
GetUsers() ([]userdomain.UserProfile, error)
|
GetUsers() ([]userdomain.UserProfile, error)
|
||||||
Update(string, staffdomain.StaffUpdate) error
|
Update(string, staffdomain.StaffUpdate) error
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user