summaryrefslogtreecommitdiff
path: root/database/dns.go
diff options
context:
space:
mode:
authorElizabeth <elizabeth@simponic.xyz>2024-04-04 15:08:50 -0600
committerElizabeth <elizabeth@simponic.xyz>2024-04-04 15:08:50 -0600
commitd9d39a01f24922b6de6ad65ceebcb3da501d2790 (patch)
treea743b2af4b8f886a89eecc4b78eb3b97feb7d0e8 /database/dns.go
parentf38e8719c2a8537fe9b64ed8ceca45858a58e498 (diff)
downloadhatecomputers.club-d9d39a01f24922b6de6ad65ceebcb3da501d2790.tar.gz
hatecomputers.club-d9d39a01f24922b6de6ad65ceebcb3da501d2790.zip
dns api tests
Diffstat (limited to 'database/dns.go')
-rw-r--r--database/dns.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/database/dns.go b/database/dns.go
index fc01347..7851ab4 100644
--- a/database/dns.go
+++ b/database/dns.go
@@ -9,6 +9,12 @@ import (
"time"
)
+type DomainOwner struct {
+ UserID string `json:"user_id"`
+ Domain string `json:"domain"`
+ CreatedAt time.Time `json:"created_at"`
+}
+
type DNSRecord struct {
ID string `json:"id"`
UserID string `json:"user_id"`
@@ -57,7 +63,10 @@ func GetUserDNSRecords(db *sql.DB, userID string) ([]DNSRecord, error) {
func SaveDNSRecord(db *sql.DB, record *DNSRecord) (*DNSRecord, error) {
log.Println("saving dns record", record.ID)
- record.CreatedAt = time.Now()
+ if (record.CreatedAt == time.Time{}) {
+ record.CreatedAt = time.Now()
+ }
+
_, err := db.Exec("INSERT OR REPLACE INTO dns_records (id, user_id, name, type, content, ttl, internal, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", record.ID, record.UserID, record.Name, record.Type, record.Content, record.TTL, record.Internal, record.CreatedAt)
if err != nil {
@@ -137,3 +146,15 @@ func FindDNSRecords(dbConn *sql.DB, name string, qtype string) ([]DNSRecord, err
return records, nil
}
+
+func SaveDomainOwner(db *sql.DB, domainOwner *DomainOwner) (*DomainOwner, error) {
+ log.Println("saving domain owner", domainOwner.Domain)
+
+ domainOwner.CreatedAt = time.Now()
+ _, err := db.Exec("INSERT OR REPLACE INTO domain_owners (user_id, domain, created_at) VALUES (?, ?, ?)", domainOwner.UserID, domainOwner.Domain, domainOwner.CreatedAt)
+
+ if err != nil {
+ return nil, err
+ }
+ return domainOwner, nil
+}