153 lines
3.9 KiB
Go
153 lines
3.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// source: team_member.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createTeamMember = `-- name: CreateTeamMember :one
|
|
INSERT INTO team_member (team_id, user_id, addedDate, role_code) VALUES ($1, $2, $3, $4)
|
|
RETURNING team_member_id, team_id, user_id, addeddate, role_code
|
|
`
|
|
|
|
type CreateTeamMemberParams struct {
|
|
TeamID uuid.UUID `json:"team_id"`
|
|
UserID uuid.UUID `json:"user_id"`
|
|
Addeddate time.Time `json:"addeddate"`
|
|
RoleCode string `json:"role_code"`
|
|
}
|
|
|
|
func (q *Queries) CreateTeamMember(ctx context.Context, arg CreateTeamMemberParams) (TeamMember, error) {
|
|
row := q.db.QueryRowContext(ctx, createTeamMember,
|
|
arg.TeamID,
|
|
arg.UserID,
|
|
arg.Addeddate,
|
|
arg.RoleCode,
|
|
)
|
|
var i TeamMember
|
|
err := row.Scan(
|
|
&i.TeamMemberID,
|
|
&i.TeamID,
|
|
&i.UserID,
|
|
&i.Addeddate,
|
|
&i.RoleCode,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteTeamMember = `-- name: DeleteTeamMember :exec
|
|
DELETE FROM team_member WHERE user_id = $1 AND team_id = $2
|
|
`
|
|
|
|
type DeleteTeamMemberParams struct {
|
|
UserID uuid.UUID `json:"user_id"`
|
|
TeamID uuid.UUID `json:"team_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteTeamMember(ctx context.Context, arg DeleteTeamMemberParams) error {
|
|
_, err := q.db.ExecContext(ctx, deleteTeamMember, arg.UserID, arg.TeamID)
|
|
return err
|
|
}
|
|
|
|
const getRoleForTeamMember = `-- name: GetRoleForTeamMember :one
|
|
SELECT code, role.name FROM team_member
|
|
INNER JOIN role ON role.code = team_member.role_code
|
|
WHERE user_id = $1 AND team_id = $2
|
|
`
|
|
|
|
type GetRoleForTeamMemberParams struct {
|
|
UserID uuid.UUID `json:"user_id"`
|
|
TeamID uuid.UUID `json:"team_id"`
|
|
}
|
|
|
|
func (q *Queries) GetRoleForTeamMember(ctx context.Context, arg GetRoleForTeamMemberParams) (Role, error) {
|
|
row := q.db.QueryRowContext(ctx, getRoleForTeamMember, arg.UserID, arg.TeamID)
|
|
var i Role
|
|
err := row.Scan(&i.Code, &i.Name)
|
|
return i, err
|
|
}
|
|
|
|
const getTeamMemberByID = `-- name: GetTeamMemberByID :one
|
|
SELECT team_member_id, team_id, user_id, addeddate, role_code FROM team_member WHERE team_id = $1 AND user_id = $2
|
|
`
|
|
|
|
type GetTeamMemberByIDParams struct {
|
|
TeamID uuid.UUID `json:"team_id"`
|
|
UserID uuid.UUID `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) GetTeamMemberByID(ctx context.Context, arg GetTeamMemberByIDParams) (TeamMember, error) {
|
|
row := q.db.QueryRowContext(ctx, getTeamMemberByID, arg.TeamID, arg.UserID)
|
|
var i TeamMember
|
|
err := row.Scan(
|
|
&i.TeamMemberID,
|
|
&i.TeamID,
|
|
&i.UserID,
|
|
&i.Addeddate,
|
|
&i.RoleCode,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getTeamMembersForTeamID = `-- name: GetTeamMembersForTeamID :many
|
|
SELECT team_member_id, team_id, user_id, addeddate, role_code FROM team_member WHERE team_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetTeamMembersForTeamID(ctx context.Context, teamID uuid.UUID) ([]TeamMember, error) {
|
|
rows, err := q.db.QueryContext(ctx, getTeamMembersForTeamID, teamID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []TeamMember
|
|
for rows.Next() {
|
|
var i TeamMember
|
|
if err := rows.Scan(
|
|
&i.TeamMemberID,
|
|
&i.TeamID,
|
|
&i.UserID,
|
|
&i.Addeddate,
|
|
&i.RoleCode,
|
|
); 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 updateTeamMemberRole = `-- name: UpdateTeamMemberRole :one
|
|
UPDATE team_member SET role_code = $3 WHERE user_id = $2 AND team_id = $1
|
|
RETURNING team_member_id, team_id, user_id, addeddate, role_code
|
|
`
|
|
|
|
type UpdateTeamMemberRoleParams struct {
|
|
TeamID uuid.UUID `json:"team_id"`
|
|
UserID uuid.UUID `json:"user_id"`
|
|
RoleCode string `json:"role_code"`
|
|
}
|
|
|
|
func (q *Queries) UpdateTeamMemberRole(ctx context.Context, arg UpdateTeamMemberRoleParams) (TeamMember, error) {
|
|
row := q.db.QueryRowContext(ctx, updateTeamMemberRole, arg.TeamID, arg.UserID, arg.RoleCode)
|
|
var i TeamMember
|
|
err := row.Scan(
|
|
&i.TeamMemberID,
|
|
&i.TeamID,
|
|
&i.UserID,
|
|
&i.Addeddate,
|
|
&i.RoleCode,
|
|
)
|
|
return i, err
|
|
}
|