Skip to content

Commit

Permalink
Merge branch 'dev' into fix/create-job-post
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberguru1 authored Aug 9, 2024
2 parents cb8c5a6 + a022a0b commit 7e0aac9
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion internal/models/faqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type FAQ struct {
ID string `gorm:"primaryKey;type:uuid" json:"id"`
Question string `gorm:"type:varchar(225);not null" json:"question" validate:"required"`
Answer string `gorm:"type:text;not null" json:"answer" validate:"required"`
Category string `gorm:"type:varchar(30);not null" json:"category" validate:"required"`
Category string `gorm:"type:varchar(30);null" json:"category" validate:"required"`
CreatedAt time.Time `gorm:"column:created_at; not null; autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at; null; autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Expand Down
6 changes: 3 additions & 3 deletions internal/models/superadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type Language struct {

type Timezone struct {
ID string `gorm:"type:uuid;primary_key" json:"timezone_id"`
Timezone string `gorm:"type:varchar(40);unique;not null" json:"timezone" validate:"required"`
GmtOffset string `gorm:"type:varchar(20);unique;not null" json:"gmt_offset" validate:"required"`
Description string `gorm:"type:varchar(100);not null" json:"description" validate:"required"`
Timezone string `gorm:"type:varchar(40);unique;null" json:"timezone" validate:"required"`
GmtOffset string `gorm:"type:varchar(20);unique;null" json:"gmt_offset" validate:"required"`
Description string `gorm:"type:varchar(100);null" json:"description" validate:"required"`
CreatedAt time.Time `gorm:"column:created_at;not null;autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Expand Down
24 changes: 12 additions & 12 deletions pkg/router/organisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ func Organisation(r *gin.Engine, ApiVersion string, validator *validator.Validat

organisationUrl := r.Group(fmt.Sprintf("%v", ApiVersion), middleware.Authorize(db.Postgresql, models.RoleIdentity.SuperAdmin, models.RoleIdentity.User))
{
organisationUrl.POST("/organizations", organisation.CreateOrganisation)
organisationUrl.GET("/organizations/:org_id", organisation.GetOrganisation)
organisationUrl.DELETE("/organizations/:org_id", organisation.DeleteOrganisation)
organisationUrl.PATCH("/organizations/:org_id", organisation.UpdateOrganisation)
organisationUrl.GET("/organizations/:org_id/users", organisation.GetUsersInOrganisation)
organisationUrl.POST("/organizations/:org_id/roles", organisation.CreateOrgRole)
organisationUrl.GET("/organizations/:org_id/roles", organisation.GetOrgRoles)
organisationUrl.GET("/organizations/:org_id/roles/:role_id", organisation.GetAOrgRole)
organisationUrl.DELETE("/organizations/:org_id/roles/:role_id", organisation.DeleteOrgRole)
organisationUrl.PATCH("/organizations/:org_id/roles/:role_id", organisation.UpdateOrgRole)
organisationUrl.PATCH("/organizations/:org_id/roles/:role_id/permissions", organisation.UpdateOrgPermissions)
organisationUrl.POST("/organisations", organisation.CreateOrganisation)
organisationUrl.GET("/organisations/:org_id", organisation.GetOrganisation)
organisationUrl.DELETE("/organisations/:org_id", organisation.DeleteOrganisation)
organisationUrl.PATCH("/organisations/:org_id", organisation.UpdateOrganisation)
organisationUrl.GET("/organisations/:org_id/users", organisation.GetUsersInOrganisation)
organisationUrl.POST("/organisations/:org_id/roles", organisation.CreateOrgRole)
organisationUrl.GET("/organisations/:org_id/roles", organisation.GetOrgRoles)
organisationUrl.GET("/organisations/:org_id/roles/:role_id", organisation.GetAOrgRole)
organisationUrl.DELETE("/organisations/:org_id/roles/:role_id", organisation.DeleteOrgRole)
organisationUrl.PATCH("/organisations/:org_id/roles/:role_id", organisation.UpdateOrgRole)
organisationUrl.PATCH("/organisations/:org_id/roles/:role_id/permissions", organisation.UpdateOrgPermissions)
}

organisationUrlSec := r.Group(fmt.Sprintf("%v", ApiVersion), middleware.Authorize(db.Postgresql, models.RoleIdentity.SuperAdmin))

{
organisationUrlSec.POST("/organizations/:org_id/users", organisation.AddUserToOrganisation)
organisationUrlSec.POST("/organisations/:org_id/users", organisation.AddUserToOrganisation)
}
return r
}
11 changes: 6 additions & 5 deletions static/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4463,7 +4463,7 @@ paths:
security:
- bearerAuth: []

/api/v1/notifications:
/notifications/global:
post:
tags:
- notifications
Expand Down Expand Up @@ -4556,6 +4556,7 @@ paths:
security:
- bearerAuth: []

/notifications/all:
get:
tags:
- notifications
Expand Down Expand Up @@ -4639,7 +4640,7 @@ paths:
security:
- bearerAuth: []

/api/v1/notifications/:
/notifications/unread:
get:
tags:
- notifications
Expand Down Expand Up @@ -4730,13 +4731,13 @@ paths:
security:
- bearerAuth: []

/api/v1/notifications/{notification_id}:
/notifications/{notification_id}:
patch:
tags:
- notifications
summary: Mark a notification as read
parameters:
- name: notification_id
- name: notificationId
in: path
required: true
schema:
Expand Down Expand Up @@ -4920,7 +4921,7 @@ paths:
security:
- bearerAuth: []

/api/v1/notification-settings:
/settings/notification-settings:
patch:
tags:
- notification_settings
Expand Down
12 changes: 6 additions & 6 deletions tests/test_organisation/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func SetupOrgRoutes(r *gin.Engine, orgController *organisation.Controller) {
orgUrl := r.Group("/api/v1",
middleware.Authorize(orgController.Db.Postgresql, models.RoleIdentity.SuperAdmin, models.RoleIdentity.User))

orgUrl.POST("/organizations/:org_id/roles", orgController.CreateOrgRole)
orgUrl.GET("/organizations/:org_id/roles", orgController.GetOrgRoles)
orgUrl.GET("/organizations/:org_id/roles/:role_id", orgController.GetAOrgRole)
orgUrl.DELETE("/organizations/:org_id/roles/:role_id", orgController.DeleteOrgRole)
orgUrl.PATCH("/organizations/:org_id/roles/:role_id", orgController.UpdateOrgRole)
orgUrl.PATCH("/organizations/:org_id/roles/:role_id/permissions", orgController.UpdateOrgPermissions)
orgUrl.POST("/organisations/:org_id/roles", orgController.CreateOrgRole)
orgUrl.GET("/organisations/:org_id/roles", orgController.GetOrgRoles)
orgUrl.GET("/organisations/:org_id/roles/:role_id", orgController.GetAOrgRole)
orgUrl.DELETE("/organisations/:org_id/roles/:role_id", orgController.DeleteOrgRole)
orgUrl.PATCH("/organisations/:org_id/roles/:role_id", orgController.UpdateOrgRole)
orgUrl.PATCH("/organisations/:org_id/roles/:role_id/permissions", orgController.UpdateOrgPermissions)
}
8 changes: 4 additions & 4 deletions tests/test_organisation/create_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestCreateOrgRole(t *testing.T) {
}
roleJSON, _ := json.Marshal(role)

req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organizations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organisations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand All @@ -97,7 +97,7 @@ func TestCreateOrgRole(t *testing.T) {
}
roleJSON, _ := json.Marshal(role)

req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organizations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organisations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer invalid_token")

Expand Down Expand Up @@ -125,7 +125,7 @@ func TestCreateOrgRole(t *testing.T) {
}
roleJSON, _ := json.Marshal(role)

req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organizations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organisations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand All @@ -152,7 +152,7 @@ func TestCreateOrgRole(t *testing.T) {
}
roleJSON, _ := json.Marshal(role)

req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organizations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("/api/v1/organisations/%s/roles", orgID), bytes.NewBuffer(roleJSON))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand Down
8 changes: 4 additions & 4 deletions tests/test_organisation/delete_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestDeleteOrgRole(t *testing.T) {
}
token := tests.GetLoginToken(t, router, *orgController, loginData)

