67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package organization
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"lms.de/backend/modules/database"
|
|
"lms.de/backend/modules/structs"
|
|
)
|
|
|
|
func GetOrganizationSettings(c *fiber.Ctx) error {
|
|
// swagger:operation GET /organization/settings organization getOrganizationSettings
|
|
// ---
|
|
// summary: Get settings
|
|
// consumes:
|
|
// - application/json
|
|
// produces:
|
|
// - application/json
|
|
// responses:
|
|
// '200':
|
|
// description: Settings fetched successfully
|
|
// schema:
|
|
// "$ref": "#/definitions/GetOrganizationSettingsResponse"
|
|
// '400':
|
|
// description: Invalid request body
|
|
// '500':
|
|
// description: Failed to fetch settings
|
|
|
|
var organizationSettings structs.GetOrganizationSettingsResponse
|
|
|
|
database.DB.Model(&structs.Organization{}).Select("subdomain", "company_name", "primary_color", "logo_url", "banner_url").First(&organizationSettings)
|
|
|
|
return c.JSON(organizationSettings)
|
|
}
|
|
|
|
func UpdateOrganizationSettings(c *fiber.Ctx) error {
|
|
// swagger:operation PATCH /organization/settings organization updateOrganizationSettings
|
|
// ---
|
|
// summary: Update settings
|
|
// consumes:
|
|
// - application/json
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: body
|
|
// in: body
|
|
// schema:
|
|
// "$ref": "#/definitions/GetOrganizationSettingsResponse"
|
|
// responses:
|
|
// '200':
|
|
// description: Settings updated successfully
|
|
// '400':
|
|
// description: Invalid request body
|
|
// '500':
|
|
// description: Failed to update settings
|
|
|
|
var organizationSettings structs.UpdateOrganizationSettingsRequest
|
|
|
|
if err := c.BodyParser(&organizationSettings); err != nil {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
database.DB.Model(&structs.Organization{
|
|
Id: c.Locals("organizationId").(string),
|
|
}).Updates(organizationSettings)
|
|
|
|
return c.SendStatus(fiber.StatusOK)
|
|
}
|