97 lines
2.2 KiB
Go
97 lines
2.2 KiB
Go
|
|
package yclients
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"database/sql"
|
||
|
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||
|
|
"gitea.pena/SQuiz/common/model"
|
||
|
|
)
|
||
|
|
|
||
|
|
type YclientsRepository struct {
|
||
|
|
queries *sqlcgen.Queries
|
||
|
|
pool *sql.DB
|
||
|
|
}
|
||
|
|
|
||
|
|
type Deps struct {
|
||
|
|
Queries *sqlcgen.Queries
|
||
|
|
Pool *sql.DB
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewYclientsRepository(deps Deps) *YclientsRepository {
|
||
|
|
return &YclientsRepository{
|
||
|
|
queries: deps.Queries,
|
||
|
|
pool: deps.Pool,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (r *YclientsRepository) GetCurrentAccount(ctx context.Context, accountID string) (*model.YclientsAccount, error) {
|
||
|
|
row, err := r.queries.GetCurrentYclientsCompany(ctx, accountID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
user := model.YclientsAccount{
|
||
|
|
ID: row.ID,
|
||
|
|
AccountID: row.Accountid,
|
||
|
|
YclientsID: row.Yclientsid,
|
||
|
|
Name: row.Name,
|
||
|
|
Country: row.Country,
|
||
|
|
Deleted: row.Deleted,
|
||
|
|
CreatedAt: row.Createdat,
|
||
|
|
Subdomain: row.Subdomain,
|
||
|
|
}
|
||
|
|
|
||
|
|
//_, err = r.queries.CheckExpiredYclientsToken(ctx, accountID)
|
||
|
|
//if err != nil {
|
||
|
|
// if err == sql.ErrNoRows {
|
||
|
|
// user.Stale = false
|
||
|
|
// return &user, nil
|
||
|
|
// }
|
||
|
|
// return nil, err
|
||
|
|
//}
|
||
|
|
|
||
|
|
user.Stale = true
|
||
|
|
|
||
|
|
return &user, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
//func (r *YclientsRepository) SoftDeleteAccount(ctx context.Context, accountID string) error {
|
||
|
|
// err := r.queries.SoftDeleteYclientsAccount(ctx, accountID)
|
||
|
|
// if err != nil {
|
||
|
|
// return err
|
||
|
|
// }
|
||
|
|
// return nil
|
||
|
|
//}
|
||
|
|
|
||
|
|
func (r *YclientsRepository) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListYclientsResp, error) {
|
||
|
|
rows, err := r.queries.GetUsersYclientsWithPagination(ctx, sqlcgen.GetUsersYclientsWithPaginationParams{
|
||
|
|
Accountid: accountID,
|
||
|
|
Column2: req.Page,
|
||
|
|
Limit: req.Size,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
var users []model.YclientsAccountUser
|
||
|
|
var count int64
|
||
|
|
for _, row := range rows {
|
||
|
|
users = append(users, model.YclientsAccountUser{
|
||
|
|
ID: row.ID,
|
||
|
|
YclientsID: row.Yclientsid,
|
||
|
|
YclientsUserID: row.Yclientsuserid,
|
||
|
|
Name: row.Name,
|
||
|
|
Role: row.Role,
|
||
|
|
Deleted: row.Deleted,
|
||
|
|
CreatedAt: row.Createdat,
|
||
|
|
})
|
||
|
|
count = row.TotalCount
|
||
|
|
}
|
||
|
|
|
||
|
|
resp := model.UserListYclientsResp{
|
||
|
|
Count: count,
|
||
|
|
Items: users,
|
||
|
|
}
|
||
|
|
|
||
|
|
return &resp, nil
|
||
|
|
}
|