this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Add delete endpoint to ircLink

This endpoint is unauthenticated, as are all endpoints right now. This should
be fixed before we go live.

+113
+21
internal/assets/openapi.json
··· 94 94 "description": "Server Error" 95 95 } 96 96 } 97 + }, 98 + "delete": { 99 + "summary": "Delete an IRC link", 100 + "parameters": [ 101 + { 102 + "name": "id", 103 + "in": "query", 104 + "required": true, 105 + "schema": { 106 + "type": "integer" 107 + } 108 + } 109 + ], 110 + "responses": { 111 + "200": { 112 + "description": "Link deleted successfully" 113 + }, 114 + "404": { 115 + "description": "Link not found" 116 + } 117 + } 97 118 } 98 119 }, 99 120 "/ogpreview.cgi": {
+11
internal/data/gorm_store.go
··· 132 132 return link.ID, err 133 133 } 134 134 135 + func (s *GormStore) DeleteIRCLink(ctx context.Context, id int) error { 136 + result := s.db.WithContext(ctx).Delete(&IRCLink{}, id) 137 + if result.Error != nil { 138 + return result.Error 139 + } 140 + if result.RowsAffected == 0 { 141 + return fmt.Errorf("link not found") 142 + } 143 + return nil 144 + } 145 + 135 146 func (s *GormStore) InsertQuote(ctx context.Context, quoteText, author string) error { 136 147 quote := Quote{ 137 148 Quote: quoteText,
+1
internal/data/store.go
··· 74 74 GetIRCLinkURL(ctx context.Context, id int) (string, error) 75 75 IncrementClicks(ctx context.Context, id int) error 76 76 InsertIRCLink(ctx context.Context, user, title, url, contentType string) (int, error) 77 + DeleteIRCLink(ctx context.Context, id int) error 77 78 InsertQuote(ctx context.Context, quote, author string) error 78 79 GetRandomQuote(ctx context.Context) (*Quote, error) 79 80
+39
internal/handler/irclink.go
··· 20 20 user := r.URL.Query().Get("user") 21 21 url := r.URL.Query().Get("url") 22 22 23 + if r.Method == http.MethodDelete { 24 + idStr := r.URL.Query().Get("id") 25 + if idStr == "" { 26 + // Try path if valid (though usually query param here) 27 + // But wait, the router handles /irclink/ so path info might be the ID 28 + // e.g. DELETE /irclink/123 29 + segments := strings.Split(strings.Trim(r.URL.Path, "/"), "/") 30 + if len(segments) > 1 { 31 + idStr = segments[len(segments)-1] 32 + } 33 + } 34 + 35 + if idStr == "" { 36 + http.Error(w, "Missing ID", http.StatusBadRequest) 37 + return 38 + } 39 + 40 + id, err := strconv.Atoi(idStr) 41 + if err != nil { 42 + http.Error(w, "Invalid ID", http.StatusBadRequest) 43 + return 44 + } 45 + 46 + err = h.Store.DeleteIRCLink(ctx, id) 47 + if err != nil { 48 + if strings.Contains(err.Error(), "not found") { 49 + http.Error(w, "Link not found", http.StatusNotFound) 50 + } else { 51 + log.Printf("DeleteIRCLink error: %v", err) 52 + http.Error(w, "Internal Server Error", http.StatusInternalServerError) 53 + } 54 + return 55 + } 56 + 57 + w.WriteHeader(http.StatusOK) 58 + fmt.Fprintf(w, "Link %d deleted", id) 59 + return 60 + } 61 + 23 62 if user != "" && url != "" { 24 63 // Handle link posting 25 64 // Fetch title (simple impl)
+27
tests/api_test.sh
··· 86 86 FAIL=1 87 87 fi 88 88 89 + # 7. Delete Link Test (Create -> Delete -> Verify) 90 + echo -n "Testing DELETE /irclink/ flow... " 91 + # Create a link first 92 + CREATE_OUT=$(curl -s "$BASE_URL/irclink/?user=testdel&url=http://delete-test.com&source=irc") 93 + # Check if we got an ID (numeric) 94 + if [[ "$CREATE_OUT" =~ ^[0-9]+$ ]]; then 95 + DEL_ID=$CREATE_OUT 96 + # Delete it 97 + DEL_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE "$BASE_URL/irclink/?id=$DEL_ID") 98 + if [ "$DEL_STATUS" == "200" ]; then 99 + # Verify it's gone 100 + GONE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/irclink/?id=$DEL_ID") 101 + if [ "$GONE_STATUS" == "404" ]; then 102 + echo "OK" 103 + else 104 + echo "FAIL (Expected 404 after delete, got $GONE_STATUS)" 105 + FAIL=1 106 + fi 107 + else 108 + echo "FAIL (Delete request failed with $DEL_STATUS)" 109 + FAIL=1 110 + fi 111 + else 112 + echo "FAIL (Could not create test link: $CREATE_OUT)" 113 + FAIL=1 114 + fi 115 + 89 116 if [ $FAIL -eq 0 ]; then 90 117 echo "All tests passed!" 91 118 exit 0
+14
tests/delete_link.sh
··· 1 + #!/bin/bash 2 + # Script to delete an IRC Link 3 + # Usage: ./delete_link.sh <id> 4 + 5 + ID=$1 6 + BASE_URL="http://localhost:8080" 7 + 8 + if [ -z "$ID" ]; then 9 + echo "Usage: $0 <id>" 10 + exit 1 11 + fi 12 + 13 + curl -v -X DELETE "$BASE_URL/irclink/?id=$ID" 14 + echo ""