Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/controller/employee/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ func (r *controller) List(workingStatuses []string, body GetListEmployeeInput, u

return employees, total, nil
}

func (r *controller) ListWithLocation() ([]*model.Employee, error) {
employees, err := r.store.Employee.SimpleList(r.repo.DB())
if err != nil {
return nil, err
}

return employees, nil
}
1 change: 1 addition & 0 deletions pkg/controller/employee/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ type IController interface {
UpdateRole(userID string, input UpdateRoleInput) (err error)
GetLineManagers(userInfo *model.CurrentLoggedUserInfo) (employees []*model.Employee, err error)
UpdateBaseSalary(l logger.Logger, employeeID string, body UpdateBaseSalaryInput) (employee *model.BaseSalary, err error)
ListWithLocation() (employees []*model.Employee, err error)
}
29 changes: 29 additions & 0 deletions pkg/handler/employee/employee.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,3 +754,32 @@ func (h *handler) UpdateBaseSalary(c *gin.Context) {

c.JSON(http.StatusOK, view.CreateResponse[any](view.ToBaseSalary(emp), nil, nil, nil, ""))
}

// ListWithLocation godoc
// @Summary Get employees list with location
// @Description Get employees list with location
// @Tags Employee
// @Accept json
// @Produce json
// @Param Authorization header string true "jwt token"
// @Param Body body request.UpdateBaseSalaryInput true "Body"
// @Success 200 {object} view.UpdateBaseSalaryResponse
// @Failure 400 {object} view.ErrorResponse
// @Failure 404 {object} view.ErrorResponse
// @Failure 500 {object} view.ErrorResponse
// @Router /public/employees [get]
func (h *handler) ListWithLocation(c *gin.Context) {
l := h.logger.Fields(logger.Fields{
"handler": "employee",
"method": "ListWithLocation",
})

employees, err := h.controller.Employee.ListWithLocation()
if err != nil {
l.Error(err, "failed to list employees")
errs.ConvertControllerErr(c, err)
return
}

c.JSON(http.StatusOK, view.CreateResponse[any](view.ToEmployeesWithLocation(employees), nil, nil, nil, ""))
}
1 change: 1 addition & 0 deletions pkg/handler/employee/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type IHandler interface {
Details(c *gin.Context)
GetLineManagers(c *gin.Context)
List(c *gin.Context)
ListWithLocation(c *gin.Context)
UpdateEmployeeStatus(c *gin.Context)
UpdateGeneralInfo(c *gin.Context)
UpdateSkills(c *gin.Context)
Expand Down
10 changes: 10 additions & 0 deletions pkg/routes/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,14 @@ func loadV1Routes(r *gin.Engine, h *handler.Handler, repo store.DBRepo, s *store
braineryGroup.GET("/metrics", amw.WithAuth, pmw.WithPerm(model.PermissionBraineryLogsRead), h.BraineryLog.GetMetrics)
braineryGroup.POST("/sync", amw.WithAuth, pmw.WithPerm(model.PermissionCronjobExecute), h.BraineryLog.Sync)
}

/////////////////
// PUBLIC API GROUP
/////////////////

// assets
publicGroup := v1.Group("/public")
{
publicGroup.GET("/employees", h.Employee.ListWithLocation)
}
}
6 changes: 6 additions & 0 deletions pkg/routes/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,12 @@ func Test_loadV1Routes(t *testing.T) {
Handler: "github.com/dwarvesf/fortress-api/pkg/handler/brainerylogs.IHandler.Sync-fm",
},
},
"/api/v1/public/employees": {
"GET": {
Method: "GET",
Handler: "github.com/dwarvesf/fortress-api/pkg/handler/employee.IHandler.ListWithLocation-fm",
},
},
}

l := logger.NewLogrusLogger()
Expand Down
11 changes: 11 additions & 0 deletions pkg/store/employee/employee.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,14 @@ func (s *store) GetByDiscordID(db *gorm.DB, discordID string) (*model.Employee,
var employee *model.Employee
return employee, db.Joins("JOIN discord_accounts ON discord_accounts.id = employees.discord_account_id AND discord_accounts.discord_id = ?", discordID).Order("created_at").First(&employee).Error
}

// SimpleList get employees by query and pagination
func (s *store) SimpleList(db *gorm.DB) ([]*model.Employee, error) {
var employees []*model.Employee

query := db.Where("deleted_at IS NULL AND working_status <> ?", model.WorkingStatusLeft).
Order("created_at").
Preload("DiscordAccount", "deleted_at IS NULL")

return employees, query.Find(&employees).Error
}
1 change: 1 addition & 0 deletions pkg/store/employee/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type IStore interface {
GetLineManagersOfPeers(db *gorm.DB, employeeID string) ([]*model.Employee, error)
GetMenteesByID(db *gorm.DB, employeeID string) ([]*model.Employee, error)
GetByDiscordID(db *gorm.DB, discordID string) (*model.Employee, error)
SimpleList(db *gorm.DB) ([]*model.Employee, error)

IsExist(db *gorm.DB, id string) (bool, error)

Expand Down
43 changes: 43 additions & 0 deletions pkg/view/employee.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,46 @@ func ToBasicEmployeeInvitationData(in *model.EmployeeInvitation) *EmployeeInvita

return rs
}

type EmployeeLocationListResponse struct {
Data []EmployeeLocation `json:"data"`
}

type EmployeeLocation struct {
DiscordID string `json:"discordID"`
FullName string `json:"fullName"`
DisplayName string `json:"displayName"`
Avatar string `json:"avatar"`
Address EmployeeAddress `json:"address"`
}
type EmployeeAddress struct {
Address string `json:"address"`
Country string `json:"country"`
City string `json:"city"`
Lat string `json:"lat"`
Long string `json:"long"`
}

func ToEmployeesWithLocation(in []*model.Employee) []EmployeeLocation {
rs := make([]EmployeeLocation, len(in))
for i, v := range in {
discordID := ""
if v.DiscordAccount != nil {
discordID = v.DiscordAccount.DiscordID
}
rs[i] = EmployeeLocation{
DiscordID: discordID,
FullName: v.FullName,
DisplayName: v.DisplayName,
Avatar: v.Avatar,
Address: EmployeeAddress{
Address: v.City + ", " + v.Country,
Country: v.Country,
City: v.City,
Lat: v.Lat,
Long: v.Long,
},
}
}
return rs
}