Implement admin media approval endpoints and add JWT role-based auth - NOT TESTED
This commit is contained in:
@@ -19,34 +19,43 @@ func NewAdminDashboardHandler(appContext *internal.AppContext) *AdminDashboardHa
|
||||
}
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) AdminHomePage(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "AdminDashboardHomePage",
|
||||
})
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) ApproveMedia(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "ApproveMedia",
|
||||
})
|
||||
var input requestmodels.ApproveMediaInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if appContext.AppContext.PostService.ApproveMedia(input.MediaId) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Media approved successfully"})
|
||||
} else {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to approve media"})
|
||||
}
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) RejectMedia(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "RejectMedia",
|
||||
})
|
||||
var input requestmodels.RejectMediaInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if appContext.AppContext.PostService.RejectMedia(input.MediaId) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Media rejected successfully"})
|
||||
} else {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to reject media"})
|
||||
}
|
||||
}
|
||||
|
||||
func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
||||
|
||||
var input requestmodels.LoginInput
|
||||
|
||||
|
||||
// Validate data
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if input.Password == appContext.AppContext.AdminPassword {
|
||||
if input.Password == appContext.AppContext.AdminPassword { // Its more than enough for this project
|
||||
token, err := appContext.AppContext.Jwt.GenerateToken(map[string]interface{}{"role": "admin"})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token generation failed"})
|
||||
@@ -60,6 +69,10 @@ func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
|
||||
c.JSON(401, gin.H{
|
||||
"YouAreOn": "Unauthorized",
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{
|
||||
"YouAreOn": "Login",
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user