Skip to content

MethasMP/sa-64-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

āļĢāļ°āļšāļšāļšāļąāļ™āļ—āļķāļāļāļēāļĢāļ”āļđāļ§āļĩāļ”āļĩāđ‚āļ­

alt text

alt text

āļ­āļ˜āļīāļšāļēāļĒ Code āđƒāļ™āļŠāđˆāļ§āļ™āļ‚āļ­āļ‡āļāļēāļĢ āļ„āđ‰āļ™āļŦāļē āļŠāļĢāđ‰āļēāļ‡ āđ‚āļĒāļ‡ āđāļĨāļ°āļšāļąāļ™āļ—āļķāļ WatchVideo āļ•āļēāļĄ use case

// POST /watch_videos
func CreateWatchVideo(c *gin.Context) {

    var watchvideo entity.WatchVideo
    var resolution entity.Resolution
    var playlist entity.Playlist
    var video entity.Video

    // āļœāļĨāļĨāļąāļžāļ˜āđŒāļ—āļĩāđˆāđ„āļ”āđ‰āļˆāļēāļāļ‚āļąāđ‰āļ™āļ•āļ­āļ™āļ—āļĩāđˆ 8 āļˆāļ°āļ–āļđāļ bind āđ€āļ‚āđ‰āļēāļ•āļąāļ§āđāļ›āļĢ watchVideo
    if err := c.ShouldBindJSON(&watchvideo); err != nil {
    	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
    	return
    }

    // 9: āļ„āđ‰āļ™āļŦāļē video āļ”āđ‰āļ§āļĒ id
    if tx := entity.DB().Where("id = ?", watchvideo.VideoID).First(&video); tx.RowsAffected == 0 {
    	c.JSON(http.StatusBadRequest, gin.H{"error": "video not found"})
    	return
    }

    // 10: āļ„āđ‰āļ™āļŦāļē resolution āļ”āđ‰āļ§āļĒ id
    if tx := entity.DB().Where("id = ?", watchvideo.ResolutionID).First(&resolution); tx.RowsAffected == 0 {
    	c.JSON(http.StatusBadRequest, gin.H{"error": "resolution not found"})
    	return
    }

    // 11: āļ„āđ‰āļ™āļŦāļē playlist āļ”āđ‰āļ§āļĒ id
    if tx := entity.DB().Where("id = ?", watchvideo.PlaylistID).First(&playlist); tx.RowsAffected == 0 {
    	c.JSON(http.StatusBadRequest, gin.H{"error": "playlist not found"})
    	return
    }
    // 12: āļŠāļĢāđ‰āļēāļ‡ WatchVideo
    wv := entity.WatchVideo{
    	Resolution:      resolution,            // āđ‚āļĒāļ‡āļ„āļ§āļēāļĄāļŠāļąāļĄāļžāļąāļ™āļ˜āđŒāļāļąāļš Entity Resolution
    	Video:             video,               // āđ‚āļĒāļ‡āļ„āļ§āļēāļĄāļŠāļąāļĄāļžāļąāļ™āļ˜āđŒāļāļąāļš Entity Video
    	Playlist:           playlist,           // āđ‚āļĒāļ‡āļ„āļ§āļēāļĄāļŠāļąāļĄāļžāļąāļ™āļ˜āđŒāļāļąāļš Entity Playlist
    	WatchedTime: watchvideo.WatchedTime,    // āļ•āļąāđ‰āļ‡āļ„āđˆāļēāļŸāļīāļĨāļ”āđŒ watchedTime
    }

    // 13: āļšāļąāļ™āļ—āļķāļ
    if err := entity.DB().Create(&wv).Error; err != nil {
    	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
    	return
    }
    c.JSON(http.StatusOK, gin.H{"data": wv})
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 55.1%
  • Go 41.2%
  • HTML 2.4%
  • CSS 1.3%