feat: implement livestream post functionality and update site theme assets
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class CreateLivestreamPost {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Class.forName("oracle.jdbc.OracleDriver");
|
||||
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/sisvietnam", "sisvietnam", "sisvietnam");
|
||||
|
||||
// 1. Check if tag 'livestream' exists, if not create it
|
||||
long tagId = -1;
|
||||
PreparedStatement checkTag = conn.prepareStatement("SELECT id FROM sis_tag WHERE slug = 'livestream'");
|
||||
ResultSet rsTag = checkTag.executeQuery();
|
||||
if (rsTag.next()) {
|
||||
tagId = rsTag.getLong("id");
|
||||
} else {
|
||||
PreparedStatement insertTag = conn.prepareStatement(
|
||||
"INSERT INTO sis_tag (id, name, slug, created_by) VALUES (sequence_generator.NEXTVAL, ?, ?, 'system')"
|
||||
);
|
||||
insertTag.setString(1, "Livestream");
|
||||
insertTag.setString(2, "livestream");
|
||||
insertTag.executeUpdate();
|
||||
|
||||
PreparedStatement getTagId = conn.prepareStatement("SELECT id FROM sis_tag WHERE slug = 'livestream'");
|
||||
ResultSet rsTag2 = getTagId.executeQuery();
|
||||
if (rsTag2.next()) {
|
||||
tagId = rsTag2.getLong("id");
|
||||
}
|
||||
}
|
||||
|
||||
if (tagId == -1) {
|
||||
System.out.println("Failed to find or create livestream tag.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Insert Post
|
||||
// We set Title as "Tuần 1" (so it shows nicely on the tab label)
|
||||
// We set Excerpt as the long Title they provided.
|
||||
String postTitle = "Tuần 1";
|
||||
String postExcerpt = "SIS Vì Sức khỏe Cộng đồng kỳ 134 Thoát vị đĩa đệm – Khi nào mới phẫu thuật?";
|
||||
String postContent = "Đau lưng, đau cổ, tê tay, tê chân... là những triệu chứng thường gặp của thoát vị đĩa đệm. Tuy nhiên, không phải ai mắc bệnh cũng cần phẫu thuật.\n" +
|
||||
"⚠️ Vậy khi nào nên điều trị bảo tồn? Khi nào cần phẫu thuật? Làm sao để tránh bỏ lỡ \"thời điểm vàng\" điều trị?\n" +
|
||||
"Cùng lắng nghe những chia sẻ từ các chuyên gia trong chương trình Livestream \"S.I.S vì sức khỏe cộng đồng\" vào lúc 𝟏𝟗𝐡𝟒𝟓 Thứ Ba, ngày 𝟎𝟕/𝟎𝟕/𝟐𝟎𝟐𝟔.\n" +
|
||||
"📌 Đồng hành và tư vấn trực tiếp cùng quý khán giả là các bác sĩ giàu kinh nghiệm tại Bệnh viện ĐKQT S.I.S Cần Thơ:\n" +
|
||||
"• BS.CKI Nguyễn Quang Hưng, chuyên khoa Ngoại Thần kinh\n" +
|
||||
"• BS.CKI Trương Đan Kha, chuyên khoa Vật lý trị liệu - Phục hồi chức năng \n" +
|
||||
"• ThS.BS Lê Thị Chi Lan, chuyên khoa Ngoại Thần kinh.";
|
||||
|
||||
// Convert standard youtube link to embed link
|
||||
String embedUrl = "https://www.youtube.com/embed/j63kT9Bjrb4";
|
||||
|
||||
PreparedStatement insertPost = conn.prepareStatement(
|
||||
"INSERT INTO sis_post (id, title, slug, content, excerpt, meta_description, featured_image, created_by, status) " +
|
||||
"VALUES (sequence_generator.NEXTVAL, ?, ?, ?, ?, ?, ?, 'system', 'PUBLISHED')"
|
||||
);
|
||||
insertPost.setString(1, postTitle);
|
||||
insertPost.setString(2, "sis-vi-suc-khoe-cong-dong-ky-134");
|
||||
insertPost.setString(3, postContent);
|
||||
insertPost.setString(4, postExcerpt);
|
||||
insertPost.setString(5, embedUrl);
|
||||
insertPost.setString(6, "/media/livestream/livestream_tuan1.jpg"); // uploaded image
|
||||
insertPost.executeUpdate();
|
||||
|
||||
// Get new post ID
|
||||
long postId = -1;
|
||||
PreparedStatement getPostId = conn.prepareStatement("SELECT id FROM sis_post WHERE slug = 'sis-vi-suc-khoe-cong-dong-ky-134'");
|
||||
ResultSet rsPost = getPostId.executeQuery();
|
||||
if (rsPost.next()) {
|
||||
postId = rsPost.getLong("id");
|
||||
}
|
||||
|
||||
if (postId == -1) {
|
||||
System.out.println("Failed to retrieve created post ID.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Link post with tag
|
||||
PreparedStatement linkPostTag = conn.prepareStatement(
|
||||
"INSERT INTO sis_post_tag (post_id, tag_id) VALUES (?, ?)"
|
||||
);
|
||||
linkPostTag.setLong(1, postId);
|
||||
linkPostTag.setLong(2, tagId);
|
||||
linkPostTag.executeUpdate();
|
||||
|
||||
System.out.println("Successfully created post and linked it with the 'livestream' tag.");
|
||||
conn.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user