Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fields to Create Connection Modal and Integrate Backend Workflow #2179

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ type ConnectionCodes struct {
ConnectionString string `json:"connection_string"`
IsUsed bool `json:"is_used"`
DateCreated *time.Time `json:"date_created"`
Pubkey string `json:"pubkey"`
aliraza556 marked this conversation as resolved.
Show resolved Hide resolved
RouteHint string `json:"route_hint"`
SatsAmount int64 `json:"sats_amount"`
}

type ConnectionCodesShort struct {
Expand Down
19 changes: 15 additions & 4 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,34 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque
body, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println("ReadAll Error", err)
w.WriteHeader(http.StatusBadRequest)
return
}
r.Body.Close()

err = json.Unmarshal(body, &codeBody)

if err != nil {
fmt.Println("Could not umarshal connection code body")
fmt.Println("Could not unmarshal connection code body")
w.WriteHeader(http.StatusNotAcceptable)
return
}

if codeBody.Pubkey != "" && codeBody.RouteHint == "" {
fmt.Println("route hint missing")
w.WriteHeader(http.StatusNotAcceptable)
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode("Route hint is required when pubkey is provided")
return
}

if codeBody.RouteHint != "" && codeBody.Pubkey == "" {
fmt.Println("pubkey missing missing")
w.WriteHeader(http.StatusNotAcceptable)
json.NewEncoder(w).Encode("pubkey is required when Route hint is provided")
return
}

if codeBody.SatsAmount == 0 {
aliraza556 marked this conversation as resolved.
Show resolved Hide resolved
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode("Sats amount must be greater than 0")
return
}

Expand All @@ -100,6 +108,9 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque
newCode := db.ConnectionCodes{
ConnectionString: code,
IsUsed: false,
Pubkey: codeBody.Pubkey,
RouteHint: codeBody.RouteHint,
SatsAmount: int64(codeBody.SatsAmount),
}
codeArr = append(codeArr, newCode)
}
Expand Down
5 changes: 4 additions & 1 deletion tribes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,8 @@ CREATE TABLE connectioncodes {
id SERIAL PRIMARY KEY,
connection_string TEXT,
is_used boolean,
date_created timestamptz
date_created timestamptz,
aliraza556 marked this conversation as resolved.
Show resolved Hide resolved
pubkey TEXT,
route_hint TEXT,
sats_amount bigint
}
Loading