questions count
parent
6a9cde458a
commit
8b05982273
|
@ -9,12 +9,13 @@ const (
|
|||
|
||||
// swagger:model LessonResponse
|
||||
type LessonResponse struct {
|
||||
Id string
|
||||
State uint8
|
||||
Title string
|
||||
ThumbnailUrl string
|
||||
CreatorUserId string
|
||||
CreatedAt time.Time
|
||||
Id string
|
||||
State uint8
|
||||
Title string
|
||||
ThumbnailUrl string
|
||||
QuestionsCount int `gorm:"-"`
|
||||
CreatorUserId string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// swagger:model CreateLessonResponse
|
||||
|
|
|
@ -41,6 +41,20 @@ func GetLessons(c *fiber.Ctx) error {
|
|||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// get all questions for each lesson
|
||||
|
||||
for i, lesson := range lessons {
|
||||
var questionsCount int64
|
||||
|
||||
if err := database.DB.Model(&models.Question{}).
|
||||
Where("lesson_id = ?", lesson.Id).
|
||||
Count(&questionsCount).Error; err != nil {
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
lessons[i].QuestionsCount = int(questionsCount)
|
||||
}
|
||||
|
||||
return c.JSON(lessons)
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ func GetRoles(c *fiber.Ctx) error {
|
|||
var users []structs.HelperRoleUser
|
||||
|
||||
if err := database.DB.Model(&models.User{}).
|
||||
Select("first_name", "last_name", "profile_picture_url").
|
||||
Where("role_id = ? AND organization_id = ?", key, c.Locals("organizationId").(string)).
|
||||
Find(&users).Error; err != nil {
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
|
|
Loading…
Reference in New Issue