-
Notifications
You must be signed in to change notification settings - Fork 0
feat: podcast #17
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
Open
SuhailAhmed2627
wants to merge
8
commits into
main
Choose a base branch
from
podcast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: podcast #17
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8640992
feat: podcast
d4c44f0
feat(podcast): update+delete routes
19dec22
feat(podcast): add episodeNo
57aff6d
feat(podcast): GET routes
rahilb1 436b8b7
fix(podcast): GET routes
rahilb1 f47fefb
fix(podcast): GET routes
rahilb1 f6b47cd
fix(podcast): Fix EditThumbnail
4ec839f
fix(podcast): GET routes
rahilb1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,291 @@ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "log" | ||
| "net/http" | ||
| "strconv" | ||
|
|
||
| "github.com/ecea-nitt/ecea-server/middlewares" | ||
| "github.com/ecea-nitt/ecea-server/models" | ||
| "github.com/ecea-nitt/ecea-server/services" | ||
| "github.com/ecea-nitt/ecea-server/utils" | ||
| "github.com/fatih/color" | ||
| "github.com/labstack/echo/v4" | ||
| ) | ||
|
|
||
| type podcastController struct { | ||
| ps services.PodcastService | ||
| } | ||
|
|
||
| type PodcastController interface { | ||
| CreatePodcast(c echo.Context) error | ||
| EditThumbnail(c echo.Context) error | ||
| EditURL(c echo.Context) error | ||
| EditDescription(c echo.Context) error | ||
| DeletePodcast(c echo.Context) error | ||
| GetPodcast(c echo.Context) error | ||
| GetAllPodcasts(c echo.Context) error | ||
| GetPodcastByType(c echo.Context) error | ||
| } | ||
|
|
||
| func NewPodcastController(ps services.PodcastService) PodcastController { | ||
| return &podcastController{ps} | ||
| } | ||
|
|
||
| // CreatePodcast godoc | ||
| // | ||
| // @Summary Create Podcast | ||
| // @Description Adds a new podcast to the database | ||
| // @Tags Podcast | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param name formData string true "Enter name" | ||
| // @Param episodeNo formData uint true "Enter episode number" | ||
| // @Param type formData models.PodcastType true "Choose a type" | ||
| // @Param description formData string true "Enter description" | ||
| // @Param mediaURL formData string true "Enter Media URL" | ||
| // @Param image formData file true "Upload Thumbnail" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/podcast/create [post] | ||
| func (pc *podcastController) CreatePodcast(c echo.Context) error { | ||
| request := new(models.PodcastRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| file, err := c.FormFile("image") | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return err | ||
| } | ||
|
|
||
| err = pc.ps.CreatePodcast(*request, file) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, http.StatusText(http.StatusOK)) | ||
| } | ||
|
|
||
| // EditThumbnail godoc | ||
| // | ||
| // @Summary Edit Thumbnail | ||
| // @Description Edits the thumbnail of a podcast | ||
| // @Tags Podcast | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param episodeNo formData uint true "Enter episode number" | ||
| // | ||
| // @Param type formData models.PodcastType true "Choose a type" | ||
| // | ||
| // @Param image formData file true "Upload Thumbnail" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/podcast/edit/thumbnail [put] | ||
| func (pc *podcastController) EditThumbnail(c echo.Context) error { | ||
| request := new(models.PodcastRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| file, err := c.FormFile("image") | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return err | ||
| } | ||
|
|
||
| err = pc.ps.EditThumbnail(*request, file) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, http.StatusText(http.StatusOK)) | ||
| } | ||
|
|
||
| // EditURL godoc | ||
| // | ||
| // @Summary Edit URL | ||
| // @Description Edits the media url of a podcast | ||
| // @Tags Podcast | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param episodeNo formData uint true "Enter episode number" | ||
| // | ||
| // @Param type formData models.PodcastType true "Choose a type" | ||
| // | ||
| // @Param mediaURL formData string true "Enter Media URL" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/podcast/edit/url [put] | ||
| func (pc *podcastController) EditURL(c echo.Context) error { | ||
| request := new(models.PodcastRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| err := pc.ps.EditURL(*request) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, http.StatusText(http.StatusOK)) | ||
| } | ||
|
|
||
| // EditDescription godoc | ||
| // | ||
| // @Summary Edit Description | ||
| // @Description Edits the description of a podcast | ||
| // @Tags Podcast | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param episodeNo formData uint true "Enter episode number" | ||
| // | ||
| // @Param type formData models.PodcastType true "Choose a type" | ||
| // | ||
| // @Param description formData string true "Enter description" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/podcast/edit/description [put] | ||
| func (pc *podcastController) EditDescription(c echo.Context) error { | ||
| request := new(models.PodcastRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| err := pc.ps.EditDescription(*request) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, http.StatusText(http.StatusOK)) | ||
| } | ||
|
|
||
| // DeletePodcast godoc | ||
| // | ||
| // @Summary Delete Podcast | ||
| // @Description Deletes a podcast | ||
| // @Tags Podcast | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param episodeNo formData uint true "Enter episode number" | ||
| // | ||
| // @Param type formData models.PodcastType true "Choose a type" | ||
| // | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/podcast/delete [delete] | ||
| func (pc *podcastController) DeletePodcast(c echo.Context) error { | ||
| request := new(models.PodcastRequest) | ||
|
|
||
| if err := c.Bind(request); err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| err := pc.ps.DeletePodcast(*request) | ||
|
|
||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, http.StatusText(http.StatusOK)) | ||
| } | ||
|
|
||
| // GetPodcastByEpisodeNumberAndType godoc | ||
| // @Summary Get Podcast By Episode Number And Type | ||
| // @Description Gets a podcast by episode number and type | ||
| // @Tags Podcast | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param episodeNo path uint true "Enter episode number" | ||
| // @Param type path models.PodcastType true "Choose a type" | ||
| // @Success 200 {object} models.Podcasts | ||
| // @Failure 400 {object} models.Error | ||
| // @Failure 500 {object} models.Error | ||
| // @Router /v1/podcast/get/{episodeNo}/{type} [get] | ||
| func (pc *podcastController) GetPodcast(c echo.Context) error { | ||
| podcastType, err := utils.PodcastTypeValidator(c.Param("type")) | ||
| if err != nil { | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| episodeNo, err := strconv.ParseUint(c.Param("episodeNo"), 10, 64) | ||
| if err != nil { | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| podcast, err := pc.ps.GetPodcastByEpisodeNumberAndType(uint(episodeNo), podcastType) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, podcast) | ||
| } | ||
|
|
||
| // GetAllPodcasts godoc | ||
| // @Summary Get All Podcasts | ||
| // @Description Gets all podcasts | ||
| // @Tags Podcast | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Success 200 {object} []models.Podcasts | ||
| // @Failure 400 {object} models.Error | ||
| // @Failure 500 {object} models.Error | ||
| // @Router /v1/podcast/get/all [get] | ||
| func (pc *podcastController) GetAllPodcasts(c echo.Context) error { | ||
| podcasts, err := pc.ps.GetAllPodcasts() | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, podcasts) | ||
| } | ||
|
|
||
| // GetPodcastByType godoc | ||
| // @Summary Get Podcast By Type | ||
| // @Description Gets a podcast by type | ||
| // @Tags Podcast | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param type path models.PodcastType true "Enter type" | ||
| // @Success 200 {object} []models.Podcasts | ||
| // @Failure 400 {object} models.Error | ||
| // @Failure 500 {object} models.Error | ||
| // @Router /v1/podcast/getall/{type} [get] | ||
| func (pc *podcastController) GetPodcastByType(c echo.Context) error { | ||
| podcastType, err := utils.PodcastTypeValidator(c.Param("type")) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusBadRequest, http.StatusText(http.StatusBadRequest)) | ||
| } | ||
|
|
||
| podcasts, err := pc.ps.GetPodcastByType(podcastType) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, podcasts) | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.