-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
27 changed files
with
78 additions
and
117 deletions.
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
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
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
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
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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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
4 changes: 2 additions & 2 deletions
4
pkg/store/bonus/interface.go → pkg/store/employeebonus/interface.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package bonus | ||
package employeebonus | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
|
||
"github.com/dwarvesf/fortress-api/pkg/model" | ||
) | ||
|
||
// Store is an interface that abstract database method for bonus | ||
// IStore is an interface that abstract database method for bonus | ||
type IStore interface { | ||
GetByUserID(db *gorm.DB, id model.UUID) ([]model.EmployeeBonus, 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 |
---|---|---|
@@ -1,18 +1,43 @@ | ||
package employeecommission | ||
|
||
import ( | ||
"time" | ||
|
||
"gorm.io/gorm" | ||
|
||
"github.com/dwarvesf/fortress-api/pkg/model" | ||
) | ||
|
||
type store struct{} | ||
|
||
// New initialize new store for commission | ||
func New() IStore { | ||
return &store{} | ||
} | ||
|
||
// Create make new one by id | ||
func (s *store) Create(db *gorm.DB, employeeCommissions []model.EmployeeCommission) ([]model.EmployeeCommission, error) { | ||
return employeeCommissions, db.Create(&employeeCommissions).Error | ||
} | ||
|
||
func (s *store) Get(db *gorm.DB, q Query) ([]model.EmployeeCommission, error) { | ||
var res []model.EmployeeCommission | ||
if q.EmployeeID != "" { | ||
db = db.Where("employee_id = ?", q.EmployeeID) | ||
} | ||
if q.FromDate != nil { | ||
db = db.Where("created_at > ?", q.FromDate) | ||
} | ||
if q.ToDate != nil { | ||
db = db.Where("created_at < ?", q.ToDate) | ||
} | ||
return res, db.Preload("Invoice").Where("is_paid = ?", q.IsPaid).Find(&res).Error | ||
} | ||
|
||
func (s *store) MarkPaid(db *gorm.DB, id model.UUID) error { | ||
var cms model.EmployeeCommission | ||
err := db.Where("id = ?", id).Find(&cms).Error | ||
if err != nil { | ||
return err | ||
} | ||
return db.Model(&cms).Updates(map[string]interface{}{"is_paid": true, "paid_at": time.Now()}).Error | ||
} |
2 changes: 1 addition & 1 deletion
2
pkg/store/commission/pg_test.go → ...yeecommission/employee_commission_test.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package commission | ||
package employeecommission | ||
|
||
// func TestCreate(t *testing.T) { | ||
// t.Parallel() | ||
|
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 |
---|---|---|
@@ -1,11 +1,25 @@ | ||
package employeecommission | ||
|
||
import ( | ||
"time" | ||
|
||
"gorm.io/gorm" | ||
|
||
"github.com/dwarvesf/fortress-api/pkg/model" | ||
) | ||
|
||
// IStore is an interface that abstract database method for commission | ||
type IStore interface { | ||
// Create new row for table user_commissions, save the commission | ||
// for an user for specific invoice | ||
Create(db *gorm.DB, employeeCommissions []model.EmployeeCommission) ([]model.EmployeeCommission, error) | ||
Get(db *gorm.DB, q Query) ([]model.EmployeeCommission, error) | ||
MarkPaid(db *gorm.DB, ids model.UUID) error | ||
} | ||
|
||
type Query struct { | ||
EmployeeID string | ||
FromDate *time.Time | ||
ToDate *time.Time | ||
IsPaid bool | ||
} |
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
File renamed without changes.
Oops, something went wrong.