feat:get agent by agent id, get agent for user

This commit is contained in:
Rama Priyanto 2026-02-09 05:28:49 +07:00
parent e72b014fd5
commit fb4fd0f4a8
19 changed files with 953 additions and 2 deletions

View File

@ -1,6 +1,9 @@
package entity
import "time"
import (
userAgent "narasi-ahli-be/app/database/entity/user_agent"
"time"
)
type Agent struct {
ID uint `gorm:"primaryKey" json:"id"`
@ -13,4 +16,6 @@ type Agent struct {
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

@ -41,6 +41,8 @@ func (_i *AgentRouter) RegisterAgentRoutes() {
_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.Post("/", agentController.Save)
router.Delete("/:id", agentController.Delete)
})

View File

@ -20,6 +20,8 @@ type AgentController interface {
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 {
@ -151,3 +153,21 @@ func (_i *agentController) Delete(c *fiber.Ctx) error {
}
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

@ -16,6 +16,9 @@ type AgentRepository interface {
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 {
@ -50,6 +53,16 @@ func (_i *agentRepository) FindById(id uint) (*entity.Agent, error) {
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

View File

@ -21,6 +21,8 @@ type AgentService interface {
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 {
@ -47,6 +49,14 @@ func (_i *agentService) Show(id uint) (*response.AgentResponse, error) {
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)

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

@ -28,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"
@ -75,7 +76,9 @@ type Router struct {
ResearchJournalsRouter *research_journals.ResearchJournalsRouter
AIChatFilesRouter *ai_chat_files.AiChatFilesRouter
NotificationRouter *notifications.NotificationRouter
AgentRouter *agent.AgentRouter
AgentRouter *agent.AgentRouter
UserAgentRouter *user_agent.UserAgentRouter
}
func NewRouter(
@ -114,6 +117,8 @@ func NewRouter(
aiChatFilesRouter *ai_chat_files.AiChatFilesRouter,
notificationRouter *notifications.NotificationRouter,
agentRouter *agent.AgentRouter,
userAgentRouter *user_agent.UserAgentRouter,
) *Router {
return &Router{
@ -151,6 +156,8 @@ func NewRouter(
AIChatFilesRouter: aiChatFilesRouter,
NotificationRouter: notificationRouter,
AgentRouter: agentRouter,
UserAgentRouter: userAgentRouter,
}
}
@ -198,6 +205,7 @@ func (r *Router) Register() {
r.AIChatFilesRouter.RegisterAiChatFilesRoutes()
r.NotificationRouter.RegisterNotificationRoutes()
r.AgentRouter.RegisterAgentRoutes()
r.UserAgentRouter.RegisterUserAgentRoutes()
}

View File

@ -988,6 +988,37 @@ const docTemplate = `{
}
}
},
"/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": [
@ -13666,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": [
@ -17921,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": {
@ -18436,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": {
@ -18453,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": {
@ -18505,6 +18696,14 @@ const docTemplate = `{
"example": false
}
}
},
"response.UpdateUserAgentResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}`

View File

@ -977,6 +977,37 @@
}
}
},
"/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": [
@ -13655,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": [
@ -17910,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": {
@ -18425,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": {
@ -18442,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": {
@ -18494,6 +18685,14 @@
"example": false
}
}
},
"response.UpdateUserAgentResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}

View File

@ -1071,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:
@ -1425,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:
@ -1437,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:
@ -1475,6 +1524,11 @@ definitions:
example: false
type: boolean
type: object
response.UpdateUserAgentResponse:
properties:
message:
type: string
type: object
info:
contact: {}
paths:
@ -2162,6 +2216,26 @@ paths:
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
@ -10198,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

View File

@ -30,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"
@ -103,6 +104,7 @@ func main() {
ai_chat_files.NewAiChatFilesModule,
notifications.NewNotificationsModule,
agent.NewAgentModule,
user_agent.NewUserAgentModule,