Skip to content

[WIP] Add story and character API integration in Flutter app#8

Merged
IfeyChan702 merged 1 commit into
mainfrom
copilot/add-story-character-api
Feb 12, 2026
Merged

[WIP] Add story and character API integration in Flutter app#8
IfeyChan702 merged 1 commit into
mainfrom
copilot/add-story-character-api

Conversation

Copilot AI commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Implementation Plan for Story & Character Features

  • Add image_picker dependency to pubspec.yaml
  • Create story_model.dart with JSON serialization
  • Create character_model.dart with JSON serialization
  • Update constants.dart with Story and Character API endpoints
  • Update api_service.dart with Story and Character API methods
  • Create story_card.dart widget
  • Create stories_screen.dart (list view)
  • Create story_detail_screen.dart (detail view)
  • Create generate_story_screen.dart (camera + AI generation)
  • Create characters_screen.dart (character list)
  • Create add_character_screen.dart (add/edit character)
  • Update home_screen.dart to add Stories tab (5 tabs total)
  • Update README.md with new features
  • Run build_runner to generate model code
  • Test the implementation
Original prompt

背景

后端 Spring Boot 已经完整实现了「拍照识别物品 → AI生成英语故事」的核心功能链路:

  1. DeepseekApiClient.analyzeImage() - 调用 Vision API 识别图片中的物品
  2. StoryServiceImpl.generateStory() - 基于识别出的物品和角色生成英语故事
  3. StoryController - REST API 端点 (/api/story/*)
  4. CharacterController - 角色管理端点 (/api/character/*)

但当前 main 分支的 Flutter 前端代码 完全缺少 Story/Character/拍照识别功能。api_service.dart 只有 Note、RAG、Review 的 API 调用,没有任何 story/character 方法。

后端 API 详情

GenerateStoryRequest (后端 DTO)

public class GenerateStoryRequest {
    @NotBlank(message = "图片不能为空")
    private String image;          // 图片 Base64 编码或 URL
    private String imageType = "base64";  // "base64" 或 "url"
    @NotNull(message = "主角ID不能为空")
    private Long characterId;      // 主角 ID
    private String title;          // 故事标题(可选)
}

Story Controller 端点 (/api/story)

  • POST /api/story/generate - 生成故事(接收 GenerateStoryRequest,包含图片和角色ID)
  • GET /api/story/list - 获取故事列表(支持 characterId、isFavorite 过滤)
  • GET /api/story/{id} - 获取故事详情
  • PUT /api/story/{id} - 更新故事
  • DELETE /api/story/{id} - 删除故事
  • POST /api/story/{id}/favorite - 收藏故事
  • DELETE /api/story/{id}/favorite - 取消收藏
  • POST /api/story/{id}/share - 分享故事
  • GET /api/story/shared/{shareToken} - 查看分享的故事

Character Controller 端点 (/api/character)

后端有 CharacterController(在 ruoyi-admin/src/main/java/com/ruoyi/web/controller/story/ 下),提供:

  • POST /api/character/add - 添加角色
  • GET /api/character/list - 获取角色列表
  • GET /api/character/{id} - 获取角色详情
  • PUT /api/character/{id} - 更新角色
  • DELETE /api/character/{id} - 删除角色

Search Controller 端点 (/api/search)

  • POST /api/search/stories - 搜索故事
  • POST /api/search/characters - 搜索角色
  • POST /api/search/all - 全局搜索

后端认证方式

JWT Bearer Token,所有 API 请求需要在 Header 中带 Authorization: Bearer {token}

后端响应格式 (RuoYi 风格)

// 成功
{"code": 200, "msg": "操作成功", "data": {...}}
// 列表(分页)
{"code": 200, "total": 10, "rows": [...]}
// 错误
{"code": 500, "msg": "错误信息"}

当前 Flutter 项目结构 (main 分支)

flutter_app/
├── pubspec.yaml                    # 已有依赖:dio, provider, image_picker等
├── lib/
│   ├── main.dart                   # 入口
│   ├── config/
│   │   └── app_constants.dart      # 旧的常量(需要保留)
│   ├── models/
│   │   ├── note_model.dart         # 笔记模型
│   │   ├── review_record_model.dart # 复习记录模型
│   │   └── rag_response_model.dart # RAG 响应模型
│   ├── services/
│   │   ├── api_service.dart        # API 服务(只有 Note/RAG/Review,缺少 Story/Character)
│   │   ├── auth_service.dart       # 认证服务
│   │   └── storage_service.dart    # 存储服务
│   ├── screens/
│   │   ├── login_screen.dart
│   │   ├── home_screen.dart        # 底部导航(只有 Notes/Search/Review/Profile 4个tab)
│   │   ├── notes_list_screen.dart
│   │   ├── note_detail_screen.dart
│   │   ├── add_note_screen.dart
│   │   ├── rag_search_screen.dart
│   │   ├── review_screen.dart
│   │   └── profile_screen.dart
│   ├── widgets/
│   │   ├── note_card.dart
│   │   ├── rag_result_card.dart
│   │   └── review_item_card.dart
│   └── utils/
│       ├── constants.dart          # API 端点常量(缺少 Story/Character 端点)
│       ├── validators.dart
│       └── helpers.dart
├── web/                            # Web 平台(已存在)
├── test/                           # 测试目录(已存在)
└── README.md

需要完成的具体任务

1. 添加 image_picker 依赖到 pubspec.yaml

在 dependencies 中添加:

  image_picker: ^1.0.7

这个包用于从相机或相册选择图片。

2. 创建 Story Model (flutter_app/lib/models/story_model.dart)

字段对应后端 Story 实体:

  • int? id
  • int? userId
  • String? title
  • String? content
  • int? characterId
  • String? characterName
  • String? identifiedObjects - 识别出的物品(逗号分隔)
  • bool? isFavorite
  • String? shareToken
  • String? status
  • String? createdAt
  • String? updatedAt

需要 fromJsontoJson 方法。

3. 创建 Character Model (flutter_app/lib/models/character_model.dart)

字段对应后端 StoryCharacter 实体:

  • int? id
  • int? userId
  • String name
  • String? nameEn
  • String? description
  • String? personality
  • String? background
  • String? role
  • String? avatarUrl
  • String? createdAt
  • String? updatedAt

需要 fromJsontoJson 方法。

4. 更新 flutter_app/lib/utils/constants.dart

AppConstants 类中添加 Story 和 Character 相关端点:

// Story API Endpoints
static const String storyGenerateEndpoint = '$apiPrefix/story/generate';
static const String storyListEndpoint = '$apiPrefix/story/list';
static const String storyGetEndpoint = '$apiPrefix/story';    // /{id}
static const String storyUpdateEndpoint = '$apiPrefix/story';  // /{id}
static const String storyDeleteEndpoint = '$apiPrefix/story';  // /{id}
static const String storyFavoriteEndpoint = '$apiPrefix/story'; // /{id}/favorite

// Character API Endpoints
static const String characterAddEndpoint = '$apiPrefix/character/add';
static const String characterListEndpoint = '$apiPrefix/character/list';
static const String characterGetEndpoint = '$apiPrefix/character';   // /{id}
static const String characterUpdateEndpoint = '$apiPrefix/character'; // /{id}
static const...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

@IfeyChan702
IfeyChan702 marked this pull request as ready for review February 12, 2026 09:21
@IfeyChan702
IfeyChan702 merged commit 89e17dc into main Feb 12, 2026
1 check failed
Copilot AI requested a review from IfeyChan702 February 12, 2026 09:21
Copilot stopped work on behalf of IfeyChan702 due to an error February 12, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants