Ejemplo n.º 1
0
func (r *ChannelRepository) CreateChannelWithName(
	tx *pg.Tx,
	clientID,
	channelID uuid.UUID,
	channelName string,
	rootThreadID uuid.UUID,
	owners []uuid.UUID,
) error {
	if tx == nil {
		return ErrWantTx
	}
	_, err := tx.Exec(`INSERT INTO channels (
            channel_id,
			ext_id,
            client_id,
            owners,
            root_thread_id,
            created_at,
            updated_at
        ) VALUES ($1, $2, $3, $4, $5, $6, $7)`,
		channelID,
		utils.HashText(channelName),
		clientID,
		utils.UUIDSFrom(owners),
		rootThreadID,
		time.Now(),
		time.Now(),
	)
	return err
}
Ejemplo n.º 2
0
// FindThreadByName find a thread by name
func (r *ThreadRepository) FindThreadByName(
	clientID,
	channelID uuid.UUID,
	name string,
) (hey.Thread, error) {
	thread := thread{}

	err := r.db.QueryRow(`
			SELECT 
				thread_id,
				client_id, 
				channel_id,
				owners,
				related_event_id,
				parent_thread_id
			FROM threads
			WHERE client_id = $1 AND channel_id = $2 AND ext_id = $3
		`, clientID, channelID, utils.HashText(name)).Scan(
		&thread.threadID,
		&thread.clientID,
		&thread.channelID,
		&thread.owners,
		&thread.relatedEventID,
		&thread.parentThreadID,
	)
	return &thread, err
}
Ejemplo n.º 3
0
func (r *ChannelRepository) FindChannelByName(
	clientID uuid.UUID,
	channelName string,
) (hey.Channel, error) {
	channel := channel{}
	sql := `SELECT 
			channel_id,
			client_id,
			owners,
			root_thread_id,
			created_at,
			updated_at
		FROM channels
		WHERE client_id = $1 AND ext_id = $2`

	err := r.db.QueryRow(
		sql,
		clientID,
		utils.HashText(channelName),
	).Scan(
		&channel.channelID,
		&channel.clientID,
		&channel.owners,
		&channel.rootThreadID,
		&channel.createdAt,
		&channel.updatedAt,
	)

	return channel, err
}
Ejemplo n.º 4
0
func (r *ThreadRepository) CreateThreadWithName(
	tx *pg.Tx,
	clientID,
	threadID uuid.UUID,
	threadName string,
	channelID,
	relatedEventID,
	parentThreadID uuid.UUID,
	owners []uuid.UUID,
) error {
	_, err := tx.Exec(`INSERT INTO threads (
            thread_id,
            client_id,
            channel_id,

			ext_id,

            owners,

            related_event_id,
            parent_thread_id,

            created_at,
            updated_at
        ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
		threadID,
		clientID,
		channelID,
		utils.HashText(threadName),
		(&utils.UUIDS{}).FromArray(owners),
		relatedEventID,
		parentThreadID,
		time.Now(),
		time.Now(),
	)

	return err
}