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",
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package handlers_home
|
||||
|
||||
import (
|
||||
"CatsOfMastodonBotGo/internal"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type MainPageHandler struct {
|
||||
AppContext *internal.AppContext
|
||||
}
|
||||
|
||||
func NewMainPageHandler(appContext *internal.AppContext) *MainPageHandler {
|
||||
return &MainPageHandler{
|
||||
AppContext: appContext,
|
||||
}
|
||||
}
|
||||
|
||||
func (appContext *MainPageHandler) HomePageHandler(c *gin.Context) {
|
||||
c.Data(200, "text/html; charset=utf-8", []byte(`<p>Welcome to CatsOfMastodonBotGo - <a href="https://git.mahdium.ir/mahdium/CatsOfMastodon">The main project</a>, writen in C# is available at that link - This is only my attempt to port it to Go for learning purposes</p>`))
|
||||
}
|
||||
Reference in New Issue
Block a user