{"id":16148241,"url":"https://github.com/chanwit/sa-64-example","last_synced_at":"2025-08-22T06:32:48.809Z","repository":{"id":63993202,"uuid":"395902483","full_name":"chanwit/sa-64-example","owner":"chanwit","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-05T05:49:28.000Z","size":25684,"stargazers_count":4,"open_issues_count":0,"forks_count":191,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-28T07:21:15.758Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chanwit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-14T05:33:42.000Z","updated_at":"2024-08-08T23:11:18.000Z","dependencies_parsed_at":"2023-01-14T18:00:53.513Z","dependency_job_id":null,"html_url":"https://github.com/chanwit/sa-64-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanwit%2Fsa-64-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanwit%2Fsa-64-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanwit%2Fsa-64-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanwit%2Fsa-64-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chanwit","download_url":"https://codeload.github.com/chanwit/sa-64-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230568590,"owners_count":18246378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T00:32:06.873Z","updated_at":"2024-12-20T10:08:31.116Z","avatar_url":"https://github.com/chanwit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ระบบบันทึกการดูวีดีโอ\n\n![alt text](./image/activity.png)\n\n![alt text](./image/communication.png)\n\nอธิบาย Code ในส่วนของการ ค้นหา สร้าง โยง และบันทึก WatchVideo ตาม use case\n\n```golang\n// POST /watch_videos\nfunc CreateWatchVideo(c *gin.Context) {\n\n    var watchvideo entity.WatchVideo\n    var resolution entity.Resolution\n    var playlist entity.Playlist\n    var video entity.Video\n\n    // ผลลัพธ์ที่ได้จากขั้นตอนที่ 8 จะถูก bind เข้าตัวแปร watchVideo\n    if err := c.ShouldBindJSON(\u0026watchvideo); err != nil {\n    \tc.JSON(http.StatusBadRequest, gin.H{\"error\": err.Error()})\n    \treturn\n    }\n\n    // 9: ค้นหา video ด้วย id\n    if tx := entity.DB().Where(\"id = ?\", watchvideo.VideoID).First(\u0026video); tx.RowsAffected == 0 {\n    \tc.JSON(http.StatusBadRequest, gin.H{\"error\": \"video not found\"})\n    \treturn\n    }\n\n    // 10: ค้นหา resolution ด้วย id\n    if tx := entity.DB().Where(\"id = ?\", watchvideo.ResolutionID).First(\u0026resolution); tx.RowsAffected == 0 {\n    \tc.JSON(http.StatusBadRequest, gin.H{\"error\": \"resolution not found\"})\n    \treturn\n    }\n\n    // 11: ค้นหา playlist ด้วย id\n    if tx := entity.DB().Where(\"id = ?\", watchvideo.PlaylistID).First(\u0026playlist); tx.RowsAffected == 0 {\n    \tc.JSON(http.StatusBadRequest, gin.H{\"error\": \"playlist not found\"})\n    \treturn\n    }\n    // 12: สร้าง WatchVideo\n    wv := entity.WatchVideo{\n    \tResolution:      resolution,            // โยงความสัมพันธ์กับ Entity Resolution\n    \tVideo:             video,               // โยงความสัมพันธ์กับ Entity Video\n    \tPlaylist:           playlist,           // โยงความสัมพันธ์กับ Entity Playlist\n    \tWatchedTime: watchvideo.WatchedTime,    // ตั้งค่าฟิลด์ watchedTime\n    }\n\n    // 13: บันทึก\n    if err := entity.DB().Create(\u0026wv).Error; err != nil {\n    \tc.JSON(http.StatusBadRequest, gin.H{\"error\": err.Error()})\n    \treturn\n    }\n    c.JSON(http.StatusOK, gin.H{\"data\": wv})\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanwit%2Fsa-64-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchanwit%2Fsa-64-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanwit%2Fsa-64-example/lists"}