added company table and get company with pagination query
This commit is contained in:
parent
bd515ca881
commit
fb85656d52
@ -1507,3 +1507,13 @@ FROM YclientsAccountUsers u
|
||||
JOIN user_data a ON u.YclientsID = a.YclientsID
|
||||
WHERE u.Deleted = false
|
||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
||||
|
||||
-- name: GetCompanyYclientsWithPagination :many
|
||||
WITH user_data AS (
|
||||
SELECT YclientsID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
||||
)
|
||||
SELECT u.*, COUNT(*) OVER() as total_count
|
||||
FROM YclientsCompany u
|
||||
JOIN user_data a ON u.YclientsID = a.YclientsID
|
||||
WHERE u.Deleted = false
|
||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
||||
@ -1,2 +1,3 @@
|
||||
DROP TABLE If EXIST accountsYclients;
|
||||
DROP TABLE If EXIST usersYclients;
|
||||
DROP TABLE If EXIST YclientsAccounts;
|
||||
DROP TABLE If EXIST YclientsAccountUsers;
|
||||
DROP TABLE If EXIST YclientsCompany;
|
||||
@ -18,3 +18,17 @@ CREATE TABLE IF NOT EXISTS YclientsAccountUsers (
|
||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS YclientsCompany (
|
||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
||||
YclientsID INT NOT NULL, -- ID "компании"
|
||||
YclientsCompanyID INT NOT NULL,
|
||||
Title text NOT NULL,
|
||||
ShortDecription text NOT NULL,
|
||||
Active INT NOT NULL,
|
||||
Country text NOT NULL,
|
||||
GroupPriority INT NOT NULL,
|
||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
@ -419,3 +419,16 @@ type Yclientsaccountuser struct {
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Yclientscompany struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Yclientsid int32 `db:"yclientsid" json:"yclientsid"`
|
||||
Yclientscompanyid int32 `db:"yclientscompanyid" json:"yclientscompanyid"`
|
||||
Title string `db:"title" json:"title"`
|
||||
Shortdecription string `db:"shortdecription" json:"shortdecription"`
|
||||
Active int32 `db:"active" json:"active"`
|
||||
Country string `db:"country" json:"country"`
|
||||
Grouppriority int32 `db:"grouppriority" json:"grouppriority"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
@ -2383,6 +2383,72 @@ func (q *Queries) GetBitrixTokenById(ctx context.Context, accountid string) (Bit
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCompanyYclientsWithPagination = `-- name: GetCompanyYclientsWithPagination :many
|
||||
WITH user_data AS (
|
||||
SELECT YclientsID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
||||
)
|
||||
SELECT u.id, u.yclientsid, u.yclientscompanyid, u.title, u.shortdecription, u.active, u.country, u.grouppriority, u.deleted, u.createdat, COUNT(*) OVER() as total_count
|
||||
FROM YclientsCompany u
|
||||
JOIN user_data a ON u.YclientsID = a.YclientsID
|
||||
WHERE u.Deleted = false
|
||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3
|
||||
`
|
||||
|
||||
type GetCompanyYclientsWithPaginationParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Column2 interface{} `db:"column_2" json:"column_2"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
}
|
||||
|
||||
type GetCompanyYclientsWithPaginationRow struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Yclientsid int32 `db:"yclientsid" json:"yclientsid"`
|
||||
Yclientscompanyid int32 `db:"yclientscompanyid" json:"yclientscompanyid"`
|
||||
Title string `db:"title" json:"title"`
|
||||
Shortdecription string `db:"shortdecription" json:"shortdecription"`
|
||||
Active int32 `db:"active" json:"active"`
|
||||
Country string `db:"country" json:"country"`
|
||||
Grouppriority int32 `db:"grouppriority" json:"grouppriority"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||
TotalCount int64 `db:"total_count" json:"total_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCompanyYclientsWithPagination(ctx context.Context, arg GetCompanyYclientsWithPaginationParams) ([]GetCompanyYclientsWithPaginationRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getCompanyYclientsWithPagination, arg.Accountid, arg.Column2, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetCompanyYclientsWithPaginationRow
|
||||
for rows.Next() {
|
||||
var i GetCompanyYclientsWithPaginationRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Yclientsid,
|
||||
&i.Yclientscompanyid,
|
||||
&i.Title,
|
||||
&i.Shortdecription,
|
||||
&i.Active,
|
||||
&i.Country,
|
||||
&i.Grouppriority,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
&i.TotalCount,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getCurrentBitrixCompany = `-- name: GetCurrentBitrixCompany :one
|
||||
SELECT id, accountid, bitrixid, deleted, createdat, subdomain FROM BitrixAccounts WHERE AccountID = $1 AND Deleted = false
|
||||
`
|
||||
|
||||
@ -28,3 +28,21 @@ type UserListYclientsResp struct {
|
||||
Count int64 `json:"count"`
|
||||
Items []YclientsAccountUser `json:"items"`
|
||||
}
|
||||
|
||||
type YclientsCompany struct {
|
||||
ID int64 `json:"id"`
|
||||
YclientsID int32 `json:"yclientsID"`
|
||||
YclientsCompanyID int32 `json:"yclientsCompanyID"`
|
||||
Title string `json:"title"`
|
||||
ShortDecription string `json:"shortDecription"`
|
||||
Active int32 `json:"active"`
|
||||
Country string `json:"country"`
|
||||
GroupPriority int32 `json:"groupPriority"`
|
||||
Deleted bool `json:"deleted"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type CompanyListYclientsResp struct {
|
||||
Count int64 `json:"count"`
|
||||
Items []YclientsCompany `json:"items"`
|
||||
}
|
||||
|
||||
@ -94,3 +94,45 @@ func (r *YclientsRepository) GettingUserWithPagination(ctx context.Context, req
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// company
|
||||
|
||||
func (r *YclientsRepository) GettingCompanyWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.CompanyListYclientsResp, error) {
|
||||
rows, err := r.queries.GetCompanyYclientsWithPagination(ctx, sqlcgen.GetCompanyYclientsWithPaginationParams{
|
||||
Accountid: accountID,
|
||||
Column2: req.Page,
|
||||
Limit: req.Size,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var users []model.YclientsCompany
|
||||
var count int64
|
||||
for _, row := range rows {
|
||||
users = append(users, model.YclientsCompany{
|
||||
ID: row.ID,
|
||||
YclientsID: row.Yclientsid,
|
||||
YclientsCompanyID: row.Yclientscompanyid,
|
||||
Title: row.Title,
|
||||
ShortDecription: row.Shortdecription,
|
||||
Active: row.Active,
|
||||
Country: row.Country,
|
||||
GroupPriority: row.Grouppriority,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat,
|
||||
})
|
||||
count = row.TotalCount
|
||||
}
|
||||
|
||||
resp := model.CompanyListYclientsResp{
|
||||
Count: count,
|
||||
Items: users,
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// todo
|
||||
func (r *YclientsRepository) UpdateCompany() {
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user