req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organizations/%s/roles/%s", orgID, roleID), nil)
req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organisations/%s/roles/%s", orgID, roleID), nil)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

resp := httptest.NewRecorder()
Expand All @@ -93,7 +93,7 @@ func TestDeleteOrgRole(t *testing.T) {
t.Run("Unauthorized Access", func(t *testing.T) {
router, _ := setup()

req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organizations/%s/roles/%s", orgID, roleID), nil)
req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organisations/%s/roles/%s", orgID, roleID), nil)
req.Header.Set("Authorization", "Bearer invalid_token")

resp := httptest.NewRecorder()
Expand All @@ -113,7 +113,7 @@ func TestDeleteOrgRole(t *testing.T) {
}
token := tests.GetLoginToken(t, router, *orgController, loginData)

req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organizations/%s/roles/%s", orgID, roleID), nil)
req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organisations/%s/roles/%s", orgID, roleID), nil)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

resp := httptest.NewRecorder()
Expand All @@ -135,7 +135,7 @@ func TestDeleteOrgRole(t *testing.T) {

nonExistentRoleID := utility.GenerateUUID()

req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organizations/%s/roles/%s", orgID, nonExistentRoleID), nil)
req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organisations/%s/roles/%s", orgID, nonExistentRoleID), nil)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

resp := httptest.NewRecorder()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_organisation/get_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestGetOrgRoles(t *testing.T) {
}
token := tests.GetLoginToken(t, router, *orgController, loginData)

req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organizations/%s/roles", orgID), nil)
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organisations/%s/roles", orgID), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand All @@ -102,7 +102,7 @@ func TestGetOrgRoles(t *testing.T) {
t.Run("Unauthorized Access", func(t *testing.T) {
router, _ := setup()

req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organizations/%s/roles", orgID), nil)
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organisations/%s/roles", orgID), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer invalid_token")

Expand All @@ -123,7 +123,7 @@ func TestGetOrgRoles(t *testing.T) {
}
token := tests.GetLoginToken(t, router, *orgController, loginData)

req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organizations/%s/roles", orgID), nil)
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organisations/%s/roles", orgID), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand Down Expand Up @@ -202,7 +202,7 @@ func TestGetAOrgRole(t *testing.T) {
}
token := tests.GetLoginToken(t, router, *orgController, loginData)

req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organizations/%s/roles/%s", orgID, roleID), nil)
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organisations/%s/roles/%s", orgID, roleID), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand All @@ -217,7 +217,7 @@ func TestGetAOrgRole(t *testing.T) {
t.Run("Unauthorized Access", func(t *testing.T) {
router, _ := setup()

req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organizations/%s/roles/%s", orgID, roleID), nil)
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organisations/%s/roles/%s", orgID, roleID), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer invalid_token")

Expand All @@ -238,7 +238,7 @@ func TestGetAOrgRole(t *testing.T) {
}
token := tests.GetLoginToken(t, router, *orgController, loginData)

req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organizations/%s/roles/%s", orgID, roleID), nil)
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organisations/%s/roles/%s", orgID, roleID), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand Down
20 changes: 10 additions & 10 deletions tests/test_organisation/organisation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestOrganizationCreate(t *testing.T) {

validatorRef := validator.New()
db := storage.Connection()
requestURI := url.URL{Path: "/api/v1/organizations"}
requestURI := url.URL{Path: "/api/v1/organisations"}
currUUID := utility.GenerateUUID()
userSignUpData := models.CreateUserRequestModel{
Email: fmt.Sprintf("testuser%[email protected]", currUUID),
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestOrganizationCreate(t *testing.T) {

orgUrl := r.Group(fmt.Sprintf("%v", "/api/v1"), middleware.Authorize(db.Postgresql, models.RoleIdentity.SuperAdmin, models.RoleIdentity.User))
{
orgUrl.POST("/organizations", org.CreateOrganisation)
orgUrl.POST("/organisations", org.CreateOrganisation)

}

Expand Down Expand Up @@ -246,12 +246,12 @@ func TestGetOrganisation(t *testing.T) {

orgUrl := r.Group("/api/v1", middleware.Authorize(db.Postgresql, models.RoleIdentity.SuperAdmin, models.RoleIdentity.User))
{
orgUrl.GET("/organizations/:org_id", org.GetOrganisation)
orgUrl.GET("/organisations/:org_id", org.GetOrganisation)
}

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organizations/%s", test.OrgID), nil)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/organisations/%s", test.OrgID), nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -386,15 +386,15 @@ func TestOrganisationUpdate(t *testing.T) {

orgUrl := r.Group("/api/v1", middleware.Authorize(db.Postgresql, models.RoleIdentity.SuperAdmin, models.RoleIdentity.User))
{
orgUrl.PATCH("/organizations/:org_id", org.UpdateOrganisation)
orgUrl.PATCH("/organisations/:org_id", org.UpdateOrganisation)
}

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
var b bytes.Buffer
json.NewEncoder(&b).Encode(test.RequestBody)

req, err := http.NewRequest(http.MethodPatch, fmt.Sprintf("/api/v1/organizations/%s", test.OrgID), &b)
req, err := http.NewRequest(http.MethodPatch, fmt.Sprintf("/api/v1/organisations/%s", test.OrgID), &b)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -498,12 +498,12 @@ func TestOrganisationDelete(t *testing.T) {

orgUrl := r.Group("/api/v1", middleware.Authorize(db.Postgresql, models.RoleIdentity.SuperAdmin, models.RoleIdentity.User))
{
orgUrl.DELETE("/organizations/:org_id", org.DeleteOrganisation)
orgUrl.DELETE("/organisations/:org_id", org.DeleteOrganisation)
}

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organizations/%s", test.OrgID), nil)
req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/organisations/%s", test.OrgID), nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -616,11 +616,11 @@ func TestGetUsersInOrg(t *testing.T) {

orgUrl := r.Group(fmt.Sprintf("%v", "/api/v1"), middleware.Authorize(db.Postgresql,models.RoleIdentity.SuperAdmin, models.RoleIdentity.User))
{
orgUrl.GET("/organizations/:org_id/users", org.GetUsersInOrganisation)
orgUrl.GET("/organisations/:org_id/users", org.GetUsersInOrganisation)
}

t.Run(test.Name, func(t *testing.T) {
req, err := http.NewRequest(http.MethodGet,fmt.Sprintf("/api/v1/organizations/%s/users", test.OrgID), nil)
req, err := http.NewRequest(http.MethodGet,fmt.Sprintf("/api/v1/organisations/%s/users", test.OrgID), nil)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 7e0aac9

Please sign in to comment.