diff --git a/app/module/agent/controller/agent.controller.go b/app/module/agent/controller/agent.controller.go index 7d77b5e..4cc4fb3 100644 --- a/app/module/agent/controller/agent.controller.go +++ b/app/module/agent/controller/agent.controller.go @@ -34,12 +34,27 @@ func NewAgentController(agentService service.AgentService) AgentController { // @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) diff --git a/app/module/agent/repository/agent.repository.go b/app/module/agent/repository/agent.repository.go index 750fe0e..a63144c 100644 --- a/app/module/agent/repository/agent.repository.go +++ b/app/module/agent/repository/agent.repository.go @@ -30,7 +30,7 @@ func (_i *agentRepository) GetAll(req request.AgentQueryRequest) (agents []*enti query = query.Where("name ILIKE ?", "%"+req.Name+"%") } if req.Type != "" { - query = query.Where("type = ?", req.Type) + query = query.Where("type ILIKE ?", "%"+req.Type+"%") } if req.Status != nil { query = query.Where("status = ?", *req.Status) diff --git a/app/module/users/repository/user-expert.repository.go b/app/module/users/repository/user-expert.repository.go index ef598fa..1a68f12 100644 --- a/app/module/users/repository/user-expert.repository.go +++ b/app/module/users/repository/user-expert.repository.go @@ -49,7 +49,7 @@ func (r *userExpertRepository) GetExperts( } if req.Type != nil { - query = query.Where("work_type = ?", *req.Type) + query = query.Where("type ILIKE ?", "%"+*req.Type+"%") } err := query.Find(&res).Error diff --git a/app/module/users/service/user-expert.service.go b/app/module/users/service/user-expert.service.go index 669be53..5541c9b 100644 --- a/app/module/users/service/user-expert.service.go +++ b/app/module/users/service/user-expert.service.go @@ -77,23 +77,37 @@ if s.UserRepo == nil { var results []*response.UserExpertResponse workReq := workReq.WorkHistoryQueryRequest{ - Pagination: &paginator.Pagination{}, + Pagination: &paginator.Pagination{ + Page: 1, + Limit: 100, + }, } eduReq := eduReq.EducationHistoryQueryRequest{ - Pagination: &paginator.Pagination{}, + Pagination: &paginator.Pagination{Page: 1, + Limit: 100, }, } researchReq := researchReq.ResearchJournalsQueryRequest{ - Pagination: &paginator.Pagination{}, + 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, diff --git a/docs/swagger/docs.go b/docs/swagger/docs.go index d0b62dc..9eb147a 100644 --- a/docs/swagger/docs.go +++ b/docs/swagger/docs.go @@ -939,6 +939,12 @@ const docTemplate = `{ "description": "Agent type", "name": "type", "in": "query" + }, + { + "type": "string", + "description": "Agent status", + "name": "status", + "in": "query" } ], "responses": { diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index 57aafae..25fc965 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -928,6 +928,12 @@ "description": "Agent type", "name": "type", "in": "query" + }, + { + "type": "string", + "description": "Agent status", + "name": "status", + "in": "query" } ], "responses": { diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index 5ab2db7..d9f86f5 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -2064,6 +2064,10 @@ paths: in: query name: type type: string + - description: Agent status + in: query + name: status + type: string produces: - application/json responses: