package admin import ( "net/http" "github.com/gin-gonic/gin" "github.com/metarare/metarare_api/common" "github.com/metarare/metarare_api/helpers/gauth" "github.com/metarare/metarare_api/helpers/gerror" "github.com/metarare/metarare_api/models" "gorm.io/gorm" ) type AdminLogV1Router struct { group *gin.RouterGroup mDB *gorm.DB rDB *gorm.DB } func NewAdminLogV1Router(r common.Router, basePath string) AdminLogV1Router { l := AdminLogV1Router{ group: r.Version.Group(basePath), mDB: r.Db.MasterDB, rDB: r.Db.ReadDB, } l.group.GET("", l.getLog) return l } // getLog godoc // @Summary get log list // @Description 어드민 로그 가져오기 // @Schemes // @security ApiKeyAuth // @Tags admin // @Accept json // @Produce json // @Success 200 {object} models.AdminLog // @Router /admin/log [get] func (l AdminLogV1Router) getLog(c *gin.Context) { admin, err := gauth.ConfirmAdminInfo(c, l.rDB) if err != nil || admin.ID == 0 { gerror.IntegratedResponseToRequest(c, http.StatusUnauthorized, gerror.Unauthorized, nil, err) return } if admin.AdminPermission.Log == 0 { gerror.IntegratedResponseToRequest(c, http.StatusUnauthorized, gerror.PermissionNotFound, nil, err) return } response := []models.AdminLog{} if err := l.rDB.Order("id desc").Find(&response).Error; err != nil { gerror.IntegratedResponseToRequest(c, http.StatusBadRequest, gerror.InvalidParameterValue, nil, err) return } gerror.IntegratedResponseToRequest(c, http.StatusOK, gerror.OK, response, nil) return }