> For the complete documentation index, see [llms.txt](https://toshio.gitbook.io/icp-rust-cdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://toshio.gitbook.io/icp-rust-cdk/samples/diary.md).

# Diary

Rust CDKの学習を兼ねて簡単なDiary Dappをつくってみることにします。

ユーザごとにDiaryを一つ持つことができ、日付をキーとして、タイトルとコンテンツを文字列として持つシンプルな構造を考えます。

## リポジトリ

<https://github.com/toshio/icptest/tree/master/samples/diary>

## Backend

### Backend I/F

ユーザに関する情報と、日記の保存/読み込みを行う基本的なI/Fを考えます。

| 関数                   | 区分     | 概要       |
| -------------------- | ------ | -------- |
| set(UserConfig)      | update | ユーザ情報の設定 |
| get(Principal)       | query  | ユーザ情報の取得 |
| save(Date)           | update | 日記の保存    |
| delete(Date)         | update | 日記の削除    |
| load(Principal,Date) | query  | 日記の取得    |
| list(Principal)      | query  | 日記一覧の取得  |

日記の更新は本人のみ可能ですが、日記に公開/非公開の設定を行えるようにして、他人の日記の参照は、引数にはPrincipalを渡すことで可能にします。

### Build & Deploy

```bash
$ dfx start --background --clean
$ dfx deploy backend
```

## Frontend

★TODO★

### Generate I/F

Frontendから利用できるようにソースファイルを生成します。

```bash
$ dfx generate backend
Generating type declarations for canister backend:
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
  src/declarations/backend/backend.did.d.ts
  src/declarations/backend/backend.did.js
  src/backend/backend.did
```

### Generate Frontend

```bash
$ cd src
$ $ npx create-next-app@latest
✔ What is your project named? … frontend
✔ Would you like to use TypeScript? … Yes
✔ Would you like to use ESLint? … Yes
✔ Would you like to use Tailwind CSS? … No
✔ Would you like to use `src/` directory? … Yes
✔ Would you like to use App Router? (recommended) … No
✔ Would you like to customize the default import alias? … No
︙
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://toshio.gitbook.io/icp-rust-cdk/samples/diary.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
