-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
211 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
client/src/main/java/com/gdevxy/blog/client/google/model/CaptchaVerifyRequest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
component/src/main/java/com/gdevxy/blog/component/cookie/Cookies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.gdevxy.blog.component.cookie; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.Optional; | ||
|
||
import jakarta.ws.rs.core.NewCookie; | ||
|
||
import io.vertx.core.http.Cookie; | ||
import io.vertx.core.http.HttpServerRequest; | ||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class Cookies { | ||
|
||
private final String BLOG_POST_RATING_COOKIE_NAME = "gdevxy-bpr-%s"; | ||
|
||
public Optional<Cookie> findBlogPostRatingCookie(HttpServerRequest req, String id) { | ||
|
||
return req.cookies(BLOG_POST_RATING_COOKIE_NAME.formatted(id)).stream().findAny(); | ||
} | ||
|
||
public NewCookie createBlogPostRatingCookie(String id, String uuid) { | ||
|
||
return new NewCookie.Builder(BLOG_POST_RATING_COOKIE_NAME.formatted(id)) | ||
.secure(true) | ||
.httpOnly(true) | ||
.sameSite(NewCookie.SameSite.STRICT) | ||
.maxAge(Integer.MAX_VALUE) | ||
.expiry(Date.from(Instant.now().plusSeconds(Integer.MAX_VALUE))) | ||
.value(uuid) | ||
.path("/") | ||
.build(); | ||
} | ||
|
||
public NewCookie deleteBlogPostRatingCookie(String id) { | ||
|
||
return new NewCookie.Builder(BLOG_POST_RATING_COOKIE_NAME.formatted(id)) | ||
.secure(true) | ||
.httpOnly(true) | ||
.sameSite(NewCookie.SameSite.STRICT) | ||
.maxAge(Integer.MAX_VALUE) | ||
.expiry(Date.from(Instant.now().plusSeconds(Integer.MAX_VALUE))) | ||
.value("goodbye") | ||
.path("/") | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
service/src/main/java/com/gdevxy/blog/dao/blogpost/BlogPostRatingDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.gdevxy.blog.dao.blogpost; | ||
|
||
import java.util.UUID; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import com.gdevxy.blog.dao.DaoSupport; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.mutiny.pgclient.PgPool; | ||
import io.vertx.mutiny.sqlclient.Tuple; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@ApplicationScoped | ||
@RequiredArgsConstructor | ||
public class BlogPostRatingDao extends DaoSupport { | ||
|
||
private final PgPool sql; | ||
|
||
public Uni<Long> findRating(Integer id) { | ||
|
||
return as(sql.preparedQuery(""" | ||
select | ||
count(*) as rating | ||
from blog_post_rating | ||
where blog_post_id = $1 | ||
""") | ||
.execute(Tuple.of(id)), r -> r.getLong("rating")); | ||
} | ||
|
||
public Uni<String> thumbsUp(Integer blogId) { | ||
|
||
var uuid = UUID.randomUUID().toString(); | ||
|
||
return sql.preparedQuery(""" | ||
insert into blog_post_rating (blog_post_id, uuid) values ($1, $2) | ||
""").execute(Tuple.of(blogId, uuid)).map(i -> uuid); | ||
} | ||
|
||
public Uni<Void> thumbsDown(String uuid) { | ||
|
||
return sql.preparedQuery(""" | ||
delete from blog_post_rating where uuid = $1 | ||
""").execute(Tuple.of(uuid)).replaceWithVoid(); | ||
} | ||
|
||
} |
14 changes: 0 additions & 14 deletions
14
service/src/main/java/com/gdevxy/blog/dao/blogpostcomment/BlogPostCommentDao.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
service/src/main/java/com/gdevxy/blog/dao/blogpostcomment/BlogPostCommentEntity.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.