-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddbc385
commit 35b7d6c
Showing
9 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2024 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization | ||
|
||
import ( | ||
"context" | ||
|
||
db "github.com/isaqueveras/powersso/database/postgres" | ||
domain "github.com/isaqueveras/powersso/domain/authorization/organization" | ||
infra "github.com/isaqueveras/powersso/infrastructure/persistencie/authorization/organization" | ||
"github.com/isaqueveras/powersso/oops" | ||
) | ||
|
||
// Create is the business logic for creating a new room | ||
func Create(ctx context.Context, in *Organization) (err error) { | ||
var tx *db.Transaction | ||
if tx, err = db.NewTransaction(ctx, false); err != nil { | ||
return oops.Err(err) | ||
} | ||
defer tx.Rollback() | ||
|
||
repo := infra.New(ctx, tx) | ||
if err = repo.Create(&domain.Organization{ | ||
Name: in.Name, | ||
Desc: in.Description, | ||
URL: in.Url, | ||
CreatedByID: in.CreatedByID, | ||
}); err != nil { | ||
return oops.Err(err) | ||
} | ||
|
||
if err = tx.Commit(); err != nil { | ||
return oops.Err(err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2024 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization | ||
|
||
import "github.com/google/uuid" | ||
|
||
// Organization models the data to create a organization | ||
type Organization struct { | ||
ID *uuid.UUID `json:"-"` | ||
Name *string `json:"name" binding:"required,min=3,max=20"` | ||
Description *string `json:"description"` | ||
Url *string `json:"url" binding:"required,max=200"` | ||
CreatedByID *uuid.UUID `json:"-"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/isaqueveras/powersso/application/authorization/organization" | ||
"github.com/isaqueveras/powersso/middleware" | ||
"github.com/isaqueveras/powersso/oops" | ||
"github.com/isaqueveras/powersso/utils" | ||
) | ||
|
||
// @Router /v1/room/create [post] | ||
func create(ctx *gin.Context) { | ||
var ( | ||
in = new(organization.Organization) | ||
session = middleware.GetSession(ctx) | ||
) | ||
|
||
if err := ctx.ShouldBindJSON(&in); err != nil { | ||
oops.Handling(ctx, err) | ||
return | ||
} | ||
|
||
in.CreatedByID = utils.Pointer(session.UserID) | ||
if err := organization.Create(ctx, in); err != nil { | ||
oops.Handling(ctx, err) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusCreated, utils.NoContent{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2024 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2024 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
// Router is the router for the room module. | ||
func Router(r *gin.RouterGroup) { | ||
r.POST("create", create) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) 2024 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization | ||
|
||
// IOrganization define an interface for data layer access methods | ||
type IOrganization interface { | ||
Create(*Organization) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2024 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
// Organization models the data of a organization | ||
type Organization struct { | ||
ID *uuid.UUID | ||
Name *string | ||
Desc *string | ||
URL *string | ||
CreatedByID *uuid.UUID | ||
CreatedAt *time.Time | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
infrastructure/persistencie/authorization/organization/repository.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2022 Isaque Veras | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package organization | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/isaqueveras/powersso/database/postgres" | ||
"github.com/isaqueveras/powersso/domain/authorization/organization" | ||
"github.com/isaqueveras/powersso/oops" | ||
) | ||
|
||
// repository is the implementation of the session repository | ||
type repository struct { | ||
pg *postgres.Transaction | ||
ctx context.Context | ||
} | ||
|
||
// New creates a new repository | ||
func New(ctx context.Context, tx *postgres.Transaction) organization.IOrganization { | ||
return &repository{ctx: ctx, pg: tx} | ||
} | ||
|
||
// Create contains the flow for create organization in database | ||
func (r *repository) Create(org *organization.Organization) error { | ||
if _, err := r.pg.Builder. | ||
Insert("organization"). | ||
Columns("name", "desc", "created_by", "url"). | ||
Values(org.Name, org.Desc, org.CreatedByID, org.URL). | ||
ExecContext(r.ctx); err != nil { | ||
return oops.Err(err) | ||
} | ||
return nil | ||
} |