-
Notifications
You must be signed in to change notification settings - Fork 61
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
Conversation
@chia7712 PTAL! |
public interface Request { | ||
|
||
/** Indicates the object used in the request */ | ||
interface RequestObject {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不好意思,我不太確定這個介面的用途是什麼?
There was a problem hiding this comment.
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 來做驗證
There was a problem hiding this comment.
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
- primitive type
- Map optional collection
- 其他 Request
因此在我的想像中,PostRecord 應該也是繼承 Request 就好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我先合併這隻PR,後面接著微調,以免擋著太多
There was a problem hiding this comment.
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)))); |
There was a problem hiding this comment.
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,並且開好對應的議題
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix #974 Implement RecordHandler