Compare commits
10 Commits
40fdb80f5c
...
f09e28830b
| Author | SHA1 | Date |
|---|---|---|
|
|
f09e28830b | |
|
|
513b086e23 | |
|
|
0d7d08ce6b | |
|
|
335e88fd6d | |
|
|
e4eb6f9088 | |
|
|
4ae4adca48 | |
|
|
98689f8f81 | |
|
|
d5e7a5f55a | |
|
|
652b720a79 | |
|
|
c646ab1eb6 |
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -57,9 +57,9 @@ func (m *Middleware) Register(db *database.Database) {
|
|||
|
||||
m.App.Use(cors.New(cors.Config{
|
||||
Next: utilsSvc.IsEnabled(m.Cfg.Middleware.Cors.Enable),
|
||||
AllowOrigins: "http://localhost:3000, http://localhost:4000, https://kontenhumas.com",
|
||||
AllowOrigins: "http://localhost:3000, http://localhost:4000, https://kontenhumas.com, https://mediapool.id, https://polrinews-project.vercel.app, http://127.0.0.1:3000, http://10.200.202.141",
|
||||
AllowMethods: "HEAD, GET, POST, PUT, DELETE, OPTION, PATCH",
|
||||
AllowHeaders: "Origin, Content-Type, Accept, Accept-Language, Authorization, X-Requested-With, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Credentials, X-Csrf-Token, Cookie, Set-Cookie",
|
||||
AllowHeaders: "Origin, Content-Type, Accept, Accept-Language, Authorization, X-Requested-With, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Origin, Access-Control-Allow-Credentials, X-Csrf-Token, Cookie, Set-Cookie",
|
||||
ExposeHeaders: "Content-Length, Content-Type",
|
||||
AllowCredentials: true,
|
||||
MaxAge: 12,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ func (_i *ArticlesRouter) RegisterArticlesRoutes() {
|
|||
// define routes
|
||||
_i.App.Route("/articles", func(router fiber.Router) {
|
||||
router.Get("/", articlesController.All)
|
||||
router.Get("/old-id/:id", articlesController.ShowByOldId)
|
||||
router.Get("/:id", articlesController.Show)
|
||||
router.Post("/", articlesController.Save)
|
||||
router.Put("/:id", articlesController.Update)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type articlesController struct {
|
|||
type ArticlesController interface {
|
||||
All(c *fiber.Ctx) error
|
||||
Show(c *fiber.Ctx) error
|
||||
ShowByOldId(c *fiber.Ctx) error
|
||||
Save(c *fiber.Ctx) error
|
||||
SaveThumbnail(c *fiber.Ctx) error
|
||||
Update(c *fiber.Ctx) error
|
||||
|
|
@ -111,6 +112,35 @@ func (_i *articlesController) Show(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// ShowByOldId Articles
|
||||
// @Summary Get one Articles
|
||||
// @Description API for getting one Articles
|
||||
// @Tags Articles
|
||||
// @Security Bearer
|
||||
// @Param id path int true "Articles Old ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /articles/old-id/{id} [get]
|
||||
func (_i *articlesController) ShowByOldId(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
articlesData, err := _i.articlesService.ShowByOldId(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"Articles successfully retrieved"},
|
||||
Data: articlesData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save Articles
|
||||
// @Summary Create Articles
|
||||
// @Description API for create Articles
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ func ArticlesResponseMapper(
|
|||
ShareCount: articlesReq.ShareCount,
|
||||
ViewCount: articlesReq.ViewCount,
|
||||
CommentCount: articlesReq.CommentCount,
|
||||
OldId: articlesReq.OldId,
|
||||
StatusId: articlesReq.StatusId,
|
||||
IsBanner: articlesReq.IsBanner,
|
||||
IsPublish: articlesReq.IsPublish,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type ArticlesRepository interface {
|
|||
GetAllPublishSchedule() (articless []*entity.Articles, err error)
|
||||
FindOne(id uint) (articles *entity.Articles, err error)
|
||||
FindByFilename(thumbnailName string) (articleReturn *entity.Articles, err error)
|
||||
FindByOldId(oldId uint) (articles *entity.Articles, err error)
|
||||
Create(articles *entity.Articles) (articleReturn *entity.Articles, err error)
|
||||
Update(id uint, articles *entity.Articles) (err error)
|
||||
UpdateSkipNull(id uint, articles *entity.Articles) (err error)
|
||||
|
|
@ -125,7 +126,6 @@ func (_i *articlesRepository) FindOne(id uint) (articles *entity.Articles, err e
|
|||
}
|
||||
|
||||
func (_i *articlesRepository) FindByFilename(thumbnailName string) (articles *entity.Articles, err error) {
|
||||
|
||||
if err := _i.DB.DB.Where("thumbnail_name = ?", thumbnailName).First(&articles).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -133,6 +133,14 @@ func (_i *articlesRepository) FindByFilename(thumbnailName string) (articles *en
|
|||
return articles, nil
|
||||
}
|
||||
|
||||
func (_i *articlesRepository) FindByOldId(oldId uint) (articles *entity.Articles, err error) {
|
||||
if err := _i.DB.DB.Where("old_id = ?", oldId).First(&articles).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return articles, nil
|
||||
}
|
||||
|
||||
func (_i *articlesRepository) Create(articles *entity.Articles) (articleReturn *entity.Articles, err error) {
|
||||
result := _i.DB.DB.Create(articles)
|
||||
return articles, result.Error
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type ArticlesResponse struct {
|
|||
ViewCount *int `json:"viewCount"`
|
||||
CommentCount *int `json:"commentCount"`
|
||||
AiArticleId *int `json:"aiArticleId"`
|
||||
OldId *uint `json:"oldId"`
|
||||
StatusId *int `json:"statusId"`
|
||||
IsBanner *bool `json:"isBanner"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ type articlesService struct {
|
|||
type ArticlesService interface {
|
||||
All(req request.ArticlesQueryRequest) (articles []*response.ArticlesResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (articles *response.ArticlesResponse, err error)
|
||||
ShowByOldId(oldId uint) (articles *response.ArticlesResponse, err error)
|
||||
Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error)
|
||||
SaveThumbnail(c *fiber.Ctx) (err error)
|
||||
Update(id uint, req request.ArticlesUpdateRequest) (err error)
|
||||
|
|
@ -130,6 +131,17 @@ func (_i *articlesService) Show(id uint) (articles *response.ArticlesResponse, e
|
|||
return mapper.ArticlesResponseMapper(_i.Log, host, result, _i.ArticleCategoriesRepo, _i.ArticleCategoryDetailsRepo, _i.ArticleFilesRepo, _i.UsersRepo), nil
|
||||
}
|
||||
|
||||
func (_i *articlesService) ShowByOldId(oldId uint) (articles *response.ArticlesResponse, err error) {
|
||||
result, err := _i.Repo.FindByOldId(oldId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
host := _i.Cfg.App.Domain
|
||||
|
||||
return mapper.ArticlesResponseMapper(_i.Log, host, result, _i.ArticleCategoriesRepo, _i.ArticleCategoryDetailsRepo, _i.ArticleFilesRepo, _i.UsersRepo), nil
|
||||
}
|
||||
|
||||
func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
newReq := req.ToEntity()
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ func (_i *usersRepository) GetAll(req request.UsersQueryRequest) (userss []*user
|
|||
}
|
||||
|
||||
func (_i *usersRepository) FindOne(id uint) (users *users.Users, err error) {
|
||||
if err := _i.DB.DB.First(&users, id).Error; err != nil {
|
||||
if err := _i.DB.DB.Preload("UserLevel").First(&users, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ func (_i *usersRepository) FindByKeycloakId(keycloakId string) (users *users.Use
|
|||
}
|
||||
|
||||
func (_i *usersRepository) FindByUsername(username string) (users *users.Users, err error) {
|
||||
if err := _i.DB.DB.Where("username = ?", username).First(&users).Error; err != nil {
|
||||
if err := _i.DB.DB.Where("username = ?", username).Preload("UserLevel").First(&users).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -140,6 +140,8 @@ func (_i *usersRepository) Create(users *users.Users) (userReturn *users.Users,
|
|||
|
||||
func (_i *usersRepository) Update(id uint, userReturn *users.Users) (err error) {
|
||||
userReturnMap, err := StructToMap(userReturn)
|
||||
delete(userReturnMap, "user_levels")
|
||||
_i.Log.Info().Interface("Update", userReturnMap).Msg("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -459,7 +459,10 @@ func (_i *usersService) SetupEmail(req request.UserEmailValidationRequest) (msgR
|
|||
return nil, fmt.Errorf("username / password incorrect")
|
||||
}
|
||||
|
||||
_i.Log.Info().Interface("findUser", "").Msg("")
|
||||
findUser, err := _i.Repo.FindByUsername(*req.Username)
|
||||
|
||||
_i.Log.Info().Interface("findUser", findUser).Msg("")
|
||||
if findUser == nil || err != nil {
|
||||
return nil, fmt.Errorf("username / password incorrect")
|
||||
}
|
||||
|
|
@ -468,7 +471,9 @@ func (_i *usersService) SetupEmail(req request.UserEmailValidationRequest) (msgR
|
|||
if findUser.Email == *req.OldEmail {
|
||||
findUser.Email = *req.NewEmail
|
||||
findUser.IsEmailUpdated = &isTrue
|
||||
_i.Log.Info().Interface("Update", "").Msg("")
|
||||
err = _i.Repo.Update(findUser.ID, findUser)
|
||||
_i.Log.Info().Interface("Update", err).Msg("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ max = 20
|
|||
expiration_seconds = 60
|
||||
|
||||
[middleware.csrf]
|
||||
enable = true
|
||||
enable = false
|
||||
cookie-name = "csrf_"
|
||||
cookie-same-site = "None"
|
||||
cookie-same-site = "Lax"
|
||||
cookie-secure = false
|
||||
cookie-session-only = true
|
||||
cookie-http-only = true
|
||||
|
|
@ -77,6 +77,6 @@ admin-password = "P@ssw0rd.1"
|
|||
host = "smtp-app.polri.go.id"
|
||||
port = 465
|
||||
username = "webhumas.divhumas@polri.go.id"
|
||||
password = "z0VfYLbaghPc"
|
||||
password = "7ZXBaIyD0HdQ"
|
||||
from-address = "webhumas.divhumas@polri.go.id"
|
||||
from-name = "APLIKASI WEB HUMAS DIVHUMAS POLRI"
|
||||
|
|
@ -3588,6 +3588,55 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/articles/old-id/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "API for getting one Articles",
|
||||
"tags": [
|
||||
"Articles"
|
||||
],
|
||||
"summary": "Get one Articles",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Articles Old ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.Response"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.BadRequestError"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorized",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.UnauthorizedError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.InternalServerError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/articles/publish-scheduling": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
|
|
|||
|
|
@ -3577,6 +3577,55 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/articles/old-id/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "API for getting one Articles",
|
||||
"tags": [
|
||||
"Articles"
|
||||
],
|
||||
"summary": "Get one Articles",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Articles Old ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.Response"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.BadRequestError"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorized",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.UnauthorizedError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.InternalServerError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/articles/publish-scheduling": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
|
|
|||
|
|
@ -3327,6 +3327,37 @@ paths:
|
|||
summary: Update Banner Articles
|
||||
tags:
|
||||
- Articles
|
||||
/articles/old-id/{id}:
|
||||
get:
|
||||
description: API for getting one Articles
|
||||
parameters:
|
||||
- description: Articles Old ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/response.Response'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/response.BadRequestError'
|
||||
"401":
|
||||
description: Unauthorized
|
||||
schema:
|
||||
$ref: '#/definitions/response.UnauthorizedError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/response.InternalServerError'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Get one Articles
|
||||
tags:
|
||||
- Articles
|
||||
/articles/publish-scheduling:
|
||||
post:
|
||||
description: API for Publish Schedule of Article
|
||||
|
|
|
|||
Loading…
Reference in New Issue