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