MCPcopy Create free account
hub / github.com/QuantumNous/new-api / tasksToDto

Function tasksToDto

controller/task.go:63–88  ·  view source on GitHub ↗
(tasks []*model.Task, fillUser bool)

Source from the content-addressed store, hash-verified

61}
62
63func tasksToDto(tasks []*model.Task, fillUser bool) []*dto.TaskDto {
64 var userIdMap map[int]*model.UserBase
65 if fillUser {
66 userIdMap = make(map[int]*model.UserBase)
67 userIds := types.NewSet[int]()
68 for _, task := range tasks {
69 userIds.Add(task.UserId)
70 }
71 for _, userId := range userIds.Items() {
72 cacheUser, err := model.GetUserCache(userId)
73 if err == nil {
74 userIdMap[userId] = cacheUser
75 }
76 }
77 }
78 result := make([]*dto.TaskDto, len(tasks))
79 for i, task := range tasks {
80 if fillUser {
81 if user, ok := userIdMap[task.UserId]; ok {
82 task.Username = user.Username
83 }
84 }
85 result[i] = relay.TaskModel2Dto(task)
86 }
87 return result
88}

Callers 2

GetAllTaskFunction · 0.85
GetUserTaskFunction · 0.85

Calls 4

GetUserCacheFunction · 0.92
TaskModel2DtoFunction · 0.92
AddMethod · 0.80
ItemsMethod · 0.80

Tested by

no test coverage detected