Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

astraea-974 Implement RecordHandler post request #1156

Merged
merged 5 commits into from
Nov 23, 2022

Conversation

g1geordie
Copy link
Contributor

fix #974 Implement RecordHandler

@g1geordie
Copy link
Contributor Author

@chia7712 PTAL!

public interface Request {

/** Indicates the object used in the request */
interface RequestObject {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不好意思,我不太確定這個介面的用途是什麼?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要想解決 之前提過的一個問題

在Request 中的field 是 generic 的 Object 的話 會拿不到他的Class
所以沒辦法做一些testing 上的驗證

像是以下

static class RecordPostRequest implements Request {
   List<PostRecord> records = List.of();
}

這裡直接在那些PostRecord上面加上這個interface 來做驗證

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不好意思,我最近記憶力有點薄弱,我講錯的話就請提醒我一下

現在的驗證是驗證一個「建構出來的物件」,因此 records 這個變數我們就是驗證它是否為 null 以及 它內涵的物件(而非generic type)是否有符合規範。

條列的地來說,一個 Request / Response 物件只能有三種 members

  1. primitive type
  2. Map optional collection
  3. 其他 Request

因此在我的想像中,PostRecord 應該也是繼承 Request 就好

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我先合併這隻PR,後面接著微調,以免擋著太多

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

瞭解
PostRecord 也是可以繼承 Request 的
只是原本定義的 Request 是user 會傳上來的 json 物件
所以才用別的interface 來代表是Request 中會使用到的其他物件

var keySerializer = SerDe.ofAlias(postRecord.keySerializer).serializer;
var valueSerializer = SerDe.ofAlias(postRecord.valueSerializer).serializer;
postRecord.key.ifPresent(
key -> builder.key(keySerializer.apply(topic, PostRequest.handle(key))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊簡單一點,就直接呼叫toString取代PostRequest.handle,然後留個TODO,描述說要處理只能傳入 number and string,並且開好對應的議題

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712 chia7712 merged commit 22e3ef9 into opensource4you:main Nov 23, 2022
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.

Replace gson with jackson
2 participants