Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
62 changes: 62 additions & 0 deletions delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"context"
"fmt"
"log"

"google.golang.org/api/calendar/v3"
)

func deleteCalendar() {
db, err := openDB(".gcalsync.db")
if err != nil {
log.Fatalf("Error opening database: %v", err)
}
defer db.Close()

fmt.Println("🚀 Starting calendar deletion...")

fmt.Print("📅 Enter calendar ID to delete: ")
var calendarID string
fmt.Scanln(&calendarID)

fmt.Print("⚠️ Are you sure you want to delete this calendar? (y/N): ")
var confirmation string
fmt.Scanln(&confirmation)

if confirmation != "y" && confirmation != "Y" {
fmt.Println("❌ Calendar deletion cancelled")
return
}
var count int
err = db.QueryRow("SELECT COUNT(*) FROM calendars WHERE calendar_id = ?", calendarID).Scan(&count)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this check before confirmation?

if err != nil {
log.Fatalf("Error checking if calendar exists: %v", err)
}
if count == 0 {
fmt.Printf("❌ Calendar %s does not exist\n", calendarID)
return
}

ctx := context.Background()
client := getClient(ctx, oauthConfig, db, "")
calendarService, err := calendar.New(client)
if err != nil {
log.Fatalf("Error creating calendar client: %v", err)
}

cleanupCalendar(calendarService, calendarID)

_, err = db.Exec(`DELETE FROM blocker_events WHERE calendar_id=?`, calendarID)
if err != nil {
log.Fatalf("Error deleting blocker events: %v", err)
}

_, err = db.Exec(`DELETE FROM calendars WHERE calendar_id=?`, calendarID)
if err != nil {
log.Fatalf("Error deleting calendar ID: %v", err)
}

fmt.Printf("✅ Calendar %s deleted successfully\n", calendarID)
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func main() {
cleanupCalendars()
case "list":
listCalendars()
case "delete":
deleteCalendar()
default:
fmt.Printf("Unknown command: %s\n", command)
os.Exit(1)
Expand Down