update organization settings
parent
d35d43a494
commit
7fda97d09e
|
@ -0,0 +1,17 @@
|
|||
package structs
|
||||
|
||||
type GetAppResponse struct {
|
||||
User AppUser
|
||||
Organization AppOrganization
|
||||
}
|
||||
|
||||
type AppUser struct {
|
||||
ProfilePictureUrl string
|
||||
}
|
||||
|
||||
type AppOrganization struct {
|
||||
CompanyName string
|
||||
PrimaryColor string
|
||||
LogoUrl string
|
||||
BannerUrl string
|
||||
}
|
|
@ -34,3 +34,8 @@ type GetOrganizationSettingsResponse struct {
|
|||
LogoUrl string
|
||||
BannerUrl string
|
||||
}
|
||||
|
||||
type UpdateOrganizationSettingsRequest struct {
|
||||
CompanyName string
|
||||
PrimaryColor string
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"lms.de/backend/modules/database"
|
||||
"lms.de/backend/modules/structs"
|
||||
)
|
||||
|
||||
func GetApp(c *fiber.Ctx) error {
|
||||
// swagger:operation GET /app app getApp
|
||||
// ---
|
||||
// summary: Get app
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// responses:
|
||||
// '200':
|
||||
// description: App fetched successfully
|
||||
// schema:
|
||||
// "$ref": "#/definitions/GetAppResponse"
|
||||
// '400':
|
||||
// description: Invalid request body
|
||||
// '500':
|
||||
// description: Failed to fetch app
|
||||
|
||||
var user structs.User
|
||||
|
||||
database.DB.Model(&structs.User{
|
||||
Id: c.Locals("userId").(string),
|
||||
}).Select("profile_picture_url").First(&user)
|
||||
|
||||
var organization structs.Organization
|
||||
|
||||
database.DB.Model(&structs.Organization{
|
||||
Id: c.Locals("organizationId").(string),
|
||||
}).Select("company_name", "primary_color", "logo_url", "banner_url").First(&organization)
|
||||
|
||||
return c.JSON(structs.GetAppResponse{
|
||||
User: structs.AppUser{
|
||||
ProfilePictureUrl: user.ProfilePictureUrl,
|
||||
},
|
||||
Organization: structs.AppOrganization{
|
||||
CompanyName: organization.CompanyName,
|
||||
PrimaryColor: organization.PrimaryColor,
|
||||
LogoUrl: organization.LogoUrl,
|
||||
BannerUrl: organization.BannerUrl,
|
||||
},
|
||||
})
|
||||
}
|
|
@ -30,3 +30,37 @@ func GetOrganizationSettings(c *fiber.Ctx) error {
|
|||
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -1,13 +1 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"lms.de/backend/modules/structs"
|
||||
)
|
||||
|
||||
func GetUser(c *fiber.Ctx) error {
|
||||
|
||||
return c.JSON(structs.GetUserResponse{
|
||||
AvatarUrl: "",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"lms.de/backend/modules/database"
|
||||
"lms.de/backend/modules/structs"
|
||||
"lms.de/backend/modules/utils"
|
||||
myapp "lms.de/backend/routers/router/api/v1/app"
|
||||
"lms.de/backend/routers/router/api/v1/lessons"
|
||||
"lms.de/backend/routers/router/api/v1/organization"
|
||||
"lms.de/backend/routers/router/api/v1/user"
|
||||
|
@ -16,13 +17,15 @@ import (
|
|||
func SetupRoutes(app *fiber.App) {
|
||||
v1 := app.Group("/v1")
|
||||
|
||||
v1.Get("/app", handleOrganizationSubdomain, requestAccessValidation, myapp.GetApp)
|
||||
|
||||
o := v1.Group("/organization")
|
||||
o.Post("/", organization.CreateOrganization)
|
||||
o.Get("/team/members", handleOrganizationSubdomain, requestAccessValidation, organization.GetTeamMembers)
|
||||
o.Get("/settings", handleOrganizationSubdomain, requestAccessValidation, organization.GetOrganizationSettings)
|
||||
o.Patch("/settings", handleOrganizationSubdomain, requestAccessValidation, organization.UpdateOrganizationSettings)
|
||||
|
||||
u := v1.Group("/user")
|
||||
u.Get("/", handleOrganizationSubdomain, requestAccessValidation, user.GetUser)
|
||||
u.Post("/auth/login", handleOrganizationSubdomain, user.UserLogin)
|
||||
|
||||
l := v1.Group("/lessons")
|
||||
|
@ -58,7 +61,7 @@ func userSessionValidation(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
c.Locals("userId", userSession.UserId)
|
||||
c.Locals("organizationId", c.Locals("organizationId"))
|
||||
//c.Locals("organizationId", c.Locals("organizationId"))
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue