feat: implement Iteration 1 — AI recipe recommendations
Backend:
- Add Groq LLM client (llama-3.3-70b) for recipe generation with JSON
retry strategy (retries only on parse errors, not API errors)
- Add Pexels client for parallel photo search per recipe
- Add saved_recipes table (migration 004) with JSONB fields
- Add GET /recommendations endpoint (profile-aware prompt building)
- Add POST/GET/GET{id}/DELETE /saved-recipes CRUD endpoints
- Wire gemini, pexels, recommendation, savedrecipe packages in main.go
Flutter:
- Add Recipe, SavedRecipe models with json_serializable
- Add RecipeService (getRecommendations, getSavedRecipes, save, delete)
- Add RecommendationsNotifier and SavedRecipesNotifier (Riverpod)
- Add RecommendationsScreen with skeleton loading and refresh FAB
- Add RecipeDetailScreen (SliverAppBar, nutrition tooltip, steps with timer)
- Add SavedRecipesScreen with Dismissible swipe-to-delete and empty state
- Update RecipesScreen to TabBar (Recommendations / Saved)
- Add /recipe-detail route outside ShellRoute (no bottom nav)
- Extend ApiClient with getList() and deleteVoid()
Project:
- Add CLAUDE.md with English-only rule for comments and commit messages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
77
backend/internal/pexels/client.go
Normal file
77
backend/internal/pexels/client.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package pexels
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
pexelsSearchURL = "https://api.pexels.com/v1/search"
|
||||
defaultPlaceholder = "https://images.pexels.com/photos/1640777/pexels-photo-1640777.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750"
|
||||
)
|
||||
|
||||
// PhotoSearcher can search for a photo by text query.
|
||||
type PhotoSearcher interface {
|
||||
SearchPhoto(ctx context.Context, query string) (string, error)
|
||||
}
|
||||
|
||||
// Client is an HTTP client for the Pexels Photos API.
|
||||
type Client struct {
|
||||
apiKey string
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
// NewClient creates a new Pexels client.
|
||||
func NewClient(apiKey string) *Client {
|
||||
return &Client{
|
||||
apiKey: apiKey,
|
||||
httpClient: &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// SearchPhoto searches for a landscape photo matching query.
|
||||
// Returns a default placeholder URL if no photo is found or on error.
|
||||
func (c *Client) SearchPhoto(ctx context.Context, query string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("query", query)
|
||||
params.Set("per_page", "1")
|
||||
params.Set("orientation", "landscape")
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, pexelsSearchURL+"?"+params.Encode(), nil)
|
||||
if err != nil {
|
||||
return defaultPlaceholder, fmt.Errorf("create request: %w", err)
|
||||
}
|
||||
req.Header.Set("Authorization", c.apiKey)
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return defaultPlaceholder, fmt.Errorf("send request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return defaultPlaceholder, fmt.Errorf("pexels API error: status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
var result struct {
|
||||
Photos []struct {
|
||||
Src struct {
|
||||
Medium string `json:"medium"`
|
||||
} `json:"src"`
|
||||
} `json:"photos"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return defaultPlaceholder, fmt.Errorf("decode response: %w", err)
|
||||
}
|
||||
|
||||
if len(result.Photos) == 0 || result.Photos[0].Src.Medium == "" {
|
||||
return defaultPlaceholder, nil
|
||||
}
|
||||
return result.Photos[0].Src.Medium, nil
|
||||
}
|
||||
Reference in New Issue
Block a user