feat: create network, and manage members, invitations (#74)
This commit was merged in pull request #74.
This commit is contained in:
@@ -87,9 +87,10 @@ type MembersRequest struct {
|
||||
}
|
||||
|
||||
type Invitation struct {
|
||||
NetworkId string `json:"network_id"`
|
||||
Email string `json:"email"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
NetworkId string `json:"network_id"`
|
||||
NetworkName string `json:"network_name"`
|
||||
Email string `json:"email"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type AcceptInvitationRequest struct {
|
||||
@@ -527,9 +528,10 @@ func (h *Handler) ListInvitationsForNetwork(w http.ResponseWriter, r *http.Reque
|
||||
resp := make([]Invitation, 0, len(invitations))
|
||||
for _, inv := range invitations {
|
||||
resp = append(resp, Invitation{
|
||||
NetworkId: inv.NetworkID,
|
||||
Email: inv.Email,
|
||||
CreatedAt: inv.CreatedAt,
|
||||
NetworkId: inv.NetworkID,
|
||||
NetworkName: inv.NetworkName,
|
||||
Email: inv.Email,
|
||||
CreatedAt: inv.CreatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -555,9 +557,10 @@ func (h *Handler) ListMyInvitations(w http.ResponseWriter, r *http.Request) {
|
||||
resp := make([]Invitation, 0, len(invitations))
|
||||
for _, inv := range invitations {
|
||||
resp = append(resp, Invitation{
|
||||
NetworkId: inv.NetworkID,
|
||||
Email: inv.Email,
|
||||
CreatedAt: inv.CreatedAt,
|
||||
NetworkId: inv.NetworkID,
|
||||
NetworkName: inv.NetworkName,
|
||||
Email: inv.Email,
|
||||
CreatedAt: inv.CreatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ type Network struct {
|
||||
}
|
||||
|
||||
type Invitation struct {
|
||||
NetworkID string
|
||||
Email string
|
||||
CreatedAt time.Time
|
||||
NetworkID string
|
||||
NetworkName string
|
||||
Email string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
@@ -215,7 +215,10 @@ func (r *repositoryImpl) createInvitation(ctx context.Context, networkID, email
|
||||
|
||||
func (r *repositoryImpl) getInvitationsByEmail(ctx context.Context, email string) ([]*Invitation, error) {
|
||||
rows, err := r.pool.Query(ctx,
|
||||
`SELECT network_id, email, created_at FROM network_invitations WHERE email = $1`,
|
||||
`SELECT ni.network_id, n.name, ni.email, ni.created_at
|
||||
FROM network_invitations ni
|
||||
JOIN networks n ON n.id = ni.network_id
|
||||
WHERE ni.email = $1`,
|
||||
email,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -226,7 +229,7 @@ func (r *repositoryImpl) getInvitationsByEmail(ctx context.Context, email string
|
||||
var invitations []*Invitation
|
||||
for rows.Next() {
|
||||
var inv Invitation
|
||||
if err := rows.Scan(&inv.NetworkID, &inv.Email, &inv.CreatedAt); err != nil {
|
||||
if err := rows.Scan(&inv.NetworkID, &inv.NetworkName, &inv.Email, &inv.CreatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
invitations = append(invitations, &inv)
|
||||
@@ -236,7 +239,10 @@ func (r *repositoryImpl) getInvitationsByEmail(ctx context.Context, email string
|
||||
|
||||
func (r *repositoryImpl) getInvitationsByNetwork(ctx context.Context, networkID string) ([]*Invitation, error) {
|
||||
rows, err := r.pool.Query(ctx,
|
||||
`SELECT network_id, email, created_at FROM network_invitations WHERE network_id = $1`,
|
||||
`SELECT ni.network_id, n.name, ni.email, ni.created_at
|
||||
FROM network_invitations ni
|
||||
JOIN networks n ON n.id = ni.network_id
|
||||
WHERE ni.network_id = $1`,
|
||||
networkID,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -247,7 +253,7 @@ func (r *repositoryImpl) getInvitationsByNetwork(ctx context.Context, networkID
|
||||
var invitations []*Invitation
|
||||
for rows.Next() {
|
||||
var inv Invitation
|
||||
if err := rows.Scan(&inv.NetworkID, &inv.Email, &inv.CreatedAt); err != nil {
|
||||
if err := rows.Scan(&inv.NetworkID, &inv.NetworkName, &inv.Email, &inv.CreatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
invitations = append(invitations, &inv)
|
||||
|
||||
Reference in New Issue
Block a user