Compare commits

...

10 Commits

Author SHA1 Message Date
Rama Priyanto e4a5612192 disable limiter 2026-02-10 11:11:00 +07:00
Rama Priyanto e205e5ab2e back knowledge base 2026-02-10 11:02:55 +07:00
Rama Priyanto e68b01a25a fix:knowledge base file 2026-02-09 15:44:31 +07:00
Rama Priyanto 760d72ac7e fix:edit agent 2026-02-09 13:59:24 +07:00
Rama Priyanto b71eb3435e fix:delete knowledge base 2026-02-09 07:25:27 +07:00
Rama Priyanto fb4fd0f4a8 feat:get agent by agent id, get agent for user 2026-02-09 05:28:49 +07:00
Rama Priyanto e72b014fd5 fix:mapping expert 2026-02-02 01:14:12 +07:00
Rama Priyanto c7f334bd00 feat:expert get user, agent api 2026-02-01 23:11:03 +07:00
Rama Priyanto 5bee8af44c fix:profile api get 2026-01-30 16:44:49 +07:00
Rama Priyanto e10e8b03fc fix:knowledge base notif 2026-01-26 06:58:36 +07:00
39 changed files with 2713 additions and 29 deletions

View File

@ -0,0 +1,21 @@
package entity
import (
userAgent "narasi-ahli-be/app/database/entity/user_agent"
"time"
)
type Agent struct {
ID uint `gorm:"primaryKey" json:"id"`
AgentID string `gorm:"type:varchar(100);uniqueIndex" json:"agent_id"`
Name string `gorm:"type:varchar(255)" json:"name"`
Description string `gorm:"type:text" json:"description"`
Instructions string `gorm:"type:text" json:"instructions"`
Type string `gorm:"type:varchar(100)" json:"type"`
Status bool `gorm:"default:true" json:"status"`
IsActive bool `gorm:"default:true" json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
UserAgents []*userAgent.UserAgent `gorm:"foreignKey:AgentID"`
}

View File

@ -0,0 +1,11 @@
package user_agent
import (
"time"
)
type UserAgent struct {
UserID uint `gorm:"primaryKey;column:user_id"`
AgentID uint `gorm:"primaryKey;column:agent_id"`
CreatedAt time.Time `gorm:"autoCreateTime"`
}

View File

@ -1,6 +1,7 @@
package users
import (
userAgent "narasi-ahli-be/app/database/entity/user_agent"
userLevels "narasi-ahli-be/app/database/entity/user_levels"
"time"
)
@ -35,4 +36,6 @@ type Users struct {
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
UserAgents []userAgent.UserAgent `gorm:"foreignKey:UserID"`
}

View File

@ -0,0 +1,49 @@
package agent
import (
"narasi-ahli-be/app/module/agent/controller"
"narasi-ahli-be/app/module/agent/repository"
"narasi-ahli-be/app/module/agent/service"
"github.com/gofiber/fiber/v2"
"go.uber.org/fx"
)
type AgentRouter struct {
App fiber.Router
Controller *controller.Controller
}
var NewAgentModule = fx.Options(
// register repository of Agent module
fx.Provide(repository.NewAgentRepository),
// register service of Agent module
fx.Provide(service.NewAgentService),
// register controller of Agent module
fx.Provide(controller.NewController),
// register router of Agent module
fx.Provide(NewAgentRouter),
)
func NewAgentRouter(fiber *fiber.App, controller *controller.Controller) *AgentRouter {
return &AgentRouter{
App: fiber,
Controller: controller,
}
}
func (_i *AgentRouter) RegisterAgentRoutes() {
agentController := _i.Controller.Agent
_i.App.Route("/agent", func(router fiber.Router) {
router.Get("/", agentController.All)
router.Get("/:id", agentController.Show)
router.Get("/agent_id/:agentId", agentController.FindByAgentId)
router.Put("/:id", agentController.Update)
router.Post("/", agentController.Save)
router.Delete("/:id", agentController.Delete)
})
}

View File

@ -0,0 +1,173 @@
package controller
import (
"narasi-ahli-be/app/module/agent/request"
"narasi-ahli-be/app/module/agent/service"
utilRes "narasi-ahli-be/utils/response"
utilVal "narasi-ahli-be/utils/validator"
"strconv"
"github.com/gofiber/fiber/v2"
)
type agentController struct {
agentService service.AgentService
}
type AgentController interface {
All(c *fiber.Ctx) error
Show(c *fiber.Ctx) error
Save(c *fiber.Ctx) error
Update(c *fiber.Ctx) error
Delete(c *fiber.Ctx) error
FindByAgentId(c *fiber.Ctx) error
}
func NewAgentController(agentService service.AgentService) AgentController {
return &agentController{agentService: agentService}
}
// All godoc
// @Summary Get list agent
// @Description Get list agent
// @Tags Agent
// @Accept json
// @Produce json
// @Param name query string false "Agent name"
// @Param type query string false "Agent type"
// @Param status query string false "Agent status"
// @Success 200 {object} utilRes.Response
// @Router /agent [get]
func (_i *agentController) All(c *fiber.Ctx) error {
statusStr := c.Query("status")
var status *bool
if statusStr != "" {
val, err := strconv.ParseBool(statusStr)
if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"message": "status must be true or false",
})
}
status = &val
}
req := request.AgentQueryRequest{
Name: c.Query("name"),
Type: c.Query("type"),
Status: status,
}
data, err := _i.agentService.All(req)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Data: data,
})
}
// Show godoc
// @Summary Get agent by ID
// @Tags Agent
// @Accept json
// @Produce json
// @Param id path int true "Agent ID"
// @Success 200 {object} utilRes.Response
// @Router /agent/{id} [get]
func (_i *agentController) Show(c *fiber.Ctx) error {
id, _ := strconv.ParseUint(c.Params("id"), 10, 64)
data, err := _i.agentService.Show(uint(id))
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{Success: true, Data: data})
}
// Save godoc
// @Summary Create agent
// @Tags Agent
// @Accept json
// @Produce json
// @Param body body request.AgentCreateRequest true "Agent payload"
// @Success 200 {object} utilRes.Response
// @Router /agent [post]
func (_i *agentController) Save(c *fiber.Ctx) error {
req := new(request.AgentCreateRequest)
if err := utilVal.ParseAndValidate(c, req); err != nil {
return err
}
data, err := _i.agentService.Save(*req)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{Success: true, Data: data})
}
// Update godoc
// @Summary Update agent
// @Tags Agent
// @Accept json
// @Produce json
// @Param id path int true "Agent ID"
// @Param body body request.AgentUpdateRequest true "Agent payload"
// @Success 200 {object} utilRes.Response
// @Router /agent/{id} [put]
func (_i *agentController) Update(c *fiber.Ctx) error {
id, _ := strconv.ParseUint(c.Params("id"), 10, 64)
req := new(request.AgentUpdateRequest)
if err := utilVal.ParseAndValidate(c, req); err != nil {
return err
}
if err := _i.agentService.Update(uint(id), *req); err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{Success: true})
}
// Delete godoc
// @Summary Delete agent
// @Tags Agent
// @Accept json
// @Produce json
// @Param id path int true "Agent ID"
// @Success 200 {object} utilRes.Response
// @Router /agent/{id} [delete]
func (_i *agentController) Delete(c *fiber.Ctx) error {
id, _ := strconv.ParseUint(c.Params("id"), 10, 64)
if err := _i.agentService.Delete(uint(id)); err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{Success: true})
}
// Show godoc
// @Summary Get agent by AgentID
// @Tags Agent
// @Accept json
// @Produce json
// @Param agentId path string true "Agent ID"
// @Success 200 {object} utilRes.Response
// @Router /agent/agent_id/{agentId} [get]
func (_i *agentController) FindByAgentId(c *fiber.Ctx) error {
id:= c.Params("agentId")
data, err := _i.agentService.FindByAgentId(id)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{Success: true, Data: data})
}

View File

@ -0,0 +1,13 @@
package controller
import "narasi-ahli-be/app/module/agent/service"
type Controller struct {
Agent AgentController
}
func NewController(agentService service.AgentService) *Controller {
return &Controller{
Agent: NewAgentController(agentService),
}
}

View File

@ -0,0 +1,25 @@
package mapper
import (
"narasi-ahli-be/app/database/entity"
"narasi-ahli-be/app/module/agent/response"
)
func AgentResponseMapper(agent *entity.Agent) *response.AgentResponse {
if agent == nil {
return nil
}
return &response.AgentResponse{
ID: agent.ID,
AgentID: agent.AgentID,
Name: agent.Name,
Description: agent.Description,
Instructions: agent.Instructions,
Type: agent.Type,
Status: agent.Status,
IsActive: agent.IsActive,
CreatedAt: agent.CreatedAt,
UpdatedAt: agent.UpdatedAt,
}
}

View File

@ -0,0 +1,83 @@
package repository
import (
"narasi-ahli-be/app/database"
"narasi-ahli-be/app/database/entity"
"narasi-ahli-be/app/module/agent/request"
)
type agentRepository struct {
DB *database.Database
}
type AgentRepository interface {
GetAll(req request.AgentQueryRequest) ([]*entity.Agent, error)
FindById(id uint) (*entity.Agent, error)
Create(agent *entity.Agent) (*entity.Agent, error)
Update(id uint, data map[string]interface{}) error
Delete(id uint) error
FindByAgentId(agentId string) (*entity.Agent, error)
}
func NewAgentRepository(db *database.Database) AgentRepository {
return &agentRepository{DB: db}
}
func (_i *agentRepository) GetAll(req request.AgentQueryRequest) (agents []*entity.Agent, err error) {
query := _i.DB.DB.Model(&entity.Agent{}).
Where("is_active = ?", true)
if req.Name != "" {
query = query.Where("name ILIKE ?", "%"+req.Name+"%")
}
if req.Type != "" {
query = query.Where("type ILIKE ?", "%"+req.Type+"%")
}
if req.Status != nil {
query = query.Where("status = ?", *req.Status)
}
err = query.Order("created_at DESC").Find(&agents).Error
return
}
func (_i *agentRepository) FindById(id uint) (*entity.Agent, error) {
var agent entity.Agent
err := _i.DB.DB.Where("id = ? AND is_active = ?", id, true).
First(&agent).Error
if err != nil {
return nil, err
}
return &agent, nil
}
func (_i *agentRepository) FindByAgentId(agentId string) (*entity.Agent, error) {
var agent entity.Agent
err := _i.DB.DB.Where("agent_id = ? ", agentId).
First(&agent).Error
if err != nil {
return nil, err
}
return &agent, nil
}
func (_i *agentRepository) Create(agent *entity.Agent) (*entity.Agent, error) {
if err := _i.DB.DB.Create(agent).Error; err != nil {
return nil, err
}
return agent, nil
}
func (_i *agentRepository) Update(id uint, data map[string]interface{}) error {
return _i.DB.DB.Model(&entity.Agent{}).
Where("id = ?", id).
Updates(data).Error
}
func (_i *agentRepository) Delete(id uint) error {
return _i.DB.DB.Model(&entity.Agent{}).
Where("id = ?", id).
Update("is_active", false).Error
}

View File

@ -0,0 +1,75 @@
package request
import "narasi-ahli-be/app/database/entity"
type AgentCreateRequest struct {
AgentID string `json:"agent_id" validate:"required"`
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Instructions string `json:"instructions"`
Type string `json:"type" validate:"required"`
Status *bool `json:"status"`
IsActive *bool `json:"is_active"`
}
func (r *AgentCreateRequest) ToEntity() *entity.Agent {
status := true
if r.Status != nil {
status = *r.Status
}
isActive := true
if r.IsActive != nil {
isActive = *r.IsActive
}
return &entity.Agent{
AgentID: r.AgentID,
Name: r.Name,
Description: r.Description,
Instructions: r.Instructions,
Type: r.Type,
Status: status,
IsActive: isActive,
}
}
type AgentUpdateRequest struct {
Name *string `json:"name"`
Description *string `json:"description"`
Instructions *string `json:"instructions"`
Type *string `json:"type"`
Status *bool `json:"status"`
IsActive *bool `json:"is_active"`
}
func (r *AgentUpdateRequest) ToMap() map[string]interface{} {
data := map[string]interface{}{}
if r.Name != nil {
data["name"] = *r.Name
}
if r.Description != nil {
data["description"] = *r.Description
}
if r.Instructions != nil {
data["instructions"] = *r.Instructions
}
if r.Type != nil {
data["type"] = *r.Type
}
if r.Status != nil {
data["status"] = *r.Status
}
if r.IsActive != nil {
data["is_active"] = *r.IsActive
}
return data
}
type AgentQueryRequest struct {
Name string `query:"name"`
Type string `query:"type"`
Status *bool `query:"status"`
}

View File

@ -0,0 +1,16 @@
package response
import "time"
type AgentResponse struct {
ID uint `json:"id"`
AgentID string `json:"agentId"`
Name string `json:"name"`
Description string `json:"description"`
Instructions string `json:"instructions"`
Type string `json:"type"`
Status bool `json:"status"`
IsActive bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}

View File

@ -0,0 +1,83 @@
package service
import (
"errors"
"narasi-ahli-be/app/module/agent/mapper"
"narasi-ahli-be/app/module/agent/repository"
"narasi-ahli-be/app/module/agent/request"
"narasi-ahli-be/app/module/agent/response"
"github.com/rs/zerolog"
)
type agentService struct {
Repo repository.AgentRepository
Log zerolog.Logger
}
type AgentService interface {
All(req request.AgentQueryRequest) ([]*response.AgentResponse, error)
Show(id uint) (*response.AgentResponse, error)
Save(req request.AgentCreateRequest) (*response.AgentResponse, error)
Update(id uint, req request.AgentUpdateRequest) error
Delete(id uint) error
FindByAgentId(id string) (*response.AgentResponse, error)
}
func NewAgentService(repo repository.AgentRepository, log zerolog.Logger) AgentService {
return &agentService{Repo: repo, Log: log}
}
func (_i *agentService) All(req request.AgentQueryRequest) (agents []*response.AgentResponse, err error) {
results, err := _i.Repo.GetAll(req)
if err != nil {
return
}
for _, result := range results {
agents = append(agents, mapper.AgentResponseMapper(result))
}
return
}
func (_i *agentService) Show(id uint) (*response.AgentResponse, error) {
result, err := _i.Repo.FindById(id)
if err != nil {
return nil, errors.New("agent not found")
}
return mapper.AgentResponseMapper(result), nil
}
func (_i *agentService) FindByAgentId(agentId string) (*response.AgentResponse, error) {
result, err := _i.Repo.FindByAgentId(agentId)
if err != nil {
return nil, errors.New("agent not found")
}
return mapper.AgentResponseMapper(result), nil
}
func (_i *agentService) Save(req request.AgentCreateRequest) (*response.AgentResponse, error) {
entity := req.ToEntity()
result, err := _i.Repo.Create(entity)
if err != nil {
return nil, err
}
return mapper.AgentResponseMapper(result), nil
}
func (_i *agentService) Update(id uint, req request.AgentUpdateRequest) error {
_, err := _i.Repo.FindById(id)
if err != nil {
return errors.New("agent not found")
}
return _i.Repo.Update(id, req.ToMap())
}
func (_i *agentService) Delete(id uint) error {
_, err := _i.Repo.FindById(id)
if err != nil {
return errors.New("agent not found")
}
return _i.Repo.Delete(id)
}

View File

@ -26,8 +26,9 @@ func NewEducationHistoryRepository(db *database.Database) EducationHistoryReposi
}
func (_i *educationHistoryRepository) GetAll(userId uint, req request.EducationHistoryQueryRequest) (educationHistories []*entity.EducationHistory, paging paginator.Pagination, err error) {
query := _i.DB.DB.Where("user_id = ?", userId)
query := _i.DB.DB.
Model(&entity.EducationHistory{}).
Where("user_id = ?", userId)
// Apply filters
if req.SchoolName != nil {
query = query.Where("school_name ILIKE ?", "%"+*req.SchoolName+"%")

View File

@ -6,7 +6,6 @@ import (
"narasi-ahli-be/app/database/entity"
"narasi-ahli-be/app/module/knowledge_base/request"
"narasi-ahli-be/utils/paginator"
utilSvc "narasi-ahli-be/utils/service"
"strings"
"time"
)
@ -107,16 +106,12 @@ func (r *KnowledgeBaseRepository) Create(data *entity.KnowledgeBase) (err error)
return r.DB.DB.Create(data).Error
}
func (r *KnowledgeBaseRepository) Update(id uint, data *entity.KnowledgeBase) (err error) {
updateMap, err := utilSvc.StructToMap(data)
if err != nil {
return err
}
func (r *KnowledgeBaseRepository) Update(id uint, data *entity.KnowledgeBase) error {
data.UpdatedAt = time.Now()
return r.DB.DB.Model(&entity.KnowledgeBase{}).
Where("id = ?", id).
Updates(updateMap).
Error
Updates(data).Error
}
func (r *KnowledgeBaseRepository) Delete(id uint) (err error) {

View File

@ -312,7 +312,7 @@ func (s *KnowledgeBaseService) Delete(id uint) error {
result.IsActive = false
result.UpdatedAt = time.Now()
return s.Repo.Update(id, result)
return s.Repo.Delete(id)
}
func (s *KnowledgeBaseService) UpdateStatus(id uint, status int) (data *response.KnowledgeBaseResponse, err error) {

View File

@ -47,9 +47,9 @@ func (_i *researchJournalsController) All(c *fiber.Ctx) error {
return err
}
authHeader := c.Get("Authorization")
reqContext := request.ResearchJournalsQueryRequestContext{
UserID: c.Query("userId"),
JournalTitle: c.Query("journalTitle"),
Publisher: c.Query("publisher"),
PublishedYear: c.Query("publishedYear"),
@ -64,7 +64,7 @@ func (_i *researchJournalsController) All(c *fiber.Ctx) error {
}
}
journalsData, paging, err := _i.researchJournalsService.All(authHeader, req)
journalsData, paging, err := _i.researchJournalsService.All(req)
if err != nil {
return err
}

View File

@ -26,8 +26,9 @@ func NewResearchJournalsRepository(db *database.Database) ResearchJournalsReposi
}
func (_i *researchJournalsRepository) GetAll(userId uint, req request.ResearchJournalsQueryRequest) (researchJournals []*entity.ResearchJournals, paging paginator.Pagination, err error) {
query := _i.DB.DB.Where("user_id = ?", userId)
query := _i.DB.DB.
Model(&entity.ResearchJournals{}).
Where("user_id = ?", userId)
// Apply filters
if req.JournalTitle != nil {
query = query.Where("journal_title ILIKE ?", "%"+*req.JournalTitle+"%")

View File

@ -3,10 +3,12 @@ package request
import (
"narasi-ahli-be/app/database/entity"
"narasi-ahli-be/utils/paginator"
"strconv"
"time"
)
type ResearchJournalsQueryRequest struct {
UserID uint `json:"userId" validate:"required"`
JournalTitle *string `json:"journalTitle"`
Publisher *string `json:"publisher"`
PublishedYear *int `json:"publishedYear"`
@ -46,6 +48,7 @@ func (req ResearchJournalsUpdateRequest) ToEntity() *entity.ResearchJournals {
}
type ResearchJournalsQueryRequestContext struct {
UserID string `json:"userId"`
JournalTitle string `json:"journalTitle"`
Publisher string `json:"publisher"`
PublishedYear string `json:"publishedYear"`
@ -54,6 +57,13 @@ type ResearchJournalsQueryRequestContext struct {
func (req ResearchJournalsQueryRequestContext) ToParamRequest() ResearchJournalsQueryRequest {
var request ResearchJournalsQueryRequest
if userId := req.UserID; userId != "" {
userIdUint, err := strconv.ParseUint(userId, 10, 0)
if err == nil {
request.UserID = uint(userIdUint)
}
}
if journalTitle := req.JournalTitle; journalTitle != "" {
request.JournalTitle = &journalTitle
}

View File

@ -2,6 +2,7 @@ package service
import (
"errors"
"log"
"narasi-ahli-be/app/module/research_journals/mapper"
"narasi-ahli-be/app/module/research_journals/repository"
"narasi-ahli-be/app/module/research_journals/request"
@ -20,7 +21,7 @@ type researchJournalsService struct {
}
type ResearchJournalsService interface {
All(authToken string, req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error)
All(req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error)
Show(authToken string, id uint) (researchJournal *response.ResearchJournalsResponse, err error)
Save(authToken string, req request.ResearchJournalsCreateRequest) (researchJournal *response.ResearchJournalsResponse, err error)
Update(authToken string, id uint, req request.ResearchJournalsUpdateRequest) (err error)
@ -35,19 +36,34 @@ func NewResearchJournalsService(repo repository.ResearchJournalsRepository, user
}
}
func (_i *researchJournalsService) All(authToken string, req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error) {
userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
if userInfo == nil {
return nil, paginator.Pagination{}, errors.New("unauthorized")
}
// func (_i *researchJournalsService) All(authToken string, req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error) {
// userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
// if userInfo == nil {
// return nil, paginator.Pagination{}, errors.New("unauthorized")
// }
results, paging, err := _i.Repo.GetAll(userInfo.ID, req)
// results, paging, err := _i.Repo.GetAll(userInfo.ID, req)
// if err != nil {
// return
// }
// for _, result := range results {
// researchJournals = append(researchJournals, mapper.ResearchJournalsResponseMapper(result))
// }
// return
// }
func (_i *researchJournalsService) All(req request.ResearchJournalsQueryRequest) (educationHistories []*response.ResearchJournalsResponse, paging paginator.Pagination, err error) {
log.Println("USER ID:", req.UserID)
results, paging, err := _i.Repo.GetAll(req.UserID, req)
if err != nil {
return
}
for _, result := range results {
researchJournals = append(researchJournals, mapper.ResearchJournalsResponseMapper(result))
educationHistories = append(educationHistories, mapper.ResearchJournalsResponseMapper(result))
}
return

View File

@ -0,0 +1,15 @@
package controller
import (
userAgentService "narasi-ahli-be/app/module/user_agent/service"
)
type Controller struct {
UserAgent UserAgentController
}
func NewController(service userAgentService.UserAgentService) *Controller {
return &Controller{
UserAgent: NewUserAgentController(service),
}
}

View File

@ -0,0 +1,120 @@
package controller
import (
"strconv"
"narasi-ahli-be/app/module/user_agent/request"
"narasi-ahli-be/app/module/user_agent/response"
"narasi-ahli-be/app/module/user_agent/service"
utilRes "narasi-ahli-be/utils/response"
"github.com/gofiber/fiber/v2"
)
type userAgentController struct {
userAgentService service.UserAgentService
}
type UserAgentController interface {
UpdateUserAgents(c *fiber.Ctx) error
GetAgentsByUser(c *fiber.Ctx) error
}
func NewUserAgentController(userAgentService service.UserAgentService) UserAgentController {
return &userAgentController{userAgentService: userAgentService}
}
type UpdateUserAgentRequest struct {
UserID uint `json:"userId"`
AgentIDs []uint `json:"agentIds"`
}
// UpdateUserAgents godoc
// @Summary Update agents assigned to user
// @Description Replace all agent mapping for a user
// @Tags User Agent
// @Accept json
// @Produce json
// @Param request body request.UpdateUserAgentRequest true "User Agent Mapping"
// @Success 200 {object} response.UpdateUserAgentResponse
// @Failure 400 {object} response.ErrorResponse
// @Failure 500 {object} response.ErrorResponse
// @Router /user-agent [put]
func (c *userAgentController) UpdateUserAgents(ctx *fiber.Ctx) error {
var req request.UpdateUserAgentRequest
if err := ctx.BodyParser(&req); err != nil {
return ctx.Status(fiber.StatusBadRequest).JSON(response.ErrorResponse{
Message: "invalid request",
})
}
err := c.userAgentService.UpdateUserAgents(req.UserID, req.AgentID)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).JSON(response.ErrorResponse{
Message: err.Error(),
})
}
return ctx.JSON(response.UpdateUserAgentResponse{
Message: "user agents updated",
})
}
// GetAgentsByUser godoc
// @Summary Get agents by user
// @Description Get all agent IDs assigned to a user
// @Tags User Agent
// @Produce json
// @Param user_id query int true "User ID"
// @Success 200 {object} response.GetUserAgentResponse
// @Failure 400 {object} response.ErrorResponse
// @Failure 500 {object} response.ErrorResponse
// @Router /user-agent [get]
func (c *userAgentController) GetAgentsByUser(ctx *fiber.Ctx) error {
userIDStr := ctx.Query("user_id")
userID, err := strconv.Atoi(userIDStr)
if err != nil || userID == 0 {
return ctx.Status(fiber.StatusBadRequest).JSON(response.ErrorResponse{
Message: "user_id required",
})
}
agents, err := c.userAgentService.GetAgentsByUser(uint(userID))
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).JSON(response.ErrorResponse{
Message: err.Error(),
})
}
var agentResponses []response.AgentDetail
for _, a := range agents {
agentResponses = append(agentResponses, response.AgentDetail{
ID: a.ID,
AgentID: a.AgentID,
Name: a.Name,
Description: a.Description,
Instructions: a.Instructions,
Type: a.Type,
Status: a.Status,
IsActive: a.IsActive,
CreatedAt: a.CreatedAt,
UpdatedAt: a.UpdatedAt,
})
}
// return ctx.JSON(response.GetUserAgentResponse{
// UserID: uint(userID),
// Agents: agentResponses,
// })
return utilRes.Resp(ctx, utilRes.Response{
Success: true,
Data: response.GetUserAgentResponse{
UserID: uint(userID),
Agents: agentResponses,
},
})
}

View File

@ -0,0 +1,77 @@
package repository
import (
"narasi-ahli-be/app/database"
"narasi-ahli-be/app/database/entity"
"narasi-ahli-be/app/database/entity/user_agent"
)
type UserAgentRepository interface {
ReplaceUserAgents(userID uint, agentIDs []uint) error
GetAgentsByUser(userID uint) ([]entity.Agent, error)
ValidateAgents(agentIDs []uint) ([]uint, error)
}
type userAgentRepository struct {
DB *database.Database
}
func NewUserAgentRepository(db *database.Database) UserAgentRepository {
return &userAgentRepository{DB: db}
}
func (r *userAgentRepository) ReplaceUserAgents(userID uint, agentIDs []uint) error {
tx := r.DB.DB.Begin()
if err := tx.Where("user_id = ?", userID).
Delete(&user_agent.UserAgent{}).Error; err != nil {
tx.Rollback()
return err
}
if len(agentIDs) == 0 {
return tx.Commit().Error
}
var mappings []user_agent.UserAgent
for _, aid := range agentIDs {
mappings = append(mappings, user_agent.UserAgent{
UserID: userID,
AgentID: aid,
})
}
if err := tx.Create(&mappings).Error; err != nil {
tx.Rollback()
return err
}
return tx.Commit().Error
}
func (r *userAgentRepository) GetAgentsByUser(userID uint) ([]entity.Agent, error) {
var agents []entity.Agent
err := r.DB.DB.
Table("user_agents ua").
Select("a.*").
Joins("JOIN agents a ON a.id = ua.agent_id").
Where("ua.user_id = ?", userID).
Scan(&agents).Error
return agents, err
}
func (r *userAgentRepository) ValidateAgents(agentIDs []uint) ([]uint, error) {
var validIDs []uint
err := r.DB.DB.
Table("agents").
Where("id IN ?", agentIDs).
Pluck("id", &validIDs).Error
return validIDs, err
}

View File

@ -0,0 +1,10 @@
package request
type UpdateUserAgentRequest struct {
UserID uint `json:"user_id" validate:"required"`
AgentID []uint `json:"agent_id"` // boleh kosong
}
type GetUserAgentRequest struct {
UserID uint `query:"user_id" validate:"required"`
}

View File

@ -0,0 +1,29 @@
package response
import "time"
type UpdateUserAgentResponse struct {
Message string `json:"message"`
}
type AgentDetail struct {
ID uint `json:"id"`
AgentID string `json:"agentId"`
Name string `json:"name"`
Description string `json:"description"`
Instructions string `json:"instructions"`
Type string `json:"type"`
Status bool `json:"status"`
IsActive bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type GetUserAgentResponse struct {
UserID uint `json:"userId"`
Agents []AgentDetail `json:"agentId"`
}
type ErrorResponse struct {
Message string `json:"message"`
}

View File

@ -0,0 +1,48 @@
package service
import (
"errors"
"narasi-ahli-be/app/database/entity"
"narasi-ahli-be/app/module/user_agent/repository"
"github.com/rs/zerolog"
)
type UserAgentService interface {
UpdateUserAgents(userID uint, agentIDs []uint) error
GetAgentsByUser(userID uint) ([]entity.Agent, error)
}
type userAgentService struct {
Repo repository.UserAgentRepository
Log zerolog.Logger
}
func NewUserAgentService(repo repository.UserAgentRepository, log zerolog.Logger) UserAgentService {
return &userAgentService{Repo: repo, Log: log}
}
func (s *userAgentService) UpdateUserAgents(userID uint, agentIDs []uint) error {
// kosong → valid (lepas semua agent)
if len(agentIDs) == 0 {
return s.Repo.ReplaceUserAgents(userID, agentIDs)
}
validIDs, err := s.Repo.ValidateAgents(agentIDs)
if err != nil {
return err
}
// cek apakah ada agent yang tidak exist
if len(validIDs) != len(agentIDs) {
return errors.New("one or more agent_id not found")
}
return s.Repo.ReplaceUserAgents(userID, agentIDs)
}
func (s *userAgentService) GetAgentsByUser(userID uint) ([]entity.Agent, error) {
return s.Repo.GetAgentsByUser(userID)
}

View File

@ -0,0 +1,50 @@
package user_agent
import (
"narasi-ahli-be/app/module/user_agent/controller"
"narasi-ahli-be/app/module/user_agent/repository"
"narasi-ahli-be/app/module/user_agent/service"
"github.com/gofiber/fiber/v2"
"go.uber.org/fx"
)
type UserAgentRouter struct {
App fiber.Router
Controller *controller.Controller
}
var NewUserAgentModule = fx.Options(
// repository
fx.Provide(repository.NewUserAgentRepository),
// service
fx.Provide(service.NewUserAgentService),
// controller
fx.Provide(controller.NewController),
// router
fx.Provide(NewUserAgentRouter),
)
func NewUserAgentRouter(app *fiber.App, controller *controller.Controller) *UserAgentRouter {
return &UserAgentRouter{
App: app,
Controller: controller,
}
}
func (r *UserAgentRouter) RegisterUserAgentRoutes() {
userAgentController := r.Controller.UserAgent
r.App.Route("/user-agent", func(router fiber.Router) {
// GET mapping agents by user
router.Get("/", userAgentController.GetAgentsByUser)
// UPDATE mapping (replace)
router.Put("/", userAgentController.UpdateUserAgents)
})
}

View File

@ -4,10 +4,15 @@ import "narasi-ahli-be/app/module/users/service"
type Controller struct {
Users UsersController
UserExpert UserExpertController
}
func NewController(UsersService service.UsersService) *Controller {
func NewController(UsersService service.UsersService, userExpert UserExpertController,
) *Controller {
return &Controller{
Users: NewUsersController(UsersService),
UserExpert: userExpert,
}
}

View File

@ -0,0 +1,92 @@
package controller
import (
"narasi-ahli-be/app/module/users/request"
"narasi-ahli-be/app/module/users/service"
utilRes "narasi-ahli-be/utils/response"
"strconv"
"github.com/gofiber/fiber/v2"
)
type userExpertController struct {
service service.UserExpertService
}
type UserExpertController interface {
All(c *fiber.Ctx) error
Show(c *fiber.Ctx) error
}
func NewUserExpertController(
service service.UserExpertService,
) UserExpertController {
return &userExpertController{
service: service,
}
}
// @Summary Get list expert users
// @Description Get users with role expert (user_role_id = 2)
// @Tags User Expert
// @Param name query string false "Filter by expert name"
// @Param type query string false "Filter by expert type"
// @Success 200 {object} response.Response
// @Failure 500 {object} response.InternalServerError
// @Router /users/experts [get]
func (_i *userExpertController) All(c *fiber.Ctx) error {
var namePtr *string
var typePtr *string
name := c.Query("name")
if name != "" {
namePtr = &name
}
t := c.Query("type")
if t != "" {
typePtr = &t
}
req := request.UserExpertQueryRequest{
Name: namePtr,
Type: typePtr,
}
data, err := _i.service.All(req)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Data: data,
})
}
// Show Expert User
// @Summary Get expert user detail
// @Description Get expert user with work, education, and research histories
// @Tags User Expert
// @Param id path int true "User ID"
// @Success 200 {object} response.Response
// @Failure 404 {object} response.BadRequestError
// @Failure 500 {object} response.InternalServerError
// @Router /users/experts/{id} [get]
func (_i *userExpertController) Show(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
if err != nil {
return err
}
data, err := _i.service.Show(uint(id))
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Data: data,
})
}

View File

@ -0,0 +1,73 @@
package repository
import (
"fmt"
"narasi-ahli-be/app/database"
"narasi-ahli-be/app/database/entity/users"
"narasi-ahli-be/app/module/users/request"
)
type UserExpertRepository interface {
GetExperts(req request.UserExpertQueryRequest) ([]*users.Users, error)
FindExpertByID(id uint) (*users.Users, error)
}
type userExpertRepository struct {
DB *database.Database
}
func NewUserExpertRepository(db *database.Database) UserExpertRepository {
return &userExpertRepository{DB: db}
}
func (r *userExpertRepository) GetExperts(
req request.UserExpertQueryRequest,
) ([]*users.Users, error) {
fmt.Println("=== GetExperts CALLED ===")
fmt.Printf("repo instance: %+v\n", r)
if r.DB == nil {
panic("🔥 r.DB IS NIL")
}
if r.DB.DB == nil {
panic("🔥 r.DB.DB IS NIL")
}
var res []*users.Users
query := r.DB.DB.
Debug(). // 🔥 TAMBAHKAN INI
Model(&users.Users{}).
Where(
"user_role_id = ? AND (is_active = true OR is_active IS NULL)",
3,
)
if req.Name != nil {
query = query.Where("fullname ILIKE ?", "%"+*req.Name+"%")
}
if req.Type != nil {
query = query.Where("type ILIKE ?", "%"+*req.Type+"%")
}
err := query.Find(&res).Error
return res, err
}
func (r *userExpertRepository) FindExpertByID(id uint) (*users.Users, error) {
var user users.Users
err := r.DB.DB.
Where(
"id = ? AND user_role_id = ? AND (is_active = true OR is_active IS NULL)",
id, 3,
).
First(&user).
Error
if err != nil {
return nil, err
}
return &user, nil
}

View File

@ -0,0 +1,6 @@
package request
type UserExpertQueryRequest struct {
Name *string `query:"name"`
Type *string `query:"type"`
}

View File

@ -1,6 +1,11 @@
package response
import "time"
import (
eduRes "narasi-ahli-be/app/module/education_history/response"
researchRes "narasi-ahli-be/app/module/research_journals/response"
workRes "narasi-ahli-be/app/module/work_history/response"
"time"
)
type UsersResponse struct {
ID uint `json:"id"`
@ -36,3 +41,18 @@ type ParetoLoginResponse struct {
type VisitorStatistic struct {
TotalVisitor string `json:"accessToken"`
}
type UserExpertResponse struct {
ID uint `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Fullname string `json:"fullname"`
Phone *string `json:"phoneNumber"`
LastJob *string `json:"lastJobTitle"`
IsActive *bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"`
WorkHistories []*workRes.WorkHistoryResponse `json:"workHistories"`
EducationHistories []*eduRes.EducationHistoryResponse `json:"educationHistories"`
ResearchJournals []*researchRes.ResearchJournalsResponse `json:"researchJournals"`
}

View File

@ -0,0 +1,185 @@
package service
import (
"errors"
"narasi-ahli-be/app/database/entity/users"
eduMapper "narasi-ahli-be/app/module/education_history/mapper"
eduRepo "narasi-ahli-be/app/module/education_history/repository"
eduReq "narasi-ahli-be/app/module/education_history/request"
researchMapper "narasi-ahli-be/app/module/research_journals/mapper"
researchRepo "narasi-ahli-be/app/module/research_journals/repository"
researchReq "narasi-ahli-be/app/module/research_journals/request"
userRepo "narasi-ahli-be/app/module/users/repository"
"narasi-ahli-be/app/module/users/request"
"narasi-ahli-be/app/module/users/response"
workMapper "narasi-ahli-be/app/module/work_history/mapper"
workRepo "narasi-ahli-be/app/module/work_history/repository"
workReq "narasi-ahli-be/app/module/work_history/request"
"narasi-ahli-be/utils/paginator"
"github.com/rs/zerolog"
)
type UserExpertService interface {
All(req request.UserExpertQueryRequest) ([]*response.UserExpertResponse, error)
Show(id uint) (*response.UserExpertResponse, error)
}
type userExpertService struct {
UserRepo userRepo.UserExpertRepository
WorkRepo workRepo.WorkHistoryRepository
EduRepo eduRepo.EducationHistoryRepository
ResearchRepo researchRepo.ResearchJournalsRepository
Log zerolog.Logger
}
func NewUserExpertService(
userRepo userRepo.UserExpertRepository,
workRepo workRepo.WorkHistoryRepository,
eduRepo eduRepo.EducationHistoryRepository,
researchRepo researchRepo.ResearchJournalsRepository,
log zerolog.Logger,
) UserExpertService {
return &userExpertService{
UserRepo: userRepo,
WorkRepo: workRepo,
EduRepo: eduRepo,
ResearchRepo: researchRepo,
Log: log,
}
}
func (s *userExpertService) All(
req request.UserExpertQueryRequest,
) ([]*response.UserExpertResponse, error) {
var users []*users.Users
var err error
if s.UserRepo == nil {
s.Log.Error().Msg("UserRepo IS NIL")
return nil, errors.New("internal server error")
}
// 🔥 pakai filter jika ada
users, err = s.UserRepo.GetExperts(req)
if err != nil {
return nil, err
}
var results []*response.UserExpertResponse
workReq := workReq.WorkHistoryQueryRequest{
Pagination: &paginator.Pagination{
Page: 1,
Limit: 100,
},
}
eduReq := eduReq.EducationHistoryQueryRequest{
Pagination: &paginator.Pagination{Page: 1,
Limit: 100, },
}
researchReq := researchReq.ResearchJournalsQueryRequest{
Pagination: &paginator.Pagination{Page: 1,
Limit: 100, },
}
for _, user := range users {
s.Log.Info().
Uint("user_id", user.ID).
Msg("Fetching relations for user")
works, _, _ := s.WorkRepo.GetAll(user.ID, workReq)
educations, _, _ := s.EduRepo.GetAll(user.ID, eduReq)
researches, _, _ := s.ResearchRepo.GetAll(user.ID, researchReq)
s.Log.Info().
Int("work_count", len(works)).
Int("edu_count", len(educations)).
Int("research_count", len(researches)).
Msg("Relation result count")
res := &response.UserExpertResponse{
ID: user.ID,
Username: user.Username,
Email: user.Email,
Fullname: user.Fullname,
Phone: user.PhoneNumber,
LastJob: user.LastJobTitle,
IsActive: user.IsActive,
CreatedAt: user.CreatedAt,
}
for _, w := range works {
res.WorkHistories = append(
res.WorkHistories,
workMapper.WorkHistoryResponseMapper(w),
)
}
for _, e := range educations {
res.EducationHistories = append(
res.EducationHistories,
eduMapper.EducationHistoryResponseMapper(e),
)
}
for _, r := range researches {
res.ResearchJournals = append(
res.ResearchJournals,
researchMapper.ResearchJournalsResponseMapper(r),
)
}
results = append(results, res)
}
return results, nil
}
func (s *userExpertService) Show(id uint) (*response.UserExpertResponse, error) {
user, err := s.UserRepo.FindExpertByID(id)
if err != nil {
return nil, errors.New("expert not found")
}
req := workReq.WorkHistoryQueryRequest{}
researchReq := researchReq.ResearchJournalsQueryRequest{}
eduReq := eduReq.EducationHistoryQueryRequest{}
works, _, _ := s.WorkRepo.GetAll(id,req)
educations, _, _ := s.EduRepo.GetAll(id, eduReq)
researches, _, _ := s.ResearchRepo.GetAll(id, researchReq)
res := &response.UserExpertResponse{
ID: user.ID,
Username: user.Username,
Email: user.Email,
Fullname: user.Fullname,
Phone: user.PhoneNumber,
LastJob: user.LastJobTitle,
IsActive: user.IsActive,
CreatedAt: user.CreatedAt,
}
for _, w := range works {
res.WorkHistories = append(res.WorkHistories, workMapper.WorkHistoryResponseMapper(w))
}
for _, e := range educations {
res.EducationHistories = append(res.EducationHistories, eduMapper.EducationHistoryResponseMapper(e))
}
for _, r := range researches {
res.ResearchJournals = append(res.ResearchJournals, researchMapper.ResearchJournalsResponseMapper(r))
}
return res, nil
}

View File

@ -28,6 +28,10 @@ var NewUsersModule = fx.Options(
// register router of Users module
fx.Provide(NewUsersRouter),
fx.Provide(repository.NewUserExpertRepository),
fx.Provide(service.NewUserExpertService),
fx.Provide(controller.NewUserExpertController),
)
// init UsersRouter
@ -41,6 +45,8 @@ func NewUsersRouter(fiber *fiber.App, controller *controller.Controller) *UsersR
// register routes of Users module
func (_i *UsersRouter) RegisterUsersRoutes() {
// define controllers
_i.RegisterUserExpertRoutes()
usersController := _i.Controller.Users
// define routes
@ -62,4 +68,15 @@ func (_i *UsersRouter) RegisterUsersRoutes() {
router.Post("/email-validation", usersController.EmailValidation)
router.Post("/setup-email", usersController.SetupEmail)
})
}
func (_i *UsersRouter) RegisterUserExpertRoutes() {
expertController := _i.Controller.UserExpert
_i.App.Route("/users/experts", func(router fiber.Router) {
router.Get("/", expertController.All)
router.Get("/:id", expertController.Show)
})
}

View File

@ -26,8 +26,10 @@ func NewWorkHistoryRepository(db *database.Database) WorkHistoryRepository {
}
func (_i *workHistoryRepository) GetAll(userId uint, req request.WorkHistoryQueryRequest) (workHistories []*entity.WorkHistory, paging paginator.Pagination, err error) {
query := _i.DB.DB.Where("user_id = ?", userId)
query := _i.DB.DB.
Model(&entity.WorkHistory{}).
Where("user_id = ?", userId)
// Apply filters
if req.JobTitle != nil {
query = query.Where("job_title ILIKE ?", "%"+*req.JobTitle+"%")

View File

@ -3,6 +3,7 @@ package router
import (
"narasi-ahli-be/app/module/activity_logs"
"narasi-ahli-be/app/module/advertisement"
"narasi-ahli-be/app/module/agent"
"narasi-ahli-be/app/module/ai_chat"
"narasi-ahli-be/app/module/ai_chat_files"
"narasi-ahli-be/app/module/article_approvals"
@ -27,6 +28,7 @@ import (
"narasi-ahli-be/app/module/provinces"
"narasi-ahli-be/app/module/research_journals"
"narasi-ahli-be/app/module/subscription"
"narasi-ahli-be/app/module/user_agent"
"narasi-ahli-be/app/module/user_levels"
"narasi-ahli-be/app/module/user_role_accesses"
"narasi-ahli-be/app/module/user_roles"
@ -74,6 +76,8 @@ type Router struct {
ResearchJournalsRouter *research_journals.ResearchJournalsRouter
AIChatFilesRouter *ai_chat_files.AiChatFilesRouter
NotificationRouter *notifications.NotificationRouter
AgentRouter *agent.AgentRouter
UserAgentRouter *user_agent.UserAgentRouter
}
@ -112,6 +116,9 @@ func NewRouter(
researchJournalsRouter *research_journals.ResearchJournalsRouter,
aiChatFilesRouter *ai_chat_files.AiChatFilesRouter,
notificationRouter *notifications.NotificationRouter,
agentRouter *agent.AgentRouter,
userAgentRouter *user_agent.UserAgentRouter,
) *Router {
return &Router{
@ -148,6 +155,9 @@ func NewRouter(
ResearchJournalsRouter: researchJournalsRouter,
AIChatFilesRouter: aiChatFilesRouter,
NotificationRouter: notificationRouter,
AgentRouter: agentRouter,
UserAgentRouter: userAgentRouter,
}
}
@ -194,6 +204,8 @@ func (r *Router) Register() {
r.ResearchJournalsRouter.RegisterResearchJournalsRoutes()
r.AIChatFilesRouter.RegisterAiChatFilesRoutes()
r.NotificationRouter.RegisterNotificationRoutes()
r.AgentRouter.RegisterAgentRoutes()
r.UserAgentRouter.RegisterUserAgentRoutes()
}

View File

@ -49,7 +49,7 @@ enable = true
enable = true
[middleware.limiter]
enable = true
enable = false
max = 20
expiration_seconds = 60

View File

@ -914,6 +914,209 @@ const docTemplate = `{
}
}
},
"/agent": {
"get": {
"description": "Get list agent",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Get list agent",
"parameters": [
{
"type": "string",
"description": "Agent name",
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Agent type",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "Agent status",
"name": "status",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
},
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Create agent",
"parameters": [
{
"description": "Agent payload",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AgentCreateRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/agent/agent_id/{agentId}": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Get agent by AgentID",
"parameters": [
{
"type": "string",
"description": "Agent ID",
"name": "agentId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/agent/{id}": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Get agent by ID",
"parameters": [
{
"type": "integer",
"description": "Agent ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
},
"put": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Update agent",
"parameters": [
{
"type": "integer",
"description": "Agent ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Agent payload",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AgentUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
},
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Delete agent",
"parameters": [
{
"type": "integer",
"description": "Agent ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/ai-chat-files": {
"get": {
"security": [
@ -12881,6 +13084,12 @@ const docTemplate = `{
"name": "publisher",
"in": "query"
},
{
"type": "integer",
"name": "userId",
"in": "query",
"required": true
},
{
"type": "integer",
"name": "count",
@ -13488,6 +13697,91 @@ const docTemplate = `{
}
}
},
"/user-agent": {
"get": {
"description": "Get all agent IDs assigned to a user",
"produces": [
"application/json"
],
"tags": [
"User Agent"
],
"summary": "Get agents by user",
"parameters": [
{
"type": "integer",
"description": "User ID",
"name": "user_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.GetUserAgentResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"put": {
"description": "Replace all agent mapping for a user",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"User Agent"
],
"summary": "Update agents assigned to user",
"parameters": [
{
"description": "User Agent Mapping",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.UpdateUserAgentRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.UpdateUserAgentResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/user-levels": {
"get": {
"security": [
@ -15132,6 +15426,81 @@ const docTemplate = `{
}
}
},
"/users/experts": {
"get": {
"description": "Get users with role expert (user_role_id = 2)",
"tags": [
"User Expert"
],
"summary": "Get list expert users",
"parameters": [
{
"type": "string",
"description": "Filter by expert name",
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Filter by expert type",
"name": "type",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.InternalServerError"
}
}
}
}
},
"/users/experts/{id}": {
"get": {
"description": "Get expert user with work, education, and research histories",
"tags": [
"User Expert"
],
"summary": "Get expert user detail",
"parameters": [
{
"type": "integer",
"description": "User ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.BadRequestError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.InternalServerError"
}
}
}
}
},
"/users/forgot-password": {
"post": {
"security": [
@ -16346,6 +16715,60 @@ const docTemplate = `{
}
}
},
"request.AgentCreateRequest": {
"type": "object",
"required": [
"agent_id",
"name",
"type"
],
"properties": {
"agent_id": {
"type": "string"
},
"description": {
"type": "string"
},
"instructions": {
"type": "string"
},
"is_active": {
"type": "boolean"
},
"name": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "string"
}
}
},
"request.AgentUpdateRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"instructions": {
"type": "string"
},
"is_active": {
"type": "boolean"
},
"name": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "string"
}
}
},
"request.AiChatFilesUpdateRequest": {
"type": "object",
"required": [
@ -17614,6 +18037,24 @@ const docTemplate = `{
}
}
},
"request.UpdateUserAgentRequest": {
"type": "object",
"required": [
"user_id"
],
"properties": {
"agent_id": {
"description": "boleh kosong",
"type": "array",
"items": {
"type": "integer"
}
},
"user_id": {
"type": "integer"
}
}
},
"request.UserEmailValidationRequest": {
"type": "object",
"properties": {
@ -18129,6 +18570,41 @@ const docTemplate = `{
}
}
},
"response.AgentDetail": {
"type": "object",
"properties": {
"agentId": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"instructions": {
"type": "string"
},
"isActive": {
"type": "boolean"
},
"name": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"response.BadRequestError": {
"type": "object",
"properties": {
@ -18146,6 +18622,28 @@ const docTemplate = `{
}
}
},
"response.ErrorResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
},
"response.GetUserAgentResponse": {
"type": "object",
"properties": {
"agentId": {
"type": "array",
"items": {
"$ref": "#/definitions/response.AgentDetail"
}
},
"userId": {
"type": "integer"
}
}
},
"response.InternalServerError": {
"type": "object",
"properties": {
@ -18198,6 +18696,14 @@ const docTemplate = `{
"example": false
}
}
},
"response.UpdateUserAgentResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}`

View File

@ -903,6 +903,209 @@
}
}
},
"/agent": {
"get": {
"description": "Get list agent",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Get list agent",
"parameters": [
{
"type": "string",
"description": "Agent name",
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Agent type",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "Agent status",
"name": "status",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
},
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Create agent",
"parameters": [
{
"description": "Agent payload",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AgentCreateRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/agent/agent_id/{agentId}": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Get agent by AgentID",
"parameters": [
{
"type": "string",
"description": "Agent ID",
"name": "agentId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/agent/{id}": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Get agent by ID",
"parameters": [
{
"type": "integer",
"description": "Agent ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
},
"put": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Update agent",
"parameters": [
{
"type": "integer",
"description": "Agent ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Agent payload",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.AgentUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
},
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Agent"
],
"summary": "Delete agent",
"parameters": [
{
"type": "integer",
"description": "Agent ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/ai-chat-files": {
"get": {
"security": [
@ -12870,6 +13073,12 @@
"name": "publisher",
"in": "query"
},
{
"type": "integer",
"name": "userId",
"in": "query",
"required": true
},
{
"type": "integer",
"name": "count",
@ -13477,6 +13686,91 @@
}
}
},
"/user-agent": {
"get": {
"description": "Get all agent IDs assigned to a user",
"produces": [
"application/json"
],
"tags": [
"User Agent"
],
"summary": "Get agents by user",
"parameters": [
{
"type": "integer",
"description": "User ID",
"name": "user_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.GetUserAgentResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"put": {
"description": "Replace all agent mapping for a user",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"User Agent"
],
"summary": "Update agents assigned to user",
"parameters": [
{
"description": "User Agent Mapping",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.UpdateUserAgentRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.UpdateUserAgentResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/user-levels": {
"get": {
"security": [
@ -15121,6 +15415,81 @@
}
}
},
"/users/experts": {
"get": {
"description": "Get users with role expert (user_role_id = 2)",
"tags": [
"User Expert"
],
"summary": "Get list expert users",
"parameters": [
{
"type": "string",
"description": "Filter by expert name",
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Filter by expert type",
"name": "type",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.InternalServerError"
}
}
}
}
},
"/users/experts/{id}": {
"get": {
"description": "Get expert user with work, education, and research histories",
"tags": [
"User Expert"
],
"summary": "Get expert user detail",
"parameters": [
{
"type": "integer",
"description": "User ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.BadRequestError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.InternalServerError"
}
}
}
}
},
"/users/forgot-password": {
"post": {
"security": [
@ -16335,6 +16704,60 @@
}
}
},
"request.AgentCreateRequest": {
"type": "object",
"required": [
"agent_id",
"name",
"type"
],
"properties": {
"agent_id": {
"type": "string"
},
"description": {
"type": "string"
},
"instructions": {
"type": "string"
},
"is_active": {
"type": "boolean"
},
"name": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "string"
}
}
},
"request.AgentUpdateRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"instructions": {
"type": "string"
},
"is_active": {
"type": "boolean"
},
"name": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "string"
}
}
},
"request.AiChatFilesUpdateRequest": {
"type": "object",
"required": [
@ -17603,6 +18026,24 @@
}
}
},
"request.UpdateUserAgentRequest": {
"type": "object",
"required": [
"user_id"
],
"properties": {
"agent_id": {
"description": "boleh kosong",
"type": "array",
"items": {
"type": "integer"
}
},
"user_id": {
"type": "integer"
}
}
},
"request.UserEmailValidationRequest": {
"type": "object",
"properties": {
@ -18118,6 +18559,41 @@
}
}
},
"response.AgentDetail": {
"type": "object",
"properties": {
"agentId": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"instructions": {
"type": "string"
},
"isActive": {
"type": "boolean"
},
"name": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"response.BadRequestError": {
"type": "object",
"properties": {
@ -18135,6 +18611,28 @@
}
}
},
"response.ErrorResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
},
"response.GetUserAgentResponse": {
"type": "object",
"properties": {
"agentId": {
"type": "array",
"items": {
"$ref": "#/definitions/response.AgentDetail"
}
},
"userId": {
"type": "integer"
}
}
},
"response.InternalServerError": {
"type": "object",
"properties": {
@ -18187,6 +18685,14 @@
"example": false
}
}
},
"response.UpdateUserAgentResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}

View File

@ -148,6 +148,42 @@ definitions:
- redirectLink
- title
type: object
request.AgentCreateRequest:
properties:
agent_id:
type: string
description:
type: string
instructions:
type: string
is_active:
type: boolean
name:
type: string
status:
type: boolean
type:
type: string
required:
- agent_id
- name
- type
type: object
request.AgentUpdateRequest:
properties:
description:
type: string
instructions:
type: string
is_active:
type: boolean
name:
type: string
status:
type: boolean
type:
type: string
type: object
request.AiChatFilesUpdateRequest:
properties:
fileAlt:
@ -1035,6 +1071,18 @@ definitions:
- email
- id
type: object
request.UpdateUserAgentRequest:
properties:
agent_id:
description: boleh kosong
items:
type: integer
type: array
user_id:
type: integer
required:
- user_id
type: object
request.UserEmailValidationRequest:
properties:
newEmail:
@ -1389,6 +1437,29 @@ definitions:
- jobTitle
- startDate
type: object
response.AgentDetail:
properties:
agentId:
type: string
createdAt:
type: string
description:
type: string
id:
type: integer
instructions:
type: string
isActive:
type: boolean
name:
type: string
status:
type: boolean
type:
type: string
updatedAt:
type: string
type: object
response.BadRequestError:
properties:
code:
@ -1401,6 +1472,20 @@ definitions:
example: false
type: boolean
type: object
response.ErrorResponse:
properties:
message:
type: string
type: object
response.GetUserAgentResponse:
properties:
agentId:
items:
$ref: '#/definitions/response.AgentDetail'
type: array
userId:
type: integer
type: object
response.InternalServerError:
properties:
code:
@ -1439,6 +1524,11 @@ definitions:
example: false
type: boolean
type: object
response.UpdateUserAgentResponse:
properties:
message:
type: string
type: object
info:
contact: {}
paths:
@ -2014,6 +2104,138 @@ paths:
summary: Viewer Advertisement
tags:
- Advertisement
/agent:
get:
consumes:
- application/json
description: Get list agent
parameters:
- description: Agent name
in: query
name: name
type: string
- description: Agent type
in: query
name: type
type: string
- description: Agent status
in: query
name: status
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: Get list agent
tags:
- Agent
post:
consumes:
- application/json
parameters:
- description: Agent payload
in: body
name: body
required: true
schema:
$ref: '#/definitions/request.AgentCreateRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: Create agent
tags:
- Agent
/agent/{id}:
delete:
consumes:
- application/json
parameters:
- description: Agent ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: Delete agent
tags:
- Agent
get:
consumes:
- application/json
parameters:
- description: Agent ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: Get agent by ID
tags:
- Agent
put:
consumes:
- application/json
parameters:
- description: Agent ID
in: path
name: id
required: true
type: integer
- description: Agent payload
in: body
name: body
required: true
schema:
$ref: '#/definitions/request.AgentUpdateRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: Update agent
tags:
- Agent
/agent/agent_id/{agentId}:
get:
consumes:
- application/json
parameters:
- description: Agent ID
in: path
name: agentId
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
summary: Get agent by AgentID
tags:
- Agent
/ai-chat-files:
get:
description: API for getting all AiChatFiles
@ -9656,6 +9878,10 @@ paths:
- in: query
name: publisher
type: string
- in: query
name: userId
required: true
type: integer
- in: query
name: count
type: integer
@ -10046,6 +10272,62 @@ paths:
summary: update Subscription
tags:
- Subscription
/user-agent:
get:
description: Get all agent IDs assigned to a user
parameters:
- description: User ID
in: query
name: user_id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.GetUserAgentResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: Get agents by user
tags:
- User Agent
put:
consumes:
- application/json
description: Replace all agent mapping for a user
parameters:
- description: User Agent Mapping
in: body
name: request
required: true
schema:
$ref: '#/definitions/request.UpdateUserAgentRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.UpdateUserAgentResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: Update agents assigned to user
tags:
- User Agent
/user-levels:
get:
description: API for getting all UserLevels
@ -11172,6 +11454,55 @@ paths:
summary: EmailValidation Users
tags:
- Users
/users/experts:
get:
description: Get users with role expert (user_role_id = 2)
parameters:
- description: Filter by expert name
in: query
name: name
type: string
- description: Filter by expert type
in: query
name: type
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.InternalServerError'
summary: Get list expert users
tags:
- User Expert
/users/experts/{id}:
get:
description: Get expert user with work, education, and research histories
parameters:
- description: User ID
in: path
name: id
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
"404":
description: Not Found
schema:
$ref: '#/definitions/response.BadRequestError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.InternalServerError'
summary: Get expert user detail
tags:
- User Expert
/users/forgot-password:
post:
description: API for ForgotPassword Users

View File

@ -5,6 +5,7 @@ import (
"narasi-ahli-be/app/middleware"
"narasi-ahli-be/app/module/activity_logs"
"narasi-ahli-be/app/module/advertisement"
"narasi-ahli-be/app/module/agent"
"narasi-ahli-be/app/module/ai_chat"
"narasi-ahli-be/app/module/ai_chat_files"
"narasi-ahli-be/app/module/article_approvals"
@ -29,6 +30,7 @@ import (
"narasi-ahli-be/app/module/provinces"
"narasi-ahli-be/app/module/research_journals"
"narasi-ahli-be/app/module/subscription"
"narasi-ahli-be/app/module/user_agent"
"narasi-ahli-be/app/module/user_levels"
"narasi-ahli-be/app/module/user_role_accesses"
"narasi-ahli-be/app/module/user_role_level_details"
@ -101,6 +103,9 @@ func main() {
research_journals.NewResearchJournalsModule,
ai_chat_files.NewAiChatFilesModule,
notifications.NewNotificationsModule,
agent.NewAgentModule,
user_agent.NewUserAgentModule,
// start aplication