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

Add Sample Api #12

Merged
merged 6 commits into from
Jul 28, 2024
Merged

Add Sample Api #12

merged 6 commits into from
Jul 28, 2024

Conversation

miyasama
Copy link
Contributor

@miyasama miyasama commented Jul 19, 2024

概要

サンプルとして、商品の検索APIと、ID指定の1件取得APIを追加しました。

詳細

以下の2つのサンプル相当のものを実装しました。

o LidoProductListAction.java
https://github.com/lastaflute/lastaflute-example-harbor/blob/master/src/main/java/org/docksidestage/app/web/lido/product/LidoProductListAction.java

o LidoProductDetailAction.java
https://github.com/lastaflute/lastaflute-example-harbor/blob/master/src/main/java/org/docksidestage/app/web/lido/product/LidoProductDetailAction.java

動作確認方法

以下のREADMEに記載の方法で、起動とSwaggerUIからの確認ができます。

https://github.com/dbflute-example/dbflute-example-on-quarkus/blob/master/README.md?plain=1#L38-L40

@miyasama miyasama marked this pull request as ready for review July 19, 2024 12:44
@miyasama miyasama requested a review from jflute July 19, 2024 12:46
Copy link
Contributor

@jflute jflute left a comment

Choose a reason for hiding this comment

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

技術的な質問だけー


/** paging data for current page */
@NotNull
public final List<@Valid BEAN> rows;
Copy link
Contributor

Choose a reason for hiding this comment

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

純粋な技術の質問。LastaFluteのexampleだと、@Validは変数自体に付けてるけど、Genericの方に付けても挙動って同じってことなのかな?

LastaFluteのexample:

@Valid
public final List<BEAN> rows;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jflute
試してみたところ、以下のどちらも同じ結果でした。

@Valid
public final List<BEAN> rows;
public final List<@Valid BEAN> rows;

ので、Lastaに合わせるように修正しました。
f9c2071

あと、Contollerのメソッドの戻り値にも @Validを付けないと、
レスポンスがバリデーションされなかったので、そちらも合わせて追加しました。

public @Valid SearchPagingResult<ProductRowResult> search(@BeanParam @Valid ProductSearchBody form) {

Copy link
Contributor

Choose a reason for hiding this comment

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

なるほど、LastaのExampleに合わせるで嬉しい、ありがとうー!
Genericにアノテーション付けられるって知らない人も多いだろうから、
挙動が同じであれば、変数自体に付けるほうが馴染みやすいかなとも思う。

一方で、レスポンスのBeanにもバリデーションできるんだ!?
こうできると便利って思ってるの自分だけかもしれない...とか思ってたので、
Quarkusも採用しているのは嬉しいね。

ただ、@Validを付けないとチェックされないってことで強制力は低めではあるんだの。
(Lastaはデフォルトで強制チェックなので)

* @author miyasama
*/
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class ProductRowResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

publicフィールドスタイルなのは、Quarkusのスタンダードなのかな?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jflute
Quarkusの公式サイトの実装例とかを見ている感じだと、publicフィールドスタイルです。

Quarkusを使っている現場のスタンダードなのかは不明ですが、
うちのチームだとpublicフィールドスタイルにしています。

Copy link
Contributor

Choose a reason for hiding this comment

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

publicフィールドスタイルはSeasar文化みたいな認識の人もよくいるんだけど、
んなこたないよってことだね笑、よかったよかった(^^

Copy link
Contributor

@jflute jflute left a comment

Choose a reason for hiding this comment

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

あぷるーゔ、thanks

@miyasama miyasama merged commit 7ee1638 into master Jul 28, 2024
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.

None yet

2 participants