Skip to content

[WIP] Add new endpoints for managing stories#9

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

[WIP] Add new endpoints for managing stories#9
IfeyChan702 merged 1 commit into
mainfrom
copilot/add-new-story-endpoints

Conversation

Copilot AI commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Flutter Story and Character Feature Implementation

  • Update constants.dart with Story, Character, and Search API endpoints
  • Add new models (story_model.dart, character_model.dart, generate_story_request_model.dart, generate_story_response_model.dart)
  • Update api_service.dart with Story, Character, and Search API methods
  • Add story_card.dart widget
  • Add character_card.dart widget
  • Add stories_screen.dart for story list
  • Add story_detail_screen.dart for story details
  • Add generate_story_screen.dart for story generation
  • Add characters_screen.dart for character management
  • Add add_character_screen.dart for adding/editing characters
  • Update home_screen.dart to add Stories tab in navigation
  • Update pubspec.yaml with image_picker dependency
  • Run Flutter pub get to install dependencies
  • Test build and verify no compilation errors
Original prompt

背景

当前 main 分支的 Spring Boot 后端已经有完整的 Story(故事)和 Character(主角)API 实现,包括:

后端已有的 Story API (/api/story/)

  • POST /api/story/generate - 通过图片生成故事(上传图片 base64 + 主角ID)
  • GET /api/story/list - 获取故事列表(支持 characterId 和 isFavorite 筛选)
  • GET /api/story/{id} - 获取故事详情
  • PUT /api/story/{id} - 更新故事(title, content)
  • 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 API (/api/character/)

  • CharacterController.java: 5 endpoints for character management (CRUD)

后端已有的 Search API (/api/search/)

  • POST /api/search/stories - 搜索故事
  • POST /api/search/characters - 搜索主角
  • POST /api/search/all - 全局搜索(故事+主角)

后端故事生成流程

  • GenerateStoryRequest: 包含 image (base64/url), imageType, characterId, title
  • GenerateStoryResponse: 包含 success, story, identifiedObjects, errorMessage, processingTime
  • 使用 DeepseekApiClient 的 analyzeImage() 识别图片物品,然后用 generateStoryFromObjects() 生成故事

需要做的事情

flutter_app/ 目录下更新 Flutter 代码,添加 Story 和 Character 相关的完整前端实现。不要删除或修改现有的 Note、RAG、Review 等功能代码,只做增量添加。

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

添加以下 API endpoint 常量:

// Story 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
static const String storyShareEndpoint = '$apiPrefix/story'; // /{id}/share
static const String storySharedEndpoint = '$apiPrefix/story/shared'; // /{shareToken}

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

// Search endpoints
static const String searchStoriesEndpoint = '$apiPrefix/search/stories';
static const String searchCharactersEndpoint = '$apiPrefix/search/characters';
static const String searchAllEndpoint = '$apiPrefix/search/all';

2. 添加新的 Models

flutter_app/lib/models/ 下添加:

story_model.dart - 故事数据模型

class StoryModel {
  final int? id;
  final int? userId;
  final int? characterId;
  final String? title;
  final String? content;
  final String? identifiedObjects; // 识别出的物品JSON
  final bool? isFavorite;
  final String? shareToken;
  final String? createdAt;
  final String? updatedAt;
  // fromJson, toJson
}

character_model.dart - 主角数据模型

class CharacterModel {
  final int? id;
  final int? userId;
  final String name;
  final String? description;
  final String? avatar;
  final String? createdAt;
  final String? updatedAt;
  // fromJson, toJson
}

generate_story_request_model.dart - 生成故事请求模型

class GenerateStoryRequestModel {
  final String image; // base64 或 URL
  final String imageType; // "base64" 或 "url"
  final int characterId;
  final String? title;
  // toJson
}

generate_story_response_model.dart - 生成故事响应模型

class GenerateStoryResponseModel {
  final bool success;
  final StoryModel? story;
  final List<String>? identifiedObjects;
  final String? errorMessage;
  final int? processingTime;
  // fromJson
}

3. 更新 flutter_app/lib/services/api_service.dart

在 ApiService 类中添加以下方法(不要修改现有方法):

// ==================== Story APIs ====================
Future<GenerateStoryResponseModel> generateStory(GenerateStoryRequestModel request);
Future<List<StoryModel>> getStories({int? characterId, bool? isFavorite, int pageNum = 1, int pageSize = 10});
Future<StoryModel> getStoryById(int id);
Future<void> updateStory(int id, {String? title, String? content});
Future<bool> deleteStory(int id);
Future<void> favoriteStory(int id);
Future<void> unfavoriteStory(int id);
Future<Map<String, String>> shareStory(int id);

// ==================== Character APIs ====================
Future<List<CharacterModel>> getCharacters({int pageNum = 1, int pageSize = 10});
Future<CharacterModel> createCharacter(String name, {String? description, String? avatar});
Future<CharacterModel> getCharacterById(int id);
Future<void> updateCharacter(int id, {String? name, String? description, String? avatar});
Future<bool> deleteCharacter(int id);

// ==================== Search APIs ====================
Future<List<StoryModel>> searchStories(String keyword, {double? threshold, int? maxResults});
Future<List<CharacterModel>> searchCharacters(String keyword);
Future<Map<String, dynamic>> searchAll(String ...

</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:48
@IfeyChan702
IfeyChan702 merged commit 883ac87 into main Feb 12, 2026
1 check failed
Copilot AI requested a review from IfeyChan702 February 12, 2026 09:48
Copilot stopped work on behalf of IfeyChan702 due to an error February 12, 2026 09:48
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