first commit
This commit is contained in:
58
.air.toml
Normal file
58
.air.toml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#:schema https://json.schemastore.org/any.json
|
||||||
|
|
||||||
|
env_files = []
|
||||||
|
root = "."
|
||||||
|
testdata_dir = "testdata"
|
||||||
|
tmp_dir = "tmp"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
args_bin = []
|
||||||
|
bin = "./tmp/main"
|
||||||
|
cmd = "go build -o ./tmp/main ."
|
||||||
|
delay = 1000
|
||||||
|
entrypoint = ["./tmp/main"]
|
||||||
|
exclude_dir = ["assets", "tmp", "vendor", "testdata","frontend"]
|
||||||
|
exclude_file = []
|
||||||
|
exclude_regex = ["_test.go"]
|
||||||
|
exclude_unchanged = false
|
||||||
|
follow_symlink = false
|
||||||
|
full_bin = ""
|
||||||
|
ignore_dangerous_root_dir = false
|
||||||
|
include_dir = []
|
||||||
|
include_ext = ["go", "tpl", "tmpl", "html"]
|
||||||
|
include_file = []
|
||||||
|
kill_delay = "0s"
|
||||||
|
log = "build-errors.log"
|
||||||
|
poll = false
|
||||||
|
poll_interval = 0
|
||||||
|
post_cmd = []
|
||||||
|
pre_cmd = []
|
||||||
|
rerun = false
|
||||||
|
rerun_delay = 500
|
||||||
|
send_interrupt = false
|
||||||
|
stop_on_error = false
|
||||||
|
|
||||||
|
[color]
|
||||||
|
app = ""
|
||||||
|
build = "yellow"
|
||||||
|
main = "magenta"
|
||||||
|
runner = "green"
|
||||||
|
watcher = "cyan"
|
||||||
|
|
||||||
|
[log]
|
||||||
|
main_only = false
|
||||||
|
silent = false
|
||||||
|
time = false
|
||||||
|
|
||||||
|
[misc]
|
||||||
|
clean_on_exit = false
|
||||||
|
|
||||||
|
[proxy]
|
||||||
|
app_port = 0
|
||||||
|
app_start_timeout = 0
|
||||||
|
enabled = false
|
||||||
|
proxy_port = 0
|
||||||
|
|
||||||
|
[screen]
|
||||||
|
clear_on_rebuild = false
|
||||||
|
keep_scroll = true
|
||||||
95
.env
Normal file
95
.env
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
NEXT_AUTH_SECRET=bFcOqf37V1DgSxsibuZ79jSIaI4MZ9TCB1Y7iWZFJZrtZdUJapesSi0dXo2Bx8xY
|
||||||
|
|
||||||
|
GITHUB_CLIENT_ID='Ov23liUt9B61O46Mdfm4'
|
||||||
|
GITHUB_CLIENT_SECRET='c7fc8dcb1b2c8f22120608425d07d5efd995baaf'
|
||||||
|
GITHUB_SCOPE=['user:email']
|
||||||
|
|
||||||
|
GOOGLE_CLIENT_ID='915364976256-691m0s87as2r5vdbqr96f6humblseobt.apps.googleusercontent.com'
|
||||||
|
GOOGLE_CLIENT_SECRET='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'
|
||||||
|
GOOGLE_REDIRECT_URL=http://localhost:8080/v1/auth/google/callback
|
||||||
|
|
||||||
|
AUTH_NO_SECRET=MlBdj44xjhZIlxQIiz4ZuszB1yvRMW0A
|
||||||
|
BASE_API_URL=http://localhost:8080
|
||||||
|
# BASE_API_URL=https://api.beyhano.com.tr
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:8080
|
||||||
|
BASE_SITE_URL=http://localhost:3000
|
||||||
|
AUTH_NO_ORIGIN=http://localhost:3000
|
||||||
|
BASE_SITE_NAME='Beyhan Oğur'
|
||||||
|
NODE_ENV='development'
|
||||||
|
NEXT_PORT=3000
|
||||||
|
APP_TITLE='Beyhan Oğur'
|
||||||
|
NEXT_API_SECRET='6YdkEwOZC0j5K9a5vJtJQGIuwAoqGG4c'
|
||||||
|
# NUXT_PUBLIC_API_BASE=https://api.beyhano.com.tr
|
||||||
|
CLOUD_FLARE_SITE_KEY='0x4AAAAAACHzHKvlEwMamxCM'
|
||||||
|
CLOUD_FLARE_SECRET='0x4AAAAAACHzHHisTSFzGw15HvwXF3yXRIg'
|
||||||
|
# JWT için gizli anahtar. Güvenlik için bunu daha karmaşık bir değerle değiştirin.
|
||||||
|
JWT_SECRET="go-gin-mTFY2jAOMWWxadVIWjRoPG9aOM3z9srCVoU35Gs1VZaRKgXet26cztUE8LLpwok9"
|
||||||
|
#####################GO###################
|
||||||
|
### Db Configuration
|
||||||
|
DB_URL="gogin:gg7678290@tcp(10.80.80.70:3306)/gogin?charset=utf8mb4&parseTime=True&loc=Local&timeout=10s&readTimeout=30s&writeTimeout=30s&multiStatements=true"
|
||||||
|
##########################
|
||||||
|
# Redis Configuration
|
||||||
|
REDIS_HOST=10.80.80.70
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_USER=default
|
||||||
|
REDIS_PASSWORD=gg7678290
|
||||||
|
REDIS_URL=redis://default:gg7678290@10.80.80.70:6379/4
|
||||||
|
#############################
|
||||||
|
# Email Settings (Mailpit)
|
||||||
|
EMAIL_HOST=10.80.80.70
|
||||||
|
EMAIL_PORT=1025
|
||||||
|
EMAIL_HOST_USER=""
|
||||||
|
EMAIL_HOST_PASSWORD=""
|
||||||
|
EMAIL_USE_TLS=false
|
||||||
|
EMAIL_USE_SSL=false
|
||||||
|
EMAIL_FROM=noreply@gauth.local
|
||||||
|
#############################
|
||||||
|
# App Genel Ayarları
|
||||||
|
PORT=8080
|
||||||
|
################################
|
||||||
|
# AVATANE IMAGES
|
||||||
|
AVATAR_H=150
|
||||||
|
AVATAR_W=150
|
||||||
|
AVATAR_Q=90
|
||||||
|
AVATAR_B=cover
|
||||||
|
AVATAR_F=webp
|
||||||
|
#######################
|
||||||
|
# Home IMAGES
|
||||||
|
HOME_IMAGE_H=400
|
||||||
|
HOME_IMAGE_W=400
|
||||||
|
HOME_IMAGE_Q=90
|
||||||
|
HOME_IMAGE_B=cover
|
||||||
|
HOME_IMAGE_F=webp
|
||||||
|
#######################
|
||||||
|
# Aboutme IMAGES
|
||||||
|
ABOUTME_IMAGE_H=400
|
||||||
|
ABOUTME_IMAGE_W=400
|
||||||
|
ABOUTME_IMAGE_Q=90
|
||||||
|
ABOUTME_IMAGE_B=cover
|
||||||
|
ABOUTME_IMAGE_F=webp
|
||||||
|
#######################
|
||||||
|
# MyService IMAGES
|
||||||
|
SERVICE_IMAGE_H=256
|
||||||
|
SERVICE_IMAGE_W=256
|
||||||
|
SERVICE_IMAGE_Q=90
|
||||||
|
SERVICE_IMAGE_B=cover
|
||||||
|
SERVICE_IMAGE_F=webp
|
||||||
|
#######################
|
||||||
|
# BANNER IMAGES
|
||||||
|
BANNER_IMAGE_H=700
|
||||||
|
BANNER_IMAGE_W=1920
|
||||||
|
BANNER_IMAGE_Q=85
|
||||||
|
BANNER_IMAGE_B=cover
|
||||||
|
BANNER_IMAGE_F=webp
|
||||||
|
################################
|
||||||
|
################################
|
||||||
|
SET_DEBUG=true
|
||||||
|
CORS_DEBUG=true
|
||||||
|
APP_ENV=development
|
||||||
|
VITE_API_BASE_URL=http://localhost:8080
|
||||||
|
FRONTEND_URL=http://localhost:3000
|
||||||
|
SESSION_SECRET=go-gin-mTFY2jAOMWWxadVIWjRoPG9aOM3z9srCVoU35Gs1VZaRKgXet26cztUE8LLpwok9
|
||||||
|
CLIENT_SECRET='2222'
|
||||||
|
CLIENT_ID='2222'
|
||||||
|
ACCESS_TOKEN_EXPIRE_MINUTES=180
|
||||||
|
REFRESH_TOKEN_EXPIRE_DAYS=60
|
||||||
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
### Go template
|
||||||
|
# If you prefer the allow list template instead of the deny list, see community template:
|
||||||
|
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||||
|
#
|
||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, built with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Dependency directories (remove the comment below to include it)
|
||||||
|
# vendor/
|
||||||
|
tmp/
|
||||||
|
frontend/node_modules/
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
go.work.sum
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Frontend
|
||||||
|
frontend/.next/
|
||||||
|
frontend/out/
|
||||||
|
frontend/build/
|
||||||
|
frontend/dist/
|
||||||
|
frontend/.DS_Store
|
||||||
|
.DS_Store
|
||||||
|
*.log
|
||||||
615
app/controllers/AuthControllers.go
Normal file
615
app/controllers/AuthControllers.go
Normal file
@@ -0,0 +1,615 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
"goGin/app/middlewares"
|
||||||
|
"goGin/app/services"
|
||||||
|
configs "goGin/config"
|
||||||
|
utils "goGin/pkg/utis"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/github"
|
||||||
|
"golang.org/x/oauth2/google"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthResponse
|
||||||
|
type AuthResponse struct {
|
||||||
|
User UserResponse `json:"user"`
|
||||||
|
AccessToken string `json:"access_token"`
|
||||||
|
RefreshToken string `json:"refresh_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterPayload
|
||||||
|
type RegisterPayload struct {
|
||||||
|
UserName string `json:"username" binding:"required"`
|
||||||
|
Email string `json:"email" binding:"required,email"`
|
||||||
|
Password string `json:"password" binding:"required,min=6"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoginPayload
|
||||||
|
type LoginPayload struct {
|
||||||
|
Email string `json:"email" binding:"required,email"`
|
||||||
|
Password string `json:"password" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RefreshPayload
|
||||||
|
type RefreshPayload struct {
|
||||||
|
RefreshToken string `json:"refresh_token" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to generate secure token for email verification
|
||||||
|
func generateSecureToken() string {
|
||||||
|
b := make([]byte, 32)
|
||||||
|
rand.Read(b)
|
||||||
|
return hex.EncodeToString(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register godoc
|
||||||
|
// @Summary Register a new user
|
||||||
|
// @Description Register a new user. Sends verification email. Does NOT return tokens.
|
||||||
|
// @Tags auth
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param register body RegisterPayload true "Register payload"
|
||||||
|
// @Success 201 {object} controllers.AuthResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/auth/register [post]
|
||||||
|
func Register(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload RegisterPayload
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check existing email
|
||||||
|
var existing models.User
|
||||||
|
if err := database.DB.Where("email = ?", payload.Email).First(&existing).Error; err == nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "email already registered"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hashedPwd, err := utils.HashPassword(payload.Password)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to hash password"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Email Verification Token
|
||||||
|
verificationToken := generateSecureToken()
|
||||||
|
emailVerified := false
|
||||||
|
|
||||||
|
user := models.User{
|
||||||
|
UserName: payload.UserName,
|
||||||
|
Email: payload.Email,
|
||||||
|
Password: hashedPwd,
|
||||||
|
EmailVerified: &emailVerified,
|
||||||
|
EmailVerifyToken: verificationToken,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Create(&user).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send Verification Email
|
||||||
|
go func() {
|
||||||
|
if err := utils.SendVerificationEmail(user.Email, verificationToken); err != nil {
|
||||||
|
fmt.Printf("Failed to send verification email to %s: %v\n", user.Email, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Response
|
||||||
|
c.JSON(http.StatusCreated, gin.H{
|
||||||
|
"message": "Registration successful. Please check your email to verify your account.",
|
||||||
|
"user": toUserResponse(user),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifyEmail godoc
|
||||||
|
// @Summary Verify email address
|
||||||
|
// @Description Verify email using token
|
||||||
|
// @Tags auth
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param token query string true "Verification Token"
|
||||||
|
// @Success 200 {object} map[string]string
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Router /api/v1/auth/verify-email [get]
|
||||||
|
func VerifyEmail(c *gin.Context) {
|
||||||
|
token := c.Query("token")
|
||||||
|
if token == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "token is required"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.Where("email_verify_token = ?", token).First(&user).Error; err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid or expired token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
verified := true
|
||||||
|
user.EmailVerified = &verified
|
||||||
|
user.EmailVerifiedAt = &now
|
||||||
|
user.EmailVerifyToken = "" // Clear token
|
||||||
|
|
||||||
|
if err := database.DB.Save(&user).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to verify email"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"message": "Email verified successfully"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Login godoc
|
||||||
|
// @Summary Login user
|
||||||
|
// @Description Login with email and password, returns tokens
|
||||||
|
// @Tags auth
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param login body LoginPayload true "Login payload"
|
||||||
|
// @Success 200 {object} controllers.AuthResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 401 {object} map[string]string
|
||||||
|
// @Router /api/v1/auth/login [post]
|
||||||
|
func Login(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload LoginPayload
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.Where("email = ?", payload.Email).First(&user).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid credentials"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !utils.CheckPasswordHash(payload.Password, user.Password) {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid credentials"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if email is verified
|
||||||
|
if user.EmailVerified != nil && !*user.EmailVerified {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "email not verified"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isAdmin := false
|
||||||
|
if user.IsAdmin != nil && *user.IsAdmin {
|
||||||
|
isAdmin = true
|
||||||
|
}
|
||||||
|
|
||||||
|
jwtService := services.NewJWTService()
|
||||||
|
accessToken, err := jwtService.GenerateToken(user.ID, isAdmin)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to generate access token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
refreshToken, err := jwtService.GenerateRefreshToken(user.ID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to generate refresh token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"user": toUserResponse(user),
|
||||||
|
"access_token": accessToken,
|
||||||
|
"refresh_token": refreshToken,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh godoc
|
||||||
|
// @Summary Refresh access token
|
||||||
|
// @Description usage: send refresh token to get new access token and refresh token
|
||||||
|
// @Tags auth
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param refresh body RefreshPayload true "Refresh token payload"
|
||||||
|
// @Success 200 {object} map[string]string "Returns both access_token and refresh_token"
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 401 {object} map[string]string
|
||||||
|
// @Router /api/v1/auth/refresh [post]
|
||||||
|
func Refresh(c *gin.Context) {
|
||||||
|
var payload RefreshPayload
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
jwtService := services.NewJWTService()
|
||||||
|
claims, err := jwtService.ValidateToken(payload.RefreshToken)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid refresh token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims.TokenType != "refresh" {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "not a refresh token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get User
|
||||||
|
var userID uint
|
||||||
|
switch v := claims.UserID.(type) {
|
||||||
|
case float64:
|
||||||
|
userID = uint(v)
|
||||||
|
case uint:
|
||||||
|
userID = v
|
||||||
|
default:
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid user claim"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.First(&user, userID).Error; err != nil {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isAdmin := false
|
||||||
|
if user.IsAdmin != nil && *user.IsAdmin {
|
||||||
|
isAdmin = true
|
||||||
|
}
|
||||||
|
|
||||||
|
newAccessToken, err := jwtService.GenerateToken(user.ID, isAdmin)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to generate token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newRefreshToken, err := jwtService.GenerateRefreshToken(user.ID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to generate refresh token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"access_token": newAccessToken,
|
||||||
|
"refresh_token": newRefreshToken,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Me godoc
|
||||||
|
// @Summary Get current user (me)
|
||||||
|
// @Description Get current authenticated user information
|
||||||
|
// @Tags auth
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} map[string]interface{}
|
||||||
|
// @Failure 401 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/auth/me [get]
|
||||||
|
func Me(c *gin.Context) {
|
||||||
|
claims, ok := middlewares.GetAuthClaims(c)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var userID uint
|
||||||
|
switch v := claims.UserID.(type) {
|
||||||
|
case float64:
|
||||||
|
userID = uint(v)
|
||||||
|
case uint:
|
||||||
|
userID = v
|
||||||
|
default:
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid user claim"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.First(&user, userID).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isAdmin := false
|
||||||
|
if user.IsAdmin != nil && *user.IsAdmin {
|
||||||
|
isAdmin = true
|
||||||
|
}
|
||||||
|
|
||||||
|
isVerified := false
|
||||||
|
if user.EmailVerified != nil && *user.EmailVerified {
|
||||||
|
isVerified = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Frontend'in beklediği formata göre response döndür
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"id": user.ID,
|
||||||
|
"username": user.UserName,
|
||||||
|
"email": user.Email,
|
||||||
|
"email_verified": isVerified,
|
||||||
|
"is_admin": isAdmin,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// OAuth Helpers
|
||||||
|
var (
|
||||||
|
googleOauthConfig = &oauth2.Config{
|
||||||
|
RedirectURL: "", // Will be set in init or handler
|
||||||
|
ClientID: "",
|
||||||
|
ClientSecret: "",
|
||||||
|
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
|
||||||
|
Endpoint: google.Endpoint,
|
||||||
|
}
|
||||||
|
githubOauthConfig = &oauth2.Config{
|
||||||
|
RedirectURL: "",
|
||||||
|
ClientID: "",
|
||||||
|
ClientSecret: "",
|
||||||
|
Scopes: []string{"user:email"},
|
||||||
|
Endpoint: github.Endpoint,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func getGoogleConfig() *oauth2.Config {
|
||||||
|
googleOauthConfig.ClientID = configs.AppConfig.GoogleClientID
|
||||||
|
googleOauthConfig.ClientSecret = configs.AppConfig.GoogleClientSecret
|
||||||
|
googleOauthConfig.RedirectURL = configs.AppConfig.GoogleRedirectURL
|
||||||
|
return googleOauthConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGithubConfig() *oauth2.Config {
|
||||||
|
githubOauthConfig.ClientID = configs.AppConfig.GithubClientID
|
||||||
|
githubOauthConfig.ClientSecret = configs.AppConfig.GithubClientSecret
|
||||||
|
githubOauthConfig.RedirectURL = configs.AppConfig.GithubRedirectURL
|
||||||
|
return githubOauthConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoogleLogin godoc
|
||||||
|
// @Summary Google OAuth2 Login
|
||||||
|
// @Description Redirects to Google for authentication
|
||||||
|
// @Tags auth
|
||||||
|
// @Success 302
|
||||||
|
// @Router /api/v1/auth/google [get]
|
||||||
|
func GoogleLogin(c *gin.Context) {
|
||||||
|
url := getGoogleConfig().AuthCodeURL("state_google", oauth2.AccessTypeOffline)
|
||||||
|
c.Redirect(http.StatusTemporaryRedirect, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoogleCallback godoc
|
||||||
|
// @Summary Google OAuth2 Callback
|
||||||
|
// @Description Handles Google OAuth2 callback
|
||||||
|
// @Tags auth
|
||||||
|
// @Success 200 {object} controllers.AuthResponse
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/auth/google/callback [get]
|
||||||
|
func GoogleCallback(c *gin.Context) {
|
||||||
|
code := c.Query("code")
|
||||||
|
token, err := getGoogleConfig().Exchange(context.Background(), code)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to exchange token: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client := getGoogleConfig().Client(context.Background(), token)
|
||||||
|
resp, err := client.Get("https://www.googleapis.com/oauth2/v2/userinfo")
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get user info: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
userData, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read user info"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var googleUser struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
VerifiedEmail bool `json:"verified_email"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Picture string `json:"picture"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(userData, &googleUser); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to parse user info"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSocialLogin(c, "google", googleUser.ID, googleUser.Email, googleUser.Name, googleUser.Picture)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GithubLogin godoc
|
||||||
|
// @Summary GitHub OAuth2 Login
|
||||||
|
// @Description Redirects to GitHub for authentication
|
||||||
|
// @Tags auth
|
||||||
|
// @Success 302
|
||||||
|
// @Router /api/v1/auth/github [get]
|
||||||
|
func GithubLogin(c *gin.Context) {
|
||||||
|
url := getGithubConfig().AuthCodeURL("state_github", oauth2.AccessTypeOffline)
|
||||||
|
c.Redirect(http.StatusTemporaryRedirect, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GithubCallback godoc
|
||||||
|
// @Summary GitHub OAuth2 Callback
|
||||||
|
// @Description Handles GitHub OAuth2 callback
|
||||||
|
// @Tags auth
|
||||||
|
// @Success 200 {object} controllers.AuthResponse
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/auth/github/callback [get]
|
||||||
|
func GithubCallback(c *gin.Context) {
|
||||||
|
code := c.Query("code")
|
||||||
|
token, err := getGithubConfig().Exchange(context.Background(), code)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to exchange token: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client := getGithubConfig().Client(context.Background(), token)
|
||||||
|
resp, err := client.Get("https://api.github.com/user")
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get user info: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
userData, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read user info"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var githubUser struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Login string `json:"login"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(userData, &githubUser); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to parse user info"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitHub email might be private, need to fetch separately if empty
|
||||||
|
email := githubUser.Email
|
||||||
|
if email == "" {
|
||||||
|
// Fetch emails
|
||||||
|
emailResp, err := client.Get("https://api.github.com/user/emails")
|
||||||
|
if err == nil {
|
||||||
|
defer emailResp.Body.Close()
|
||||||
|
var emails []struct {
|
||||||
|
Email string `json:"email"`
|
||||||
|
Primary bool `json:"primary"`
|
||||||
|
Verified bool `json:"verified"`
|
||||||
|
}
|
||||||
|
if body, err := io.ReadAll(emailResp.Body); err == nil {
|
||||||
|
json.Unmarshal(body, &emails)
|
||||||
|
for _, e := range emails {
|
||||||
|
if e.Primary && e.Verified {
|
||||||
|
email = e.Email
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if email == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Could not retrieve email from GitHub"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSocialLogin(c, "github", fmt.Sprintf("%d", githubUser.ID), email, githubUser.Name, githubUser.AvatarURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleSocialLogin(c *gin.Context, provider, providerID, email, name, avatarURL string) {
|
||||||
|
var user models.User
|
||||||
|
var socialAccount models.SocialAccount
|
||||||
|
|
||||||
|
// Check if social account exists
|
||||||
|
err := database.DB.Where("provider = ? AND provider_id = ?", provider, providerID).First(&socialAccount).Error
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
// Found social account, find user
|
||||||
|
if err := database.DB.First(&user, socialAccount.UserID).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "User record missing for social account"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Social account not found. Check if email exists
|
||||||
|
if err := database.DB.Where("email = ?", email).First(&user).Error; err == nil {
|
||||||
|
// User exists, add social account
|
||||||
|
newSocial := models.SocialAccount{
|
||||||
|
UserID: uint64(user.ID),
|
||||||
|
Provider: provider,
|
||||||
|
ProviderID: providerID,
|
||||||
|
Email: email,
|
||||||
|
Name: name,
|
||||||
|
AvatarURL: avatarURL,
|
||||||
|
}
|
||||||
|
database.DB.Create(&newSocial)
|
||||||
|
} else {
|
||||||
|
// Create new user
|
||||||
|
verified := true
|
||||||
|
now := time.Now()
|
||||||
|
// Generate random password
|
||||||
|
randomPass := generateSecureToken()
|
||||||
|
hashedPwd, _ := utils.HashPassword(randomPass)
|
||||||
|
|
||||||
|
user = models.User{
|
||||||
|
UserName: name, // Handle duplicate usernames?
|
||||||
|
Email: email,
|
||||||
|
Password: hashedPwd,
|
||||||
|
EmailVerified: &verified,
|
||||||
|
EmailVerifiedAt: &now,
|
||||||
|
}
|
||||||
|
// Fallback username if empty
|
||||||
|
if user.UserName == "" {
|
||||||
|
user.UserName = strings.Split(email, "@")[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Create(&user).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create user: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newSocial := models.SocialAccount{
|
||||||
|
UserID: uint64(user.ID),
|
||||||
|
Provider: provider,
|
||||||
|
ProviderID: providerID,
|
||||||
|
Email: email,
|
||||||
|
Name: name,
|
||||||
|
AvatarURL: avatarURL,
|
||||||
|
}
|
||||||
|
database.DB.Create(&newSocial)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Login logic
|
||||||
|
isAdmin := false
|
||||||
|
if user.IsAdmin != nil && *user.IsAdmin {
|
||||||
|
isAdmin = true
|
||||||
|
}
|
||||||
|
|
||||||
|
jwtService := services.NewJWTService()
|
||||||
|
accessToken, err := jwtService.GenerateToken(user.ID, isAdmin)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to generate access token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
refreshToken, err := jwtService.GenerateRefreshToken(user.ID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to generate refresh token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"user": toUserResponse(user),
|
||||||
|
"access_token": accessToken,
|
||||||
|
"refresh_token": refreshToken,
|
||||||
|
})
|
||||||
|
}
|
||||||
2289
app/controllers/BlogContraller.go
Normal file
2289
app/controllers/BlogContraller.go
Normal file
File diff suppressed because it is too large
Load Diff
538
app/controllers/HeroController.go
Normal file
538
app/controllers/HeroController.go
Normal file
@@ -0,0 +1,538 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Hero payload
|
||||||
|
type HeroPayload struct {
|
||||||
|
Color string `json:"color" binding:"required"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Text1 string `json:"text1"`
|
||||||
|
Text2 string `json:"text2"`
|
||||||
|
Text4 string `json:"text4"`
|
||||||
|
Text5 string `json:"text5"`
|
||||||
|
Image string `json:"image"`
|
||||||
|
IsActive *bool `json:"is_active"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminListHeroes godoc
|
||||||
|
// @Summary Admin: List heroes
|
||||||
|
// @Description Admin listing of heroes. Use ?soft=only to list deleted, ?soft=with to include deleted.
|
||||||
|
// @Tags heroes
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param page query int false "Page number"
|
||||||
|
// @Param per_page query int false "Items per page"
|
||||||
|
// @Param soft query string false "Soft delete filter: only|with"
|
||||||
|
// @Success 200 {object} controllers.HeroListResponse
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/heroes [get]
|
||||||
|
func AdminListHeroes(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pageStr := c.DefaultQuery("page", "1")
|
||||||
|
perPageStr := c.DefaultQuery("per_page", "20")
|
||||||
|
page, _ := strconv.Atoi(pageStr)
|
||||||
|
perPage, _ := strconv.Atoi(perPageStr)
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if perPage < 1 {
|
||||||
|
perPage = 20
|
||||||
|
}
|
||||||
|
if perPage > 200 {
|
||||||
|
perPage = 200
|
||||||
|
}
|
||||||
|
offset := (page - 1) * perPage
|
||||||
|
|
||||||
|
soft := c.Query("soft")
|
||||||
|
var query *gorm.DB
|
||||||
|
if soft == "only" {
|
||||||
|
query = database.DB.Unscoped().Model(&models.Hero{}).Where("deleted_at IS NOT NULL")
|
||||||
|
} else if soft == "with" {
|
||||||
|
query = database.DB.Unscoped().Model(&models.Hero{})
|
||||||
|
} else {
|
||||||
|
query = database.DB.Model(&models.Hero{})
|
||||||
|
}
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
if err := query.Count(&total).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var items []models.Hero
|
||||||
|
if err := query.Order("created_at desc").Limit(perPage).Offset(offset).Find(&items).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"items": items, "total": total, "page": page, "per_page": perPage})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminGetHero godoc
|
||||||
|
// @Summary Admin: Get a hero by id
|
||||||
|
// @Description Return a single hero by id
|
||||||
|
// @Tags heroes
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Hero ID"
|
||||||
|
// @Success 200 {object} controllers.HeroResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/heroes/{id} [get]
|
||||||
|
func AdminGetHero(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var h models.Hero
|
||||||
|
if err := database.DB.Unscoped().First(&h, id).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "hero not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": h})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateHero godoc
|
||||||
|
// @Summary Admin: Create a hero
|
||||||
|
// @Description Create a new hero item (multipart/form-data)
|
||||||
|
// @Tags heroes
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept multipart/form-data
|
||||||
|
// @Produce json
|
||||||
|
// @Param color formData string true "Color"
|
||||||
|
// @Param title formData string false "Title"
|
||||||
|
// @Param text1 formData string false "Text1"
|
||||||
|
// @Param text2 formData string false "Text2"
|
||||||
|
// @Param text4 formData string false "Text4"
|
||||||
|
// @Param text5 formData string false "Text5"
|
||||||
|
// @Param is_active formData boolean false "Is Active"
|
||||||
|
// @Param width formData int false "Image width (frontend-provided)"
|
||||||
|
// @Param height formData int false "Image height (frontend-provided)"
|
||||||
|
// @Param quality formData int false "Image quality (frontend-provided)"
|
||||||
|
// @Param format formData string false "Image format (jpeg|png|webp) (frontend-provided)"
|
||||||
|
// @Param image formData file false "Image file"
|
||||||
|
// @Success 201 {object} controllers.HeroResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/heroes [post]
|
||||||
|
func CreateHero(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Parse form fields
|
||||||
|
color := c.PostForm("color")
|
||||||
|
if color == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "color is required"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
title := c.PostForm("title")
|
||||||
|
text1 := c.PostForm("text1")
|
||||||
|
text2 := c.PostForm("text2")
|
||||||
|
text4 := c.PostForm("text4")
|
||||||
|
text5 := c.PostForm("text5")
|
||||||
|
isActive := true
|
||||||
|
if v := c.PostForm("is_active"); v != "" {
|
||||||
|
if b, err := strconv.ParseBool(v); err == nil {
|
||||||
|
isActive = b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// optional frontend-provided image metadata
|
||||||
|
var width, height, quality int
|
||||||
|
if w := c.PostForm("width"); w != "" {
|
||||||
|
if wi, err := strconv.Atoi(w); err == nil {
|
||||||
|
width = wi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if h := c.PostForm("height"); h != "" {
|
||||||
|
if hi, err := strconv.Atoi(h); err == nil {
|
||||||
|
height = hi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if q := c.PostForm("quality"); q != "" {
|
||||||
|
if qi, err := strconv.Atoi(q); err == nil {
|
||||||
|
quality = qi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
format := c.PostForm("format")
|
||||||
|
|
||||||
|
hero := models.Hero{
|
||||||
|
Color: color,
|
||||||
|
Title: title,
|
||||||
|
Text1: text1,
|
||||||
|
Text2: text2,
|
||||||
|
Text4: text4,
|
||||||
|
Text5: text5,
|
||||||
|
IsActive: isActive,
|
||||||
|
Width: width,
|
||||||
|
Height: height,
|
||||||
|
Quality: quality,
|
||||||
|
Format: format,
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle file upload (no server-side image processing)
|
||||||
|
file, err := c.FormFile("image")
|
||||||
|
if err == nil {
|
||||||
|
// ensure uploads/heroes exists
|
||||||
|
uploadDir := filepath.Join("uploads", "heroes")
|
||||||
|
if err := os.MkdirAll(uploadDir, os.ModePerm); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to create upload dir"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ext := filepath.Ext(file.Filename)
|
||||||
|
newName := fmt.Sprintf("hero-%d%s", time.Now().UnixNano(), ext)
|
||||||
|
destination := filepath.Join(uploadDir, newName)
|
||||||
|
if err := c.SaveUploadedFile(file, destination); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hero.Image = "/uploads/heroes/" + newName
|
||||||
|
// do not attempt to decode/process image here; frontend provides metadata
|
||||||
|
// if format not provided, fallback to extension without dot
|
||||||
|
if heroFormat := format; heroFormat == "" {
|
||||||
|
if ext != "" {
|
||||||
|
hero.Format = ext[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Create(&hero).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusCreated, gin.H{"data": hero})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateHero godoc
|
||||||
|
// @Summary Admin: Update a hero
|
||||||
|
// @Description Update an existing hero (multipart/form-data)
|
||||||
|
// @Tags heroes
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept multipart/form-data
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Hero ID"
|
||||||
|
// @Param color formData string false "Color"
|
||||||
|
// @Param title formData string false "Title"
|
||||||
|
// @Param text1 formData string false "Text1"
|
||||||
|
// @Param text2 formData string false "Text2"
|
||||||
|
// @Param text4 formData string false "Text4"
|
||||||
|
// @Param text5 formData string false "Text5"
|
||||||
|
// @Param is_active formData boolean false "Is Active"
|
||||||
|
// @Param width formData int false "Image width (frontend-provided)"
|
||||||
|
// @Param height formData int false "Image height (frontend-provided)"
|
||||||
|
// @Param quality formData int false "Image quality (frontend-provided)"
|
||||||
|
// @Param format formData string false "Image format (jpeg|png|webp) (frontend-provided)"
|
||||||
|
// @Param image formData file false "Image file"
|
||||||
|
// @Success 200 {object} controllers.HeroResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/heroes/{id} [put]
|
||||||
|
func UpdateHero(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var h models.Hero
|
||||||
|
if err := database.DB.First(&h, id).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "hero not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// read form fields (if present)
|
||||||
|
if color := c.PostForm("color"); color != "" {
|
||||||
|
h.Color = color
|
||||||
|
}
|
||||||
|
if title := c.PostForm("title"); title != "" {
|
||||||
|
h.Title = title
|
||||||
|
}
|
||||||
|
if t := c.PostForm("text1"); t != "" {
|
||||||
|
h.Text1 = t
|
||||||
|
}
|
||||||
|
if t := c.PostForm("text2"); t != "" {
|
||||||
|
h.Text2 = t
|
||||||
|
}
|
||||||
|
if t := c.PostForm("text4"); t != "" {
|
||||||
|
h.Text4 = t
|
||||||
|
}
|
||||||
|
if t := c.PostForm("text5"); t != "" {
|
||||||
|
h.Text5 = t
|
||||||
|
}
|
||||||
|
if v := c.PostForm("is_active"); v != "" {
|
||||||
|
if b, err := strconv.ParseBool(v); err == nil {
|
||||||
|
h.IsActive = b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// optional frontend-provided image metadata
|
||||||
|
if w := c.PostForm("width"); w != "" {
|
||||||
|
if wi, err := strconv.Atoi(w); err == nil {
|
||||||
|
h.Width = wi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hgt := c.PostForm("height"); hgt != "" {
|
||||||
|
if hi, err := strconv.Atoi(hgt); err == nil {
|
||||||
|
h.Height = hi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if q := c.PostForm("quality"); q != "" {
|
||||||
|
if qi, err := strconv.Atoi(q); err == nil {
|
||||||
|
h.Quality = qi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if fmtStr := c.PostForm("format"); fmtStr != "" {
|
||||||
|
h.Format = fmtStr
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle optional file upload (no server-side processing)
|
||||||
|
file, err := c.FormFile("image")
|
||||||
|
if err == nil {
|
||||||
|
// Save new file first
|
||||||
|
uploadDir := filepath.Join("uploads", "heroes")
|
||||||
|
if err := os.MkdirAll(uploadDir, os.ModePerm); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to create upload dir"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ext := filepath.Ext(file.Filename)
|
||||||
|
newName := fmt.Sprintf("hero-%d%s", time.Now().UnixNano(), ext)
|
||||||
|
destination := filepath.Join(uploadDir, newName)
|
||||||
|
if err := c.SaveUploadedFile(file, destination); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there was a previous image, attempt to remove it safely
|
||||||
|
prev := h.Image
|
||||||
|
if prev != "" {
|
||||||
|
// normalize and ensure it's inside uploads/
|
||||||
|
prevPath := strings.TrimPrefix(prev, "/")
|
||||||
|
clean := filepath.Clean(prevPath)
|
||||||
|
// only remove files under uploads/ to avoid accidental deletions
|
||||||
|
if strings.HasPrefix(clean, "uploads"+string(os.PathSeparator)) {
|
||||||
|
_ = os.Remove(clean) // ignore error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Image = "/uploads/heroes/" + newName
|
||||||
|
// if format not provided by frontend, fallback to extension
|
||||||
|
if h.Format == "" && ext != "" {
|
||||||
|
h.Format = ext[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Save(&h).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": h})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteHero godoc
|
||||||
|
// @Summary Admin: Delete a hero
|
||||||
|
// @Description Soft-delete a hero by ID
|
||||||
|
// @Tags heroes
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Hero ID"
|
||||||
|
// @Success 200 {object} map[string]interface{}
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/heroes/{id} [delete]
|
||||||
|
func DeleteHero(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var h models.Hero
|
||||||
|
if err := database.DB.First(&h, id).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "hero not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := database.DB.Delete(&h).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// attempt to remove image file if present
|
||||||
|
if h.Image != "" {
|
||||||
|
imgPath := strings.TrimPrefix(h.Image, "/")
|
||||||
|
clean := filepath.Clean(imgPath)
|
||||||
|
if strings.HasPrefix(clean, "uploads"+string(os.PathSeparator)) {
|
||||||
|
_ = os.Remove(clean)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"message": "hero deleted successfully", "id": h.ID})
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreHero godoc
|
||||||
|
// @Summary Admin: Restore a soft-deleted hero
|
||||||
|
// @Description Restore a soft-deleted hero by ID
|
||||||
|
// @Tags heroes
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Hero ID"
|
||||||
|
// @Success 200 {object} controllers.HeroResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/heroes/{id}/restore [post]
|
||||||
|
func RestoreHero(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var h models.Hero
|
||||||
|
// Find soft-deleted record with Unscoped
|
||||||
|
if err := database.DB.Unscoped().Where("id = ?", id).First(&h).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "hero not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Clear deleted_at (restore)
|
||||||
|
if err := database.DB.Unscoped().Model(&models.Hero{}).Where("id = ?", id).Update("deleted_at", nil).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Reload the record in normal scope to ensure DeletedAt is nil in struct
|
||||||
|
if err := database.DB.First(&h, id).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": h})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListHeroes godoc
|
||||||
|
// @Summary Public: List heroes
|
||||||
|
// @Description Return active heroes with pagination
|
||||||
|
// @Tags heroes
|
||||||
|
// @Produce json
|
||||||
|
// @Param page query int false "Page number"
|
||||||
|
// @Param per_page query int false "Items per page"
|
||||||
|
// @Success 200 {object} controllers.HeroListResponse
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/heroes [get]
|
||||||
|
func ListHeroes(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pageStr := c.DefaultQuery("page", "1")
|
||||||
|
perPageStr := c.DefaultQuery("per_page", "20")
|
||||||
|
page, _ := strconv.Atoi(pageStr)
|
||||||
|
perPage, _ := strconv.Atoi(perPageStr)
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if perPage < 1 {
|
||||||
|
perPage = 20
|
||||||
|
}
|
||||||
|
if perPage > 100 {
|
||||||
|
perPage = 100
|
||||||
|
}
|
||||||
|
offset := (page - 1) * perPage
|
||||||
|
|
||||||
|
query := database.DB.Model(&models.Hero{}).Where("is_active = ?", true)
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
if err := query.Count(&total).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var items []models.Hero
|
||||||
|
if err := query.Order("created_at desc").Limit(perPage).Offset(offset).Find(&items).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"items": items, "total": total, "page": page, "per_page": perPage})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHero godoc
|
||||||
|
// @Summary Public: Get a hero by id
|
||||||
|
// @Description Return a single hero by id
|
||||||
|
// @Tags heroes
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Hero ID"
|
||||||
|
// @Success 200 {object} controllers.HeroResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Router /api/v1/heroes/{id} [get]
|
||||||
|
func GetHero(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var h models.Hero
|
||||||
|
if err := database.DB.First(&h, id).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "hero not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": h})
|
||||||
|
}
|
||||||
758
app/controllers/SettingController.go
Normal file
758
app/controllers/SettingController.go
Normal file
@@ -0,0 +1,758 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Payload for creating/updating settings
|
||||||
|
type SettingPayload struct {
|
||||||
|
Title string `json:"title" binding:"required"`
|
||||||
|
MetaTitle string `json:"meta_title" binding:"required"`
|
||||||
|
MetaDescription string `json:"meta_description" binding:"required"`
|
||||||
|
Phone string `json:"phone" binding:"required"`
|
||||||
|
URL string `json:"url" binding:"required"`
|
||||||
|
Email string `json:"email" binding:"required"`
|
||||||
|
Facebook string `json:"facebook"`
|
||||||
|
X string `json:"x"`
|
||||||
|
Instagram string `json:"instagram"`
|
||||||
|
Whatsapp string `json:"whatsapp"`
|
||||||
|
Pinterest string `json:"pinterest"`
|
||||||
|
Linkedin string `json:"linkedin"`
|
||||||
|
Slogan string `json:"slogan"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
Copyright string `json:"copyright"`
|
||||||
|
MapEmbed string `json:"map_embed"`
|
||||||
|
WLogo string `json:"w_logo"`
|
||||||
|
BLogo string `json:"b_logo"`
|
||||||
|
IsActive *bool `json:"is_active"`
|
||||||
|
// Optional image transformation / dimension settings
|
||||||
|
WWidth *int `json:"w_width"`
|
||||||
|
WHeight *int `json:"w_height"`
|
||||||
|
WQuality *int `json:"w_quality"`
|
||||||
|
WFormat string `json:"w_format"`
|
||||||
|
BWidth *int `json:"b_width"`
|
||||||
|
BHeight *int `json:"b_height"`
|
||||||
|
BQuality *int `json:"b_quality"`
|
||||||
|
BFormat string `json:"b_format"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminListSettings godoc
|
||||||
|
// @Summary Admin: List settings
|
||||||
|
// @Description Admin listing of settings. Use ?soft=only to list deleted, ?soft=with to include deleted.
|
||||||
|
// @Tags settings
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param page query int false "Page number"
|
||||||
|
// @Param per_page query int false "Items per page"
|
||||||
|
// @Param soft query string false "Soft delete filter: only|with"
|
||||||
|
// @Success 200 {object} controllers.SettingListResponse
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/settings [get]
|
||||||
|
func AdminListSettings(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pageStr := c.DefaultQuery("page", "1")
|
||||||
|
perPageStr := c.DefaultQuery("per_page", "20")
|
||||||
|
page, _ := strconv.Atoi(pageStr)
|
||||||
|
perPage, _ := strconv.Atoi(perPageStr)
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if perPage < 1 {
|
||||||
|
perPage = 20
|
||||||
|
}
|
||||||
|
if perPage > 200 {
|
||||||
|
perPage = 200
|
||||||
|
}
|
||||||
|
offset := (page - 1) * perPage
|
||||||
|
|
||||||
|
soft := c.Query("soft")
|
||||||
|
var query *gorm.DB
|
||||||
|
if soft == "only" {
|
||||||
|
query = database.DB.Unscoped().Model(&models.Setting{}).Where("deleted_at IS NOT NULL")
|
||||||
|
} else if soft == "with" {
|
||||||
|
query = database.DB.Unscoped().Model(&models.Setting{})
|
||||||
|
} else {
|
||||||
|
query = database.DB.Model(&models.Setting{})
|
||||||
|
}
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
if err := query.Count(&total).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var items []models.Setting
|
||||||
|
if err := query.Order("created_at desc").Limit(perPage).Offset(offset).Find(&items).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"items": items, "total": total, "page": page, "per_page": perPage})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminGetSetting godoc
|
||||||
|
// @Summary Admin: Get a setting by id
|
||||||
|
// @Description Return a single setting by id
|
||||||
|
// @Tags settings
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Setting ID"
|
||||||
|
// @Success 200 {object} controllers.SettingResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/settings/{id} [get]
|
||||||
|
func AdminGetSetting(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var s models.Setting
|
||||||
|
if err := database.DB.Unscoped().First(&s, id).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "setting not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": s})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCreateSetting godoc
|
||||||
|
// @Summary Admin: Create a setting
|
||||||
|
// @Description Create a new setting
|
||||||
|
// @Tags settings
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept multipart/form-data
|
||||||
|
// @Produce json
|
||||||
|
// @Param title formData string true "Title"
|
||||||
|
// @Param meta_title formData string true "Meta title"
|
||||||
|
// @Param meta_description formData string true "Meta description"
|
||||||
|
// @Param phone formData string true "Phone"
|
||||||
|
// @Param url formData string true "URL"
|
||||||
|
// @Param email formData string true "Email"
|
||||||
|
// @Param facebook formData string false "Facebook"
|
||||||
|
// @Param x formData string false "X"
|
||||||
|
// @Param instagram formData string false "Instagram"
|
||||||
|
// @Param whatsapp formData string false "Whatsapp"
|
||||||
|
// @Param pinterest formData string false "Pinterest"
|
||||||
|
// @Param linkedin formData string false "Linkedin"
|
||||||
|
// @Param slogan formData string false "Slogan"
|
||||||
|
// @Param address formData string false "Address"
|
||||||
|
// @Param copyright formData string false "Copyright"
|
||||||
|
// @Param map_embed formData string false "Map embed"
|
||||||
|
// @Param w_logo formData file false "White logo file upload (or provide w_logo path as string)"
|
||||||
|
// @Param b_logo formData file false "Black logo file upload (or provide b_logo path as string)"
|
||||||
|
// @Param is_active formData boolean false "Is active"
|
||||||
|
// @Param w_width formData int false "W logo width"
|
||||||
|
// @Param w_height formData int false "W logo height"
|
||||||
|
// @Param w_quality formData int false "W logo quality"
|
||||||
|
// @Param w_format formData string false "W logo format"
|
||||||
|
// @Param b_width formData int false "B logo width"
|
||||||
|
// @Param b_height formData int false "B logo height"
|
||||||
|
// @Param b_quality formData int false "B logo quality"
|
||||||
|
// @Param b_format formData string false "B logo format"
|
||||||
|
// @Success 201 {object} controllers.SettingResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/settings [post]
|
||||||
|
func AdminCreateSetting(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support both JSON and multipart/form-data
|
||||||
|
var payload SettingPayload
|
||||||
|
contentType := c.GetHeader("Content-Type")
|
||||||
|
if strings.HasPrefix(contentType, "multipart/form-data") {
|
||||||
|
// read form fields
|
||||||
|
payload.Title = c.PostForm("title")
|
||||||
|
payload.MetaTitle = c.PostForm("meta_title")
|
||||||
|
payload.MetaDescription = c.PostForm("meta_description")
|
||||||
|
payload.Phone = c.PostForm("phone")
|
||||||
|
payload.URL = c.PostForm("url")
|
||||||
|
payload.Email = c.PostForm("email")
|
||||||
|
payload.Facebook = c.PostForm("facebook")
|
||||||
|
payload.X = c.PostForm("x")
|
||||||
|
payload.Instagram = c.PostForm("instagram")
|
||||||
|
payload.Whatsapp = c.PostForm("whatsapp")
|
||||||
|
payload.Pinterest = c.PostForm("pinterest")
|
||||||
|
payload.Linkedin = c.PostForm("linkedin")
|
||||||
|
payload.Slogan = c.PostForm("slogan")
|
||||||
|
payload.Address = c.PostForm("address")
|
||||||
|
payload.Copyright = c.PostForm("copyright")
|
||||||
|
payload.MapEmbed = c.PostForm("map_embed")
|
||||||
|
// keep payload.WLogo/BLogo as string if client sends path
|
||||||
|
payload.WLogo = c.PostForm("w_logo")
|
||||||
|
payload.BLogo = c.PostForm("b_logo")
|
||||||
|
if v := c.PostForm("is_active"); v != "" {
|
||||||
|
if b, err := strconv.ParseBool(v); err == nil {
|
||||||
|
payload.IsActive = &b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// numeric metadata
|
||||||
|
if v := c.PostForm("w_width"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
payload.WWidth = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("w_height"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
payload.WHeight = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("w_quality"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
payload.WQuality = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
payload.WFormat = c.PostForm("w_format")
|
||||||
|
if v := c.PostForm("b_width"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
payload.BWidth = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("b_height"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
payload.BHeight = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("b_quality"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
payload.BQuality = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
payload.BFormat = c.PostForm("b_format")
|
||||||
|
} else {
|
||||||
|
// JSON
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// basic required validation
|
||||||
|
if payload.Title == "" || payload.MetaTitle == "" || payload.MetaDescription == "" || payload.Phone == "" || payload.URL == "" || payload.Email == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "missing required fields"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isActive := false
|
||||||
|
if payload.IsActive != nil {
|
||||||
|
isActive = *payload.IsActive
|
||||||
|
}
|
||||||
|
setting := models.Setting{
|
||||||
|
Title: payload.Title,
|
||||||
|
MetaTitle: payload.MetaTitle,
|
||||||
|
MetaDescription: payload.MetaDescription,
|
||||||
|
Phone: payload.Phone,
|
||||||
|
URL: payload.URL,
|
||||||
|
Email: payload.Email,
|
||||||
|
Facebook: payload.Facebook,
|
||||||
|
X: payload.X,
|
||||||
|
Instagram: payload.Instagram,
|
||||||
|
Whatsapp: payload.Whatsapp,
|
||||||
|
Pinterest: payload.Pinterest,
|
||||||
|
Linkedin: payload.Linkedin,
|
||||||
|
Slogan: payload.Slogan,
|
||||||
|
Address: payload.Address,
|
||||||
|
Copyright: payload.Copyright,
|
||||||
|
MapEmbed: payload.MapEmbed,
|
||||||
|
WLogo: payload.WLogo,
|
||||||
|
BLogo: payload.BLogo,
|
||||||
|
IsActive: isActive,
|
||||||
|
}
|
||||||
|
// optional image transform params
|
||||||
|
if payload.WWidth != nil {
|
||||||
|
setting.WWidth = *payload.WWidth
|
||||||
|
}
|
||||||
|
if payload.WHeight != nil {
|
||||||
|
setting.WHeight = *payload.WHeight
|
||||||
|
}
|
||||||
|
if payload.WQuality != nil {
|
||||||
|
setting.WQuality = *payload.WQuality
|
||||||
|
}
|
||||||
|
setting.WFormat = payload.WFormat
|
||||||
|
if payload.BWidth != nil {
|
||||||
|
setting.BWidth = *payload.BWidth
|
||||||
|
}
|
||||||
|
if payload.BHeight != nil {
|
||||||
|
setting.BHeight = *payload.BHeight
|
||||||
|
}
|
||||||
|
if payload.BQuality != nil {
|
||||||
|
setting.BQuality = *payload.BQuality
|
||||||
|
}
|
||||||
|
setting.BFormat = payload.BFormat
|
||||||
|
|
||||||
|
// Handle optional logo file uploads when multipart/form-data
|
||||||
|
if strings.HasPrefix(contentType, "multipart/form-data") {
|
||||||
|
// Support file upload on field name 'w_logo' (preferred) or fallback to provided path
|
||||||
|
if file, err := c.FormFile("w_logo"); err == nil {
|
||||||
|
uploadDir := filepath.Join("uploads", "logos")
|
||||||
|
_ = os.MkdirAll(uploadDir, os.ModePerm)
|
||||||
|
ext := filepath.Ext(file.Filename)
|
||||||
|
newName := "wlogo-" + strconv.FormatInt(time.Now().UnixNano(), 10) + ext
|
||||||
|
destination := filepath.Join(uploadDir, newName)
|
||||||
|
if err := c.SaveUploadedFile(file, destination); err == nil {
|
||||||
|
setting.WLogo = "/uploads/logos/" + newName
|
||||||
|
if setting.WFormat == "" && ext != "" {
|
||||||
|
setting.WFormat = ext[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Support file upload on field name 'b_logo'
|
||||||
|
if file, err := c.FormFile("b_logo"); err == nil {
|
||||||
|
uploadDir := filepath.Join("uploads", "logos")
|
||||||
|
_ = os.MkdirAll(uploadDir, os.ModePerm)
|
||||||
|
ext := filepath.Ext(file.Filename)
|
||||||
|
newName := "blogo-" + strconv.FormatInt(time.Now().UnixNano(), 10) + ext
|
||||||
|
destination := filepath.Join(uploadDir, newName)
|
||||||
|
if err := c.SaveUploadedFile(file, destination); err == nil {
|
||||||
|
setting.BLogo = "/uploads/logos/" + newName
|
||||||
|
if setting.BFormat == "" && ext != "" {
|
||||||
|
setting.BFormat = ext[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enforce single active setting rule
|
||||||
|
if setting.IsActive {
|
||||||
|
// Deactivate all other settings
|
||||||
|
if err := database.DB.Model(&models.Setting{}).Where("1 = 1").Update("is_active", false).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to deactivate other settings: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Create(&setting).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusCreated, gin.H{"data": setting})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminUpdateSetting godoc
|
||||||
|
// @Summary Admin: Update a setting
|
||||||
|
// @Description Update an existing setting
|
||||||
|
// @Tags settings
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept multipart/form-data
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Setting ID"
|
||||||
|
// @Param title formData string false "Title"
|
||||||
|
// @Param meta_title formData string false "Meta title"
|
||||||
|
// @Param meta_description formData string false "Meta description"
|
||||||
|
// @Param phone formData string false "Phone"
|
||||||
|
// @Param url formData string false "URL"
|
||||||
|
// @Param email formData string false "Email"
|
||||||
|
// @Param facebook formData string false "Facebook"
|
||||||
|
// @Param x formData string false "X"
|
||||||
|
// @Param instagram formData string false "Instagram"
|
||||||
|
// @Param whatsapp formData string false "Whatsapp"
|
||||||
|
// @Param pinterest formData string false "Pinterest"
|
||||||
|
// @Param linkedin formData string false "Linkedin"
|
||||||
|
// @Param slogan formData string false "Slogan"
|
||||||
|
// @Param address formData string false "Address"
|
||||||
|
// @Param copyright formData string false "Copyright"
|
||||||
|
// @Param map_embed formData string false "Map embed"
|
||||||
|
// @Param w_logo formData file false "White logo file upload (or provide w_logo path as string)"
|
||||||
|
// @Param b_logo formData file false "Black logo file upload (or provide b_logo path as string)"
|
||||||
|
// @Param is_active formData boolean false "Is active"
|
||||||
|
// @Param w_width formData int false "W logo width"
|
||||||
|
// @Param w_height formData int false "W logo height"
|
||||||
|
// @Param w_quality formData int false "W logo quality"
|
||||||
|
// @Param w_format formData string false "W logo format"
|
||||||
|
// @Param b_width formData int false "B logo width"
|
||||||
|
// @Param b_height formData int false "B logo height"
|
||||||
|
// @Param b_quality formData int false "B logo quality"
|
||||||
|
// @Param b_format formData string false "B logo format"
|
||||||
|
// @Success 200 {object} controllers.SettingResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/settings/{id} [put]
|
||||||
|
func AdminUpdateSetting(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var s models.Setting
|
||||||
|
if err := database.DB.First(&s, id).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "setting not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
contentType := c.GetHeader("Content-Type")
|
||||||
|
if strings.HasPrefix(contentType, "multipart/form-data") {
|
||||||
|
// read form fields and update if present
|
||||||
|
if v := c.PostForm("title"); v != "" {
|
||||||
|
s.Title = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("meta_title"); v != "" {
|
||||||
|
s.MetaTitle = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("meta_description"); v != "" {
|
||||||
|
s.MetaDescription = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("phone"); v != "" {
|
||||||
|
s.Phone = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("url"); v != "" {
|
||||||
|
s.URL = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("email"); v != "" {
|
||||||
|
s.Email = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("facebook"); v != "" {
|
||||||
|
s.Facebook = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("x"); v != "" {
|
||||||
|
s.X = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("instagram"); v != "" {
|
||||||
|
s.Instagram = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("whatsapp"); v != "" {
|
||||||
|
s.Whatsapp = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("pinterest"); v != "" {
|
||||||
|
s.Pinterest = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("linkedin"); v != "" {
|
||||||
|
s.Linkedin = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("slogan"); v != "" {
|
||||||
|
s.Slogan = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("address"); v != "" {
|
||||||
|
s.Address = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("copyright"); v != "" {
|
||||||
|
s.Copyright = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("map_embed"); v != "" {
|
||||||
|
s.MapEmbed = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("w_logo"); v != "" {
|
||||||
|
s.WLogo = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("b_logo"); v != "" {
|
||||||
|
s.BLogo = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("is_active"); v != "" {
|
||||||
|
if b, err := strconv.ParseBool(v); err == nil {
|
||||||
|
s.IsActive = b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("w_width"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
s.WWidth = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("w_height"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
s.WHeight = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("w_quality"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
s.WQuality = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("w_format"); v != "" {
|
||||||
|
s.WFormat = v
|
||||||
|
}
|
||||||
|
if v := c.PostForm("b_width"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
s.BWidth = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("b_height"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
s.BHeight = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("b_quality"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil {
|
||||||
|
s.BQuality = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v := c.PostForm("b_format"); v != "" {
|
||||||
|
s.BFormat = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle optional file uploads
|
||||||
|
if file, err := c.FormFile("w_logo"); err == nil {
|
||||||
|
uploadDir := filepath.Join("uploads", "logos")
|
||||||
|
_ = os.MkdirAll(uploadDir, os.ModePerm)
|
||||||
|
ext := filepath.Ext(file.Filename)
|
||||||
|
newName := "wlogo-" + strconv.FormatInt(time.Now().UnixNano(), 10) + ext
|
||||||
|
destination := filepath.Join(uploadDir, newName)
|
||||||
|
if err := c.SaveUploadedFile(file, destination); err == nil {
|
||||||
|
s.WLogo = "/uploads/logos/" + newName
|
||||||
|
if s.WFormat == "" && ext != "" {
|
||||||
|
s.WFormat = ext[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if file, err := c.FormFile("b_logo"); err == nil {
|
||||||
|
uploadDir := filepath.Join("uploads", "logos")
|
||||||
|
_ = os.MkdirAll(uploadDir, os.ModePerm)
|
||||||
|
ext := filepath.Ext(file.Filename)
|
||||||
|
newName := "blogo-" + strconv.FormatInt(time.Now().UnixNano(), 10) + ext
|
||||||
|
destination := filepath.Join(uploadDir, newName)
|
||||||
|
if err := c.SaveUploadedFile(file, destination); err == nil {
|
||||||
|
s.BLogo = "/uploads/logos/" + newName
|
||||||
|
if s.BFormat == "" && ext != "" {
|
||||||
|
s.BFormat = ext[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// JSON payload
|
||||||
|
var payload SettingPayload
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// update fields from payload
|
||||||
|
s.Title = payload.Title
|
||||||
|
s.MetaTitle = payload.MetaTitle
|
||||||
|
s.MetaDescription = payload.MetaDescription
|
||||||
|
s.Phone = payload.Phone
|
||||||
|
s.URL = payload.URL
|
||||||
|
s.Email = payload.Email
|
||||||
|
s.Facebook = payload.Facebook
|
||||||
|
s.X = payload.X
|
||||||
|
s.Instagram = payload.Instagram
|
||||||
|
s.Whatsapp = payload.Whatsapp
|
||||||
|
s.Pinterest = payload.Pinterest
|
||||||
|
s.Linkedin = payload.Linkedin
|
||||||
|
s.Slogan = payload.Slogan
|
||||||
|
s.Address = payload.Address
|
||||||
|
s.Copyright = payload.Copyright
|
||||||
|
s.MapEmbed = payload.MapEmbed
|
||||||
|
s.WLogo = payload.WLogo
|
||||||
|
s.BLogo = payload.BLogo
|
||||||
|
if payload.IsActive != nil {
|
||||||
|
s.IsActive = *payload.IsActive
|
||||||
|
}
|
||||||
|
if payload.WWidth != nil {
|
||||||
|
s.WWidth = *payload.WWidth
|
||||||
|
}
|
||||||
|
if payload.WHeight != nil {
|
||||||
|
s.WHeight = *payload.WHeight
|
||||||
|
}
|
||||||
|
if payload.WQuality != nil {
|
||||||
|
s.WQuality = *payload.WQuality
|
||||||
|
}
|
||||||
|
s.WFormat = payload.WFormat
|
||||||
|
if payload.BWidth != nil {
|
||||||
|
s.BWidth = *payload.BWidth
|
||||||
|
}
|
||||||
|
if payload.BHeight != nil {
|
||||||
|
s.BHeight = *payload.BHeight
|
||||||
|
}
|
||||||
|
if payload.BQuality != nil {
|
||||||
|
s.BQuality = *payload.BQuality
|
||||||
|
}
|
||||||
|
s.BFormat = payload.BFormat
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enforce single active setting rule
|
||||||
|
if s.IsActive {
|
||||||
|
// Deactivate all other settings except this one
|
||||||
|
if err := database.DB.Model(&models.Setting{}).Where("id != ?", s.ID).Update("is_active", false).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to deactivate other settings: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Save(&s).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": s})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminDeleteSetting godoc
|
||||||
|
// @Summary Admin: Delete a setting
|
||||||
|
// @Description Soft-delete a setting by ID
|
||||||
|
// @Tags settings
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Setting ID"
|
||||||
|
// @Success 200 {object} map[string]interface{}
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/settings/{id} [delete]
|
||||||
|
func AdminDeleteSetting(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var s models.Setting
|
||||||
|
if err := database.DB.First(&s, id).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "setting not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := database.DB.Delete(&s).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// attempt to remove logo files if present (safe: only under uploads/)
|
||||||
|
for _, p := range []string{s.WLogo, s.BLogo} {
|
||||||
|
if p == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
imgPath := strings.TrimPrefix(p, "/")
|
||||||
|
clean := filepath.Clean(imgPath)
|
||||||
|
if strings.HasPrefix(clean, "uploads"+string(os.PathSeparator)) {
|
||||||
|
_ = os.Remove(clean)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"message": "setting deleted successfully", "id": s.ID})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminRestoreSetting godoc
|
||||||
|
// @Summary Admin: Restore a soft-deleted setting
|
||||||
|
// @Description Restore a soft-deleted setting by ID
|
||||||
|
// @Tags settings
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "Setting ID"
|
||||||
|
// @Success 200 {object} controllers.SettingResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/settings/{id}/restore [post]
|
||||||
|
func AdminRestoreSetting(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var s models.Setting
|
||||||
|
// Find soft-deleted record using Unscoped
|
||||||
|
if err := database.DB.Unscoped().Where("id = ?", id).First(&s).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "setting not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// If DeletedAt is zero, record is not soft-deleted
|
||||||
|
if s.DeletedAt.Time.IsZero() {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "setting is not deleted"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Clear deleted_at (restore) using Unscoped Model to allow update on soft-deleted rows
|
||||||
|
res := database.DB.Unscoped().Model(&models.Setting{}).Where("id = ?", id).UpdateColumn("deleted_at", nil)
|
||||||
|
if res.Error != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": res.Error.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if res.RowsAffected == 0 {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "restore failed (no rows affected)"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Reload the record in normal scope to ensure DeletedAt is nil in struct
|
||||||
|
if err := database.DB.First(&s, id).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enforce single active setting rule if restored setting is active
|
||||||
|
if s.IsActive {
|
||||||
|
if err := database.DB.Model(&models.Setting{}).Where("id != ?", s.ID).Update("is_active", false).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to deactivate other settings: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": s})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSettings godoc
|
||||||
|
// @Summary Public: Get site settings
|
||||||
|
// @Description Return the active site setting (latest active). If none active, return latest setting.
|
||||||
|
// @Tags settings
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} controllers.SettingResponse
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/settings [get]
|
||||||
|
func GetSettings(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var s models.Setting
|
||||||
|
// Try to find active setting
|
||||||
|
if err := database.DB.Where("is_active = ?", true).Order("updated_at desc").First(&s).Error; err != nil {
|
||||||
|
// if not found, fallback to latest
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
if err2 := database.DB.Order("updated_at desc").First(&s).Error; err2 != nil {
|
||||||
|
if err2 == gorm.ErrRecordNotFound {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": nil})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err2.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": s})
|
||||||
|
}
|
||||||
374
app/controllers/UserControllers.go
Normal file
374
app/controllers/UserControllers.go
Normal file
@@ -0,0 +1,374 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
"goGin/app/middlewares"
|
||||||
|
utils "goGin/pkg/utis"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserResponse, kullanıcı verilerini güvenli bir şekilde döndürmek için
|
||||||
|
type UserResponse struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
UserName string `json:"username"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
EmailVerified bool `json:"email_verified"`
|
||||||
|
IsAdmin bool `json:"is_admin"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminUserListItem, admin listesinde deleted_at ile ayırt etmek için
|
||||||
|
type AdminUserListItem struct {
|
||||||
|
UserResponse
|
||||||
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserPayload, kullanıcı güncelleme payload'u
|
||||||
|
type UserPayload struct {
|
||||||
|
UserName string `json:"username"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Password string `json:"password,omitempty"` // Opsiyonel şifre güncellemesi
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminUserUpdatePayload, admin tarafından kullanıcı güncelleme
|
||||||
|
type AdminUserUpdatePayload struct {
|
||||||
|
UserName string `json:"username"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
IsAdmin *bool `json:"is_admin"` // Pointer allows checking if field is present
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to convert model to response
|
||||||
|
func toUserResponse(u models.User) UserResponse {
|
||||||
|
isAdmin := false
|
||||||
|
if u.IsAdmin != nil {
|
||||||
|
isAdmin = *u.IsAdmin
|
||||||
|
}
|
||||||
|
isVerified := false
|
||||||
|
if u.EmailVerified != nil {
|
||||||
|
isVerified = *u.EmailVerified
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserResponse{
|
||||||
|
ID: u.ID,
|
||||||
|
UserName: u.UserName,
|
||||||
|
Email: u.Email,
|
||||||
|
EmailVerified: isVerified,
|
||||||
|
IsAdmin: isAdmin,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// toAdminUserListItem, admin listesinde deleted_at döndürmek için
|
||||||
|
func toAdminUserListItem(u models.User) AdminUserListItem {
|
||||||
|
item := AdminUserListItem{UserResponse: toUserResponse(u)}
|
||||||
|
if u.DeletedAt.Valid {
|
||||||
|
item.DeletedAt = &u.DeletedAt.Time
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProfile godoc
|
||||||
|
// @Summary Get current user profile
|
||||||
|
// @Description Get profile of the logged-in user
|
||||||
|
// @Tags users
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} controllers.UserResponse
|
||||||
|
// @Failure 401 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/users/profile [get]
|
||||||
|
func GetProfile(c *gin.Context) {
|
||||||
|
claims, ok := middlewares.GetAuthClaims(c)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.Preload("SocialAccounts").Preload("Profile").First(&user, claims.UserID).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": toUserResponse(user)})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProfile godoc
|
||||||
|
// @Summary Update current user profile
|
||||||
|
// @Description Update profile of the logged-in user
|
||||||
|
// @Tags users
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param user body UserPayload true "User update payload"
|
||||||
|
// @Success 200 {object} controllers.UserResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/users/profile [put]
|
||||||
|
func UpdateProfile(c *gin.Context) {
|
||||||
|
claims, ok := middlewares.GetAuthClaims(c)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload UserPayload
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.First(&user, claims.UserID).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if payload.UserName != "" {
|
||||||
|
user.UserName = payload.UserName
|
||||||
|
}
|
||||||
|
if payload.Email != "" {
|
||||||
|
user.Email = payload.Email
|
||||||
|
// Email değişirse doğrulama sıfırlanabilir
|
||||||
|
f := false
|
||||||
|
user.EmailVerified = &f
|
||||||
|
}
|
||||||
|
if payload.Password != "" {
|
||||||
|
hashed, err := utils.HashPassword(payload.Password)
|
||||||
|
if err == nil {
|
||||||
|
user.Password = hashed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Save(&user).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": toUserResponse(user)})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminListUsers godoc
|
||||||
|
// @Summary Admin: List users
|
||||||
|
// @Description Admin listing of users with pagination and search
|
||||||
|
// @Tags users_admin
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param page query int false "Page number"
|
||||||
|
// @Param per_page query int false "Items per page"
|
||||||
|
// @Param q query string false "Search query (username or email)"
|
||||||
|
// @Param soft query string false "Soft delete filter: only|with"
|
||||||
|
// @Success 200 {object} map[string]interface{}
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/users [get]
|
||||||
|
func AdminListUsers(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database not configured"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pageStr := c.DefaultQuery("page", "1")
|
||||||
|
perPageStr := c.DefaultQuery("per_page", "20")
|
||||||
|
page, _ := strconv.Atoi(pageStr)
|
||||||
|
perPage, _ := strconv.Atoi(perPageStr)
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if perPage < 1 {
|
||||||
|
perPage = 20
|
||||||
|
}
|
||||||
|
if perPage > 100 {
|
||||||
|
perPage = 100
|
||||||
|
}
|
||||||
|
offset := (page - 1) * perPage
|
||||||
|
|
||||||
|
soft := c.Query("soft")
|
||||||
|
var query *gorm.DB
|
||||||
|
if soft == "only" {
|
||||||
|
query = database.DB.Unscoped().Model(&models.User{}).Where("deleted_at IS NOT NULL")
|
||||||
|
} else if soft == "with" {
|
||||||
|
query = database.DB.Unscoped().Model(&models.User{})
|
||||||
|
} else {
|
||||||
|
query = database.DB.Model(&models.User{})
|
||||||
|
}
|
||||||
|
|
||||||
|
if q := c.Query("q"); q != "" {
|
||||||
|
like := "%" + q + "%"
|
||||||
|
query = query.Where("user_name LIKE ? OR email LIKE ?", like, like)
|
||||||
|
}
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
if err := query.Count(&total).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var users []models.User
|
||||||
|
if err := query.Order("created_at desc").Limit(perPage).Offset(offset).Find(&users).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var data []AdminUserListItem
|
||||||
|
for _, u := range users {
|
||||||
|
data = append(data, toAdminUserListItem(u))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"items": data, "total": total, "page": page, "per_page": perPage})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminGetUser godoc
|
||||||
|
// @Summary Admin: Get user
|
||||||
|
// @Description Get user details by ID
|
||||||
|
// @Tags users_admin
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "User ID"
|
||||||
|
// @Success 200 {object} controllers.UserResponse
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/users/{id} [get]
|
||||||
|
func AdminGetUser(c *gin.Context) {
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
// Admin deleted kullanıcıyı da görebilmeli mi? Genelde evet, soft=with ile listede görüyorsa detayda da görmeli.
|
||||||
|
// Varsayılan olarak normal get soft-deleted getirmez. Unscoped kullanalım veya id ile direk bakalım.
|
||||||
|
if err := database.DB.Unscoped().First(&user, id).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": toUserResponse(user)})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminUpdateUser godoc
|
||||||
|
// @Summary Admin: Update user
|
||||||
|
// @Description Update user details (admin)
|
||||||
|
// @Tags users_admin
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "User ID"
|
||||||
|
// @Param user body AdminUserUpdatePayload true "User update payload"
|
||||||
|
// @Success 200 {object} controllers.UserResponse
|
||||||
|
// @Failure 400 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/users/{id} [put]
|
||||||
|
func AdminUpdateUser(c *gin.Context) {
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload AdminUserUpdatePayload
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.Unscoped().First(&user, id).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if payload.UserName != "" {
|
||||||
|
user.UserName = payload.UserName
|
||||||
|
}
|
||||||
|
if payload.Email != "" {
|
||||||
|
user.Email = payload.Email
|
||||||
|
}
|
||||||
|
if payload.IsAdmin != nil {
|
||||||
|
user.IsAdmin = payload.IsAdmin
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Save(&user).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": toUserResponse(user)})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminDeleteUser godoc
|
||||||
|
// @Summary Admin: Delete user
|
||||||
|
// @Description Soft delete user
|
||||||
|
// @Tags users_admin
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "User ID"
|
||||||
|
// @Success 200 {object} map[string]interface{}
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/users/{id} [delete]
|
||||||
|
func AdminDeleteUser(c *gin.Context) {
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.First(&user, id).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DB.Delete(&user).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"message": "user deleted successfully",
|
||||||
|
"id": user.ID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminRestoreUser godoc
|
||||||
|
// @Summary Admin: Restore user
|
||||||
|
// @Description Restore soft-deleted user
|
||||||
|
// @Tags users_admin
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path int true "User ID"
|
||||||
|
// @Success 200 {object} controllers.UserResponse
|
||||||
|
// @Failure 404 {object} map[string]string
|
||||||
|
// @Failure 500 {object} map[string]string
|
||||||
|
// @Router /api/v1/admin/users/{id}/restore [post]
|
||||||
|
func AdminRestoreUser(c *gin.Context) {
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := database.DB.Unscoped().First(&user, id).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "user not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.DeletedAt.Valid {
|
||||||
|
// Restore
|
||||||
|
if err := database.DB.Unscoped().Model(&user).Update("deleted_at", nil).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"data": toUserResponse(user)})
|
||||||
|
}
|
||||||
137
app/controllers/swagger_models.go
Normal file
137
app/controllers/swagger_models.go
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// Note: these structs are only used for Swagger documentation generation.
|
||||||
|
// They intentionally avoid embedding gorm.Model to keep swag parser happy.
|
||||||
|
|
||||||
|
type CategorySimple struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
Title string `json:"title" example:"News"`
|
||||||
|
Slug string `json:"slug" example:"news"`
|
||||||
|
ParentID *uint `json:"parent_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCategoryListItem admin listesinde deleted_at ile ayırt etmek için
|
||||||
|
type AdminCategoryListItem struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
Title string `json:"title" example:"News"`
|
||||||
|
Slug string `json:"slug" example:"news"`
|
||||||
|
ParentID *uint `json:"parent_id,omitempty"`
|
||||||
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TagSimple struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
Name string `json:"name" example:"golang"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminTagListItem admin listesinde deleted_at ile ayırt etmek için
|
||||||
|
type AdminTagListItem struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
Name string `json:"name" example:"golang"`
|
||||||
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PostResponse struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
Title string `json:"title" example:"My post title"`
|
||||||
|
Slug string `json:"slug" example:"my-post-title"`
|
||||||
|
Images string `json:"images"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
Categories []CategorySimple `json:"categories,omitempty"`
|
||||||
|
Tags []TagSimple `json:"tags,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PostListResponse struct {
|
||||||
|
Items []PostResponse `json:"items"`
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Page int `json:"page"`
|
||||||
|
PerPage int `json:"per_page"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// New swagger-only types
|
||||||
|
type CommentSimple struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
UserID uint `json:"user_id" example:"2"`
|
||||||
|
PostID uint `json:"post_id" example:"1"`
|
||||||
|
Body string `json:"body" example:"Nice post"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CategoryViewSimple struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
CategoryID uint `json:"category_id" example:"1"`
|
||||||
|
IPAddress string `json:"ip_address" example:"127.0.0.1"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting swagger-only types
|
||||||
|
type SettingResponse struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
Title string `json:"title" example:"Site Başlığı"`
|
||||||
|
MetaTitle string `json:"meta_title" example:"Meta Başlık"`
|
||||||
|
MetaDescription string `json:"meta_description" example:"Site açıklaması"`
|
||||||
|
Phone string `json:"phone" example:" +90 555 555 55 55"`
|
||||||
|
URL string `json:"url" example:"https://example.com"`
|
||||||
|
Email string `json:"email" example:"info@example.com"`
|
||||||
|
Facebook string `json:"facebook" example:"https://facebook.com/example"`
|
||||||
|
X string `json:"x" example:"https://x.com/example"`
|
||||||
|
Instagram string `json:"instagram" example:"https://instagram.com/example"`
|
||||||
|
Whatsapp string `json:"whatsapp" example:"https://wa.me/90555"`
|
||||||
|
Pinterest string `json:"pinterest" example:"https://pinterest.com/example"`
|
||||||
|
Linkedin string `json:"linkedin" example:"https://linkedin.com/company/example"`
|
||||||
|
Slogan string `json:"slogan" example:"En iyi içerik"`
|
||||||
|
Address string `json:"address" example:"Adres örneği"`
|
||||||
|
Copyright string `json:"copyright" example:"© 2026 Example"`
|
||||||
|
MapEmbed string `json:"map_embed"`
|
||||||
|
WLogo string `json:"w_logo"`
|
||||||
|
BLogo string `json:"b_logo"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
|
// image transform / metadata fields (match app/database/models/setting.go)
|
||||||
|
WWidth int `json:"w_width"`
|
||||||
|
WHeight int `json:"w_height"`
|
||||||
|
WQuality int `json:"w_quality"`
|
||||||
|
WFormat string `json:"w_format"`
|
||||||
|
BWidth int `json:"b_width"`
|
||||||
|
BHeight int `json:"b_height"`
|
||||||
|
BQuality int `json:"b_quality"`
|
||||||
|
BFormat string `json:"b_format"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SettingListResponse struct {
|
||||||
|
Items []SettingResponse `json:"items"`
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Page int `json:"page"`
|
||||||
|
PerPage int `json:"per_page"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hero swagger-only types
|
||||||
|
type HeroResponse struct {
|
||||||
|
ID uint `json:"id" example:"1"`
|
||||||
|
Color string `json:"color" example:"#ffffff"`
|
||||||
|
Title string `json:"title" example:"Hero Başlık"`
|
||||||
|
Text1 string `json:"text1" example:"Kısa açıklama"`
|
||||||
|
Text2 string `json:"text2" example:"İkinci metin"`
|
||||||
|
Text4 string `json:"text4" example:"Yardımcı metin"`
|
||||||
|
Text5 string `json:"text5" example:"Ek metin"`
|
||||||
|
Image string `json:"image" example:"/uploads/heroes/img.jpg"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
|
Width int `json:"width" example:"1920"`
|
||||||
|
Height int `json:"height" example:"1080"`
|
||||||
|
Quality int `json:"quality" example:"80"`
|
||||||
|
Format string `json:"format" example:"jpeg"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HeroListResponse struct {
|
||||||
|
Items []HeroResponse `json:"items"`
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Page int `json:"page"`
|
||||||
|
PerPage int `json:"per_page"`
|
||||||
|
}
|
||||||
39
app/database/config/mysql_db.go
Normal file
39
app/database/config/mysql_db.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
configs "goGin/config"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DB *gorm.DB
|
||||||
|
|
||||||
|
func ConnectDB() {
|
||||||
|
dsn := configs.AppConfig.DBUrl
|
||||||
|
if dsn == "" {
|
||||||
|
log.Println(".env dosyasında DB_URL ayarlı değil — veritabanı bağlantısı atlanıyor (geliştirme modu)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Yapılandırmada DB_URL bulundu, veritabanına bağlanılmaya çalışılıyor...")
|
||||||
|
|
||||||
|
// GORM için MySQL konfigürasyonu
|
||||||
|
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||||
|
Logger: logger.Default.LogMode(logger.Info), // Info seviyesi (performans etkileyebilir); üretimde Error seviyesine alınabilir
|
||||||
|
PrepareStmt: true, // PrepareStmt performansını artırmak için
|
||||||
|
NowFunc: func() time.Time {
|
||||||
|
return time.Now().UTC()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Println("MySQL veritabanı bağlantısı kurulamadı:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("MySQL bağlantısı Sağlandı.")
|
||||||
|
DB = db
|
||||||
|
}
|
||||||
108
app/database/config/redis_db.go
Normal file
108
app/database/config/redis_db.go
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
config "goGin/config"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var RedisClient *redis.Client
|
||||||
|
var RedisOptions *redis.Options
|
||||||
|
var ctx = context.Background()
|
||||||
|
|
||||||
|
func ConnectRedis() {
|
||||||
|
redisURL := config.AppConfig.RedisUrl
|
||||||
|
if redisURL == "" {
|
||||||
|
log.Println("Warning: REDIS_URL is not set, continuing without Redis cache")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
opt, err := redis.ParseURL(redisURL)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Failed to parse Redis URL: %v, continuing without Redis cache", err)
|
||||||
|
RedisOptions = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RedisOptions = opt
|
||||||
|
RedisClient = redis.NewClient(opt)
|
||||||
|
|
||||||
|
// Test connection
|
||||||
|
_, err = RedisClient.Ping(ctx).Result()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Failed to connect to Redis: %v, continuing without Redis cache", err)
|
||||||
|
RedisClient = nil
|
||||||
|
RedisOptions = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Redis Bağlatısı Sağlandı")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set stores a key-value pair in Redis with expiration
|
||||||
|
func Set(key string, value interface{}, expiration time.Duration) error {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return nil // Gracefully handle when Redis is not available
|
||||||
|
}
|
||||||
|
return RedisClient.Set(ctx, key, value, expiration).Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get retrieves a value from Redis
|
||||||
|
func Get(key string) (string, error) {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return "", redis.Nil // Return Nil error when Redis is not available
|
||||||
|
}
|
||||||
|
return RedisClient.Get(ctx, key).Result()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete removes a key from Redis
|
||||||
|
func Delete(key string) error {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return RedisClient.Del(ctx, key).Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exists checks if a key exists in Redis
|
||||||
|
func Exists(key string) (bool, error) {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
count, err := RedisClient.Exists(ctx, key).Result()
|
||||||
|
return count > 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWithJSON stores a JSON-serializable value in Redis
|
||||||
|
func SetEx(key string, value interface{}, seconds int) error {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return RedisClient.Set(ctx, key, value, time.Duration(seconds)*time.Second).Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment increments a counter in Redis
|
||||||
|
func Increment(key string) (int64, error) {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
return RedisClient.Incr(ctx, key).Result()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expire sets expiration time for a key
|
||||||
|
func Expire(key string, expiration time.Duration) error {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return RedisClient.Expire(ctx, key, expiration).Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FlushAll clears all keys in the current database
|
||||||
|
func FlushAll() error {
|
||||||
|
if RedisClient == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
log.Println("🧹 Clearing Redis Cache...")
|
||||||
|
return RedisClient.FlushDB(ctx).Err()
|
||||||
|
}
|
||||||
122
app/database/migrate/migrate.go
Normal file
122
app/database/migrate/migrate.go
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package migrasyon
|
||||||
|
|
||||||
|
import (
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
configs "goGin/config"
|
||||||
|
"log"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Only run AutoMigrate if DB is initialized
|
||||||
|
|
||||||
|
func Migrate() {
|
||||||
|
if database.DB != nil {
|
||||||
|
if err := database.DB.AutoMigrate(
|
||||||
|
&models.User{},
|
||||||
|
&models.SocialAccount{},
|
||||||
|
&models.Profile{},
|
||||||
|
&models.Hero{},
|
||||||
|
&models.Setting{},
|
||||||
|
&models.CorsWhitelist{},
|
||||||
|
&models.CorsBlacklist{},
|
||||||
|
&models.RateLimitSetting{},
|
||||||
|
&models.Category{},
|
||||||
|
&models.Tag{},
|
||||||
|
&models.Post{},
|
||||||
|
&models.CategoryView{},
|
||||||
|
&models.Comment{},
|
||||||
|
); err != nil {
|
||||||
|
log.Printf("AutoMigrate Yapılamadı !!: %v", err)
|
||||||
|
}
|
||||||
|
seedSecurityDefaults()
|
||||||
|
log.Println("AutoMigrate Yapıldı.")
|
||||||
|
} else {
|
||||||
|
log.Println("DB not initialized: skipping AutoMigrate")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func seedSecurityDefaults() {
|
||||||
|
seedRateLimit("register", "Register endpoint default rate limit", 5, 60)
|
||||||
|
seedRateLimit("login", "Login endpoint default rate limit", 10, 60)
|
||||||
|
|
||||||
|
for _, origin := range defaultWhitelistOrigins() {
|
||||||
|
seedCorsWhitelist(origin, "default seeded whitelist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func seedRateLimit(name, description string, maxRequests int64, windowSeconds int) {
|
||||||
|
var existing models.RateLimitSetting
|
||||||
|
if err := database.DB.Where("name = ?", name).First(&existing).Error; err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
item := models.RateLimitSetting{
|
||||||
|
Name: name,
|
||||||
|
Description: description,
|
||||||
|
MaxRequests: maxRequests,
|
||||||
|
WindowSeconds: windowSeconds,
|
||||||
|
IsActive: true,
|
||||||
|
UpdatedBy: "seed",
|
||||||
|
}
|
||||||
|
if err := database.DB.Create(&item).Error; err != nil {
|
||||||
|
log.Printf("RateLimit seed failed (%s): %v", name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("RateLimit seed created: name=%s max=%d window=%ds", name, maxRequests, windowSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
func seedCorsWhitelist(origin, description string) {
|
||||||
|
origin = strings.TrimSpace(origin)
|
||||||
|
if origin == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var existing models.CorsWhitelist
|
||||||
|
if err := database.DB.Where("origin = ?", origin).First(&existing).Error; err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
item := models.CorsWhitelist{
|
||||||
|
Origin: origin,
|
||||||
|
Description: description,
|
||||||
|
IsActive: true,
|
||||||
|
CreatedBy: "seed",
|
||||||
|
}
|
||||||
|
if err := database.DB.Create(&item).Error; err != nil {
|
||||||
|
log.Printf("CorsWhitelist seed failed (%s): %v", origin, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("CorsWhitelist seed created: origin=%s", origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultWhitelistOrigins() []string {
|
||||||
|
origins := []string{
|
||||||
|
"http://localhost:3000",
|
||||||
|
"http://localhost:5173",
|
||||||
|
"http://localhost:8080",
|
||||||
|
}
|
||||||
|
|
||||||
|
appURL := strings.TrimSpace(configs.AppConfig.AppURL)
|
||||||
|
if appURL != "" {
|
||||||
|
if parsed, err := url.Parse(appURL); err == nil && parsed.Scheme != "" && parsed.Host != "" {
|
||||||
|
origins = append(origins, parsed.Scheme+"://"+parsed.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uniq := make(map[string]struct{})
|
||||||
|
out := make([]string, 0, len(origins))
|
||||||
|
for _, origin := range origins {
|
||||||
|
origin = strings.TrimSpace(origin)
|
||||||
|
if origin == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := uniq[origin]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
uniq[origin] = struct{}{}
|
||||||
|
out = append(out, origin)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
51
app/database/models/blog.go
Normal file
51
app/database/models/blog.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Minimal, temiz GORM modelleri
|
||||||
|
|
||||||
|
type Category struct {
|
||||||
|
gorm.Model
|
||||||
|
Title string `gorm:"type:varchar(254);not null" json:"title"`
|
||||||
|
Slug string `gorm:"type:varchar(254);not null;uniqueIndex" json:"slug"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
ParentID *uint `json:"parent_id,omitempty"`
|
||||||
|
Parent *Category `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;foreignKey:ParentID" json:"parent,omitempty"`
|
||||||
|
Children []Category `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
||||||
|
Posts []Post `gorm:"many2many:post_categories;" json:"posts,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string `gorm:"type:varchar(254);not null" json:"name"`
|
||||||
|
Posts []Post `gorm:"many2many:post_tags;" json:"posts,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Post struct {
|
||||||
|
gorm.Model
|
||||||
|
Title string `gorm:"type:varchar(254);not null" json:"title"`
|
||||||
|
Images string `gorm:"type:text;not null" json:"images"`
|
||||||
|
Content string `gorm:"type:text" json:"content,omitempty"`
|
||||||
|
Slug string `gorm:"type:varchar(254);not null;uniqueIndex" json:"slug"`
|
||||||
|
Categories []Category `gorm:"many2many:post_categories;" json:"categories,omitempty"`
|
||||||
|
Tags []Tag `gorm:"many2many:post_tags;" json:"tags,omitempty"`
|
||||||
|
Width int `gorm:"default:0" json:"width" form:"width"`
|
||||||
|
Height int `gorm:"default:0" json:"height" form:"height"`
|
||||||
|
Quality int `gorm:"default:0" json:"quality" form:"quality"`
|
||||||
|
Format string `gorm:"type:varchar(10)" json:"format" form:"format"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CategoryView struct {
|
||||||
|
gorm.Model
|
||||||
|
CategoryID uint `json:"category_id"`
|
||||||
|
IPAddress string `gorm:"type:varchar(45)" json:"ip_address,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Comment struct {
|
||||||
|
gorm.Model
|
||||||
|
UserID uint `json:"user_id"`
|
||||||
|
PostID uint `json:"post_id"`
|
||||||
|
Body string `gorm:"type:text" json:"body,omitempty"`
|
||||||
|
}
|
||||||
34
app/database/models/cors.go
Normal file
34
app/database/models/cors.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CorsWhitelist - CORS için izin verilen origin'ler
|
||||||
|
type CorsWhitelist struct {
|
||||||
|
gorm.Model
|
||||||
|
Origin string `gorm:"type:varchar(255);uniqueIndex;not null" json:"origin"`
|
||||||
|
Description string `gorm:"type:varchar(255)" json:"description"`
|
||||||
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||||
|
CreatedBy string `gorm:"type:varchar(255)" json:"created_by,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CorsBlacklist - CORS için yasaklanan origin'ler
|
||||||
|
type CorsBlacklist struct {
|
||||||
|
gorm.Model
|
||||||
|
Origin string `gorm:"type:varchar(255);uniqueIndex;not null" json:"origin"`
|
||||||
|
Reason string `gorm:"type:varchar(255)" json:"reason"`
|
||||||
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||||
|
CreatedBy string `gorm:"type:varchar(255)" json:"created_by,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RateLimitSetting - Rate limit ayarları
|
||||||
|
type RateLimitSetting struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string `gorm:"type:varchar(100);uniqueIndex;not null" json:"name"` // e.g., "login", "register", "api"
|
||||||
|
Description string `gorm:"type:varchar(255)" json:"description"`
|
||||||
|
MaxRequests int64 `gorm:"not null" json:"max_requests"` // Max istek sayısı
|
||||||
|
WindowSeconds int `gorm:"not null" json:"window_seconds"` // Zaman penceresi (saniye)
|
||||||
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||||
|
UpdatedBy string `gorm:"type:varchar(255)" json:"updated_by,omitempty"`
|
||||||
|
}
|
||||||
23
app/database/models/hero.go
Normal file
23
app/database/models/hero.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Banner model structure
|
||||||
|
// Represents a banner item with optional thumbnail.
|
||||||
|
type Hero struct {
|
||||||
|
gorm.Model
|
||||||
|
Color string `gorm:"type:varchar(32);not null" json:"color" form:"color"`
|
||||||
|
Title string `gorm:"type:varchar(254)" json:"title,omitempty" form:"title"`
|
||||||
|
Text1 string `gorm:"type:varchar(254)" json:"text1,omitempty" form:"text1"`
|
||||||
|
Text2 string `gorm:"type:varchar(254)" json:"text2,omitempty" form:"text2"`
|
||||||
|
Text4 string `gorm:"type:varchar(254)" json:"text4,omitempty" form:"text4"`
|
||||||
|
Text5 string `gorm:"type:varchar(254)" json:"text5,omitempty" form:"text5"`
|
||||||
|
Image string `gorm:"type:varchar(254)" json:"image" form:"image"`
|
||||||
|
IsActive bool `gorm:"default:true" json:"is_active" form:"is_active"`
|
||||||
|
Width int `gorm:"default:0" json:"width" form:"width"`
|
||||||
|
Height int `gorm:"default:0" json:"height" form:"height"`
|
||||||
|
Quality int `gorm:"default:0" json:"quality" form:"quality"`
|
||||||
|
Format string `gorm:"type:varchar(10)" json:"format" form:"format"`
|
||||||
|
}
|
||||||
43
app/database/models/setting.go
Normal file
43
app/database/models/setting.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Setting model structure
|
||||||
|
// Stores site-wide metadata and contact information.
|
||||||
|
type Setting struct {
|
||||||
|
gorm.Model
|
||||||
|
Title string `gorm:"type:varchar(254);not null" json:"title" form:"title"`
|
||||||
|
MetaTitle string `gorm:"type:varchar(254);not null" json:"meta_title" form:"meta_title"`
|
||||||
|
MetaDescription string `gorm:"type:varchar(254);not null" json:"meta_description" form:"meta_description"`
|
||||||
|
Phone string `gorm:"type:varchar(254);not null" json:"phone" form:"phone"`
|
||||||
|
URL string `gorm:"type:varchar(254);not null" json:"url" form:"url"`
|
||||||
|
Email string `gorm:"type:varchar(254);not null" json:"email" form:"email"`
|
||||||
|
Facebook string `gorm:"type:varchar(254)" json:"facebook,omitempty" form:"facebook"`
|
||||||
|
X string `gorm:"type:varchar(254)" json:"x,omitempty" form:"x"`
|
||||||
|
Instagram string `gorm:"type:varchar(254)" json:"instagram,omitempty" form:"instagram"`
|
||||||
|
Whatsapp string `gorm:"type:varchar(254)" json:"whatsapp,omitempty" form:"whatsapp"`
|
||||||
|
Pinterest string `gorm:"type:varchar(254)" json:"pinterest,omitempty" form:"pinterest"`
|
||||||
|
Linkedin string `gorm:"type:varchar(254)" json:"linkedin,omitempty" form:"linkedin"`
|
||||||
|
Slogan string `gorm:"type:varchar(254)" json:"slogan,omitempty" form:"slogan"`
|
||||||
|
Address string `gorm:"type:text" json:"address,omitempty" form:"address"`
|
||||||
|
Copyright string `gorm:"type:varchar(254)" json:"copyright,omitempty" form:"copyright"`
|
||||||
|
MapEmbed string `gorm:"type:text" json:"map_embed,omitempty" form:"map_embed"`
|
||||||
|
WLogo string `gorm:"type:text" json:"w_logo,omitempty" form:"w_logo"`
|
||||||
|
BLogo string `gorm:"type:text" json:"b_logo,omitempty" form:"b_logo"`
|
||||||
|
IsActive bool `gorm:"default:false" json:"is_active" form:"is_active"`
|
||||||
|
WWidth int `gorm:"default:0" json:"w_width" form:"w_width"`
|
||||||
|
WHeight int `gorm:"default:0" json:"w_height" form:"w_height"`
|
||||||
|
WQuality int `gorm:"default:0" json:"w_quality" form:"w_quality"`
|
||||||
|
WFormat string `gorm:"type:varchar(10)" json:"w_format" form:"w_format"`
|
||||||
|
BWidth int `gorm:"default:0" json:"b_width" form:"b_width"`
|
||||||
|
BHeight int `gorm:"default:0" json:"b_height" form:"b_height"`
|
||||||
|
BQuality int `gorm:"default:0" json:"b_quality" form:"b_quality"`
|
||||||
|
BFormat string `gorm:"type:varchar(10)" json:"b_format" form:"b_format"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName overrides the table name used by Setting to `settings`
|
||||||
|
func (Setting) TableName() string {
|
||||||
|
return "settings"
|
||||||
|
}
|
||||||
51
app/database/models/user.go
Normal file
51
app/database/models/user.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
ID uint `gorm:"primarykey" json:"id"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
||||||
|
UserName string `json:"username" gorm:"type:varchar(255)"`
|
||||||
|
Email string `gorm:"uniqueIndex;not null;type:varchar(255)" json:"email"`
|
||||||
|
Password string `json:"-" gorm:"type:varchar(255)"` // Password shouldn't be returned in JSON
|
||||||
|
EmailVerified *bool `gorm:"default:false" json:"email_verified"` // default false for email/password registration
|
||||||
|
EmailVerifyToken string `gorm:"index;type:varchar(255)" json:"-"`
|
||||||
|
EmailVerifiedAt *time.Time `json:"email_verified_at,omitempty"`
|
||||||
|
IsAdmin *bool `gorm:"default:false" json:"is_admin"`
|
||||||
|
SocialAccounts []SocialAccount `gorm:"foreignKey:UserID" json:"social_accounts,omitempty"`
|
||||||
|
Profile []Profile `gorm:"foreignKey:UserID" json:"profiles,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Email Veriyf i False Döndürüyor
|
||||||
|
func (u *User) IsEmailVerified() bool {
|
||||||
|
if u.EmailVerified == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *u.EmailVerified
|
||||||
|
}
|
||||||
|
|
||||||
|
// SocialAccount model structure
|
||||||
|
type SocialAccount struct {
|
||||||
|
gorm.Model
|
||||||
|
UserID uint64 `gorm:"type:bigint unsigned;not null;index" json:"user_id"`
|
||||||
|
Provider string `gorm:"not null" json:"provider"` // google, github
|
||||||
|
ProviderID string `gorm:"not null" json:"provider_id"`
|
||||||
|
Email string `json:"email" gorm:"type:varchar(255)"`
|
||||||
|
Name string `json:"name,omitempty" gorm:"type:varchar(255)"` // Full name from provider
|
||||||
|
AvatarURL string `json:"avatar_url,omitempty" gorm:"type:varchar(255)"` // Avatar URL from provider
|
||||||
|
|
||||||
|
}
|
||||||
|
type Profile struct {
|
||||||
|
gorm.Model
|
||||||
|
UserID uint64 `gorm:"type:bigint unsigned;not null;index" json:"user_id"`
|
||||||
|
AvatarURL string `json:"avatar_url,omitempty" gorm:"type:varchar(255)"` // Avatar URL from provider
|
||||||
|
FirstName string `json:"first_name" gorm:"type:varchar(255)"` // Full name from provider
|
||||||
|
LastName string `json:"last_name" gorm:"type:varchar(255)"` // Full name from provider
|
||||||
|
|
||||||
|
}
|
||||||
119
app/database/seed/seed.go
Normal file
119
app/database/seed/seed.go
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
package seed
|
||||||
|
|
||||||
|
import (
|
||||||
|
"goGin/app/database/models"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
dbconfig "goGin/app/database/config"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SeedDefaultSettings() {
|
||||||
|
// Seed default CORS whitelist
|
||||||
|
var whitelistCount int64
|
||||||
|
dbconfig.DB.Model(&models.CorsWhitelist{}).Count(&whitelistCount)
|
||||||
|
|
||||||
|
if whitelistCount == 0 {
|
||||||
|
defaultWhitelist := []models.CorsWhitelist{
|
||||||
|
{
|
||||||
|
Origin: "http://localhost:3000",
|
||||||
|
Description: "Default local frontend",
|
||||||
|
IsActive: true,
|
||||||
|
CreatedBy: "system",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Origin: "http://localhost:8080",
|
||||||
|
Description: "Backend self",
|
||||||
|
IsActive: true,
|
||||||
|
CreatedBy: "system",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, w := range defaultWhitelist {
|
||||||
|
dbconfig.DB.Create(&w)
|
||||||
|
}
|
||||||
|
log.Println("Default CORS whitelist seeded")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seed default rate limit settings
|
||||||
|
var rateLimitCount int64
|
||||||
|
dbconfig.DB.Model(&models.RateLimitSetting{}).Count(&rateLimitCount)
|
||||||
|
|
||||||
|
if rateLimitCount == 0 {
|
||||||
|
defaultRateLimits := []models.RateLimitSetting{
|
||||||
|
{
|
||||||
|
Name: "login",
|
||||||
|
Description: "Login endpoint rate limit",
|
||||||
|
MaxRequests: 5,
|
||||||
|
WindowSeconds: 60, // 1 minute
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "register",
|
||||||
|
Description: "Registration endpoint rate limit",
|
||||||
|
MaxRequests: 3,
|
||||||
|
WindowSeconds: 300, // 5 minutes
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "api",
|
||||||
|
Description: "General API rate limit",
|
||||||
|
MaxRequests: 100,
|
||||||
|
WindowSeconds: 60, // 1 minute
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range defaultRateLimits {
|
||||||
|
dbconfig.DB.Create(&r)
|
||||||
|
}
|
||||||
|
log.Println("Default rate limit settings seeded")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SeedDefaultAdmin creates the default admin user if it doesn't exist
|
||||||
|
func SeedDefaultAdmin() {
|
||||||
|
// Check if admin user already exists (including soft-deleted)
|
||||||
|
var adminUser models.User
|
||||||
|
err := dbconfig.DB.Unscoped().Where("email = ?", "admin@gauth.local").First(&adminUser).Error
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
// Admin user doesn't exist, create one
|
||||||
|
// Hash default password: "Admin@123"
|
||||||
|
hashedPassword, err := bcrypt.GenerateFromPassword([]byte("Admin@123"), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to hash admin password: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
trueBool := true
|
||||||
|
adminUser = models.User{
|
||||||
|
Email: "admin@gauth.local",
|
||||||
|
UserName: "admin",
|
||||||
|
Password: string(hashedPassword),
|
||||||
|
EmailVerified: &trueBool,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := dbconfig.DB.Create(&adminUser).Error; err != nil {
|
||||||
|
log.Printf("Failed to create admin user: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("✅ Default admin user created:")
|
||||||
|
log.Println(" Email: admin@gauth.local")
|
||||||
|
log.Println(" Password: Admin@123")
|
||||||
|
log.Println(" ⚠️ Please change this password after first login!")
|
||||||
|
} else {
|
||||||
|
// Admin user exists (possibly soft-deleted)
|
||||||
|
if adminUser.DeletedAt.Valid {
|
||||||
|
log.Println("Restoring deleted admin user...")
|
||||||
|
if err := dbconfig.DB.Model(&adminUser).Unscoped().Update("deleted_at", nil).Error; err != nil {
|
||||||
|
log.Printf("Failed to restore admin user: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Admin rolü eklenmesi kaldırıldı çünkü Role modeli yok
|
||||||
|
}
|
||||||
91
app/middlewares/auth_middleware.go
Normal file
91
app/middlewares/auth_middleware.go
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package middlewares
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
configs "goGin/config"
|
||||||
|
"goGin/app/services"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
const authClaimsKey = "auth_claims"
|
||||||
|
|
||||||
|
func RequireAuth(c *gin.Context) {
|
||||||
|
authHeader := strings.TrimSpace(c.GetHeader("Authorization"))
|
||||||
|
if authHeader == "" {
|
||||||
|
authLogf("auth: missing Authorization header path=%s", c.Request.URL.Path)
|
||||||
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "authorization header is required"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.SplitN(authHeader, " ", 2)
|
||||||
|
if len(parts) != 2 || !strings.EqualFold(parts[0], "Bearer") || strings.TrimSpace(parts[1]) == "" {
|
||||||
|
authLogf("auth: invalid authorization format path=%s header=%s", c.Request.URL.Path, authHeader)
|
||||||
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid authorization format, expected: Bearer <token>"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
jwtService := services.NewJWTService()
|
||||||
|
claims, err := jwtService.ValidateToken(strings.TrimSpace(parts[1]))
|
||||||
|
if err != nil {
|
||||||
|
authLogf("auth: invalid token path=%s error=%v", c.Request.URL.Path, err)
|
||||||
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if claims.TokenType != services.TokenTypeAccess {
|
||||||
|
authLogf("auth: non-access token used path=%s token_type=%s", c.Request.URL.Path, claims.TokenType)
|
||||||
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "access token required"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Set(authClaimsKey, claims)
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RequireAdmin(c *gin.Context) {
|
||||||
|
claims, ok := GetAuthClaims(c)
|
||||||
|
if !ok {
|
||||||
|
authLogf("auth: RequireAdmin missing claims path=%s", c.Request.URL.Path)
|
||||||
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !claims.IsAdmin {
|
||||||
|
authLogf("auth: RequireAdmin forbidden path=%s user_id=%v", c.Request.URL.Path, claims.UserID)
|
||||||
|
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "admin role required"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RequireNormalUser(c *gin.Context) {
|
||||||
|
claims, ok := GetAuthClaims(c)
|
||||||
|
if !ok {
|
||||||
|
authLogf("auth: RequireNormalUser missing claims path=%s", c.Request.URL.Path)
|
||||||
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if claims.IsAdmin {
|
||||||
|
authLogf("auth: RequireNormalUser forbidden (admin tried to access) path=%s user_id=%v", c.Request.URL.Path, claims.UserID)
|
||||||
|
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "only normal users can access this endpoint"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAuthClaims(c *gin.Context) (*services.JWTClaim, bool) {
|
||||||
|
raw, exists := c.Get(authClaimsKey)
|
||||||
|
if !exists {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
claims, ok := raw.(*services.JWTClaim)
|
||||||
|
return claims, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func authLogf(format string, args ...interface{}) {
|
||||||
|
if configs.AppConfig != nil && configs.AppConfig.Debug {
|
||||||
|
log.Printf(format, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
154
app/middlewares/dynamic_cors.go
Normal file
154
app/middlewares/dynamic_cors.go
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
package middlewares
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
configs "goGin/config"
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
corsWhitelistActiveCacheKey = "cors:active:whitelist"
|
||||||
|
corsBlacklistActiveCacheKey = "cors:active:blacklist"
|
||||||
|
corsCacheTTLSeconds = 60
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
allowedMethods = "GET,POST,PUT,PATCH,DELETE,OPTIONS"
|
||||||
|
allowedHeaders = "Authorization,Content-Type,Accept,Origin,X-Requested-With"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DynamicCORS validates request Origin using DB-backed whitelist/blacklist with Redis caching.
|
||||||
|
func DynamicCORS() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
origin := strings.TrimSpace(c.GetHeader("Origin"))
|
||||||
|
if origin == "" {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if database.DB == nil {
|
||||||
|
corsLogf("[cors][skip] database unavailable origin=%s path=%s", origin, c.Request.URL.Path)
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
originKey := strings.ToLower(origin)
|
||||||
|
// Keep same-origin requests working even if DB entries are missing.
|
||||||
|
if origin == requestBaseURL(c) {
|
||||||
|
corsLogf("[cors][allow] same-origin origin=%s path=%s", origin, c.Request.URL.Path)
|
||||||
|
setCORSHeaders(c, origin)
|
||||||
|
if c.Request.Method == http.MethodOptions {
|
||||||
|
c.AbortWithStatus(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
blacklist, err := loadActiveOriginSet(corsBlacklistActiveCacheKey, true)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "cors blacklist lookup failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if blacklist[originKey] {
|
||||||
|
log.Printf("[cors][blocked] blacklist origin=%s path=%s", origin, c.Request.URL.Path)
|
||||||
|
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "origin is blocked by CORS policy"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
whitelist, err := loadActiveOriginSet(corsWhitelistActiveCacheKey, false)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "cors whitelist lookup failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !whitelist[originKey] {
|
||||||
|
log.Printf("[cors][blocked] not-whitelisted origin=%s path=%s", origin, c.Request.URL.Path)
|
||||||
|
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "origin is not allowed by CORS policy"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
corsLogf("[cors][allow] origin=%s path=%s", origin, c.Request.URL.Path)
|
||||||
|
setCORSHeaders(c, origin)
|
||||||
|
if c.Request.Method == http.MethodOptions {
|
||||||
|
c.AbortWithStatus(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setCORSHeaders(c *gin.Context, origin string) {
|
||||||
|
c.Header("Vary", "Origin")
|
||||||
|
c.Header("Access-Control-Allow-Origin", origin)
|
||||||
|
c.Header("Access-Control-Allow-Methods", allowedMethods)
|
||||||
|
c.Header("Access-Control-Allow-Headers", allowedHeaders)
|
||||||
|
c.Header("Access-Control-Allow-Credentials", "true")
|
||||||
|
c.Header("Access-Control-Max-Age", "600")
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestBaseURL(c *gin.Context) string {
|
||||||
|
scheme := c.Request.Header.Get("X-Forwarded-Proto")
|
||||||
|
if scheme == "" {
|
||||||
|
if c.Request.TLS != nil {
|
||||||
|
scheme = "https"
|
||||||
|
} else {
|
||||||
|
scheme = "http"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return scheme + "://" + c.Request.Host
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadActiveOriginSet(cacheKey string, isBlacklist bool) (map[string]bool, error) {
|
||||||
|
out := make(map[string]bool)
|
||||||
|
|
||||||
|
if cached, err := database.Get(cacheKey); err == nil {
|
||||||
|
corsLogf("[cors][cache-hit] key=%s", cacheKey)
|
||||||
|
var origins []string
|
||||||
|
if jsonErr := json.Unmarshal([]byte(cached), &origins); jsonErr == nil {
|
||||||
|
for _, origin := range origins {
|
||||||
|
out[strings.ToLower(strings.TrimSpace(origin))] = true
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
} else if !errors.Is(err, redis.Nil) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
corsLogf("[cors][cache-miss] key=%s", cacheKey)
|
||||||
|
|
||||||
|
var origins []string
|
||||||
|
var dbErr error
|
||||||
|
if isBlacklist {
|
||||||
|
dbErr = database.DB.Model(&models.CorsBlacklist{}).
|
||||||
|
Where("is_active = ?", true).
|
||||||
|
Pluck("origin", &origins).Error
|
||||||
|
} else {
|
||||||
|
dbErr = database.DB.Model(&models.CorsWhitelist{}).
|
||||||
|
Where("is_active = ?", true).
|
||||||
|
Pluck("origin", &origins).Error
|
||||||
|
}
|
||||||
|
if dbErr != nil {
|
||||||
|
return nil, dbErr
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, origin := range origins {
|
||||||
|
out[strings.ToLower(strings.TrimSpace(origin))] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheBytes, _ := json.Marshal(origins)
|
||||||
|
_ = database.SetEx(cacheKey, string(cacheBytes), corsCacheTTLSeconds)
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func corsLogf(format string, args ...interface{}) {
|
||||||
|
if configs.AppConfig != nil && (configs.AppConfig.Debug || configs.AppConfig.CorsDebug) {
|
||||||
|
log.Printf(format, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
128
app/middlewares/rate_limit.go
Normal file
128
app/middlewares/rate_limit.go
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
package middlewares
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
configs "goGin/config"
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type rateLimitRuntime struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
MaxRequests int64 `json:"max_requests"`
|
||||||
|
WindowSeconds int `json:"window_seconds"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RequireRateLimit applies Redis-backed per-IP rate limiting by setting name.
|
||||||
|
func RequireRateLimit(name string, fallbackMax int64, fallbackWindowSeconds int) gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
if database.DB == nil {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setting, err := loadRateLimitRuntime(name, fallbackMax, fallbackWindowSeconds)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "rate limit configuration error"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !setting.IsActive {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if database.RedisClient == nil {
|
||||||
|
rateLimitLogf("[rate-limit][warn] redis unavailable, skipping enforcement name=%s", setting.Name)
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ip := strings.TrimSpace(c.ClientIP())
|
||||||
|
if ip == "" {
|
||||||
|
ip = "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
counterKey := fmt.Sprintf("ratelimit:%s:%s", setting.Name, ip)
|
||||||
|
count, err := database.RedisClient.Incr(context.Background(), counterKey).Result()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "rate limit check failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if count == 1 {
|
||||||
|
_ = database.RedisClient.Expire(context.Background(), counterKey, time.Duration(setting.WindowSeconds)*time.Second).Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
if count > setting.MaxRequests {
|
||||||
|
ttl, _ := database.RedisClient.TTL(context.Background(), counterKey).Result()
|
||||||
|
retryAfter := int(ttl.Seconds())
|
||||||
|
if retryAfter < 1 {
|
||||||
|
retryAfter = setting.WindowSeconds
|
||||||
|
}
|
||||||
|
c.Header("Retry-After", strconv.Itoa(retryAfter))
|
||||||
|
log.Printf("[rate-limit][blocked] name=%s ip=%s count=%d max=%d window=%ds", setting.Name, ip, count, setting.MaxRequests, setting.WindowSeconds)
|
||||||
|
c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{
|
||||||
|
"error": "too many requests",
|
||||||
|
"retry_after": retryAfter,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rateLimitLogf("[rate-limit][allow] name=%s ip=%s count=%d max=%d window=%ds", setting.Name, ip, count, setting.MaxRequests, setting.WindowSeconds)
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadRateLimitRuntime(name string, fallbackMax int64, fallbackWindowSeconds int) (*rateLimitRuntime, error) {
|
||||||
|
cacheKey := "ratelimit:setting:" + name
|
||||||
|
if cached, err := database.Get(cacheKey); err == nil {
|
||||||
|
var s rateLimitRuntime
|
||||||
|
if jsonErr := json.Unmarshal([]byte(cached), &s); jsonErr == nil {
|
||||||
|
return &s, nil
|
||||||
|
}
|
||||||
|
} else if !errors.Is(err, redis.Nil) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
setting := &rateLimitRuntime{
|
||||||
|
Name: name,
|
||||||
|
MaxRequests: fallbackMax,
|
||||||
|
WindowSeconds: fallbackWindowSeconds,
|
||||||
|
IsActive: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
var dbSetting models.RateLimitSetting
|
||||||
|
if err := database.DB.Where("name = ?", name).First(&dbSetting).Error; err != nil {
|
||||||
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rateLimitLogf("[rate-limit][config] setting=%s not found, using fallback max=%d window=%ds", name, fallbackMax, fallbackWindowSeconds)
|
||||||
|
} else {
|
||||||
|
setting.MaxRequests = dbSetting.MaxRequests
|
||||||
|
setting.WindowSeconds = dbSetting.WindowSeconds
|
||||||
|
setting.IsActive = dbSetting.IsActive
|
||||||
|
rateLimitLogf("[rate-limit][config] loaded from db name=%s active=%t max=%d window=%ds", name, setting.IsActive, setting.MaxRequests, setting.WindowSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheJSON, _ := json.Marshal(setting)
|
||||||
|
_ = database.SetEx(cacheKey, string(cacheJSON), 60)
|
||||||
|
|
||||||
|
return setting, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func rateLimitLogf(format string, args ...interface{}) {
|
||||||
|
if configs.AppConfig != nil && (configs.AppConfig.Debug || configs.AppConfig.CorsDebug) {
|
||||||
|
log.Printf(format, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
150
app/routes/router.go
Normal file
150
app/routes/router.go
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"goGin/app/controllers"
|
||||||
|
"goGin/app/middlewares"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Böylece Gin artık “tüm proxy’lere güveniyorum” modundan çıktı, uyarı gidecek ve IP/scheme güvenliği artmış olacak.
|
||||||
|
// İleride reverse proxy arkası deploy yaparsan, SetTrustedProxies(nil)
|
||||||
|
// satırını kendi proxy IP / CIDR’larınla değiştirebiliriz.
|
||||||
|
func SetupRouter() *gin.Engine {
|
||||||
|
r := gin.Default()
|
||||||
|
// Güvenli varsayılan: hiçbir proxy'ye güvenme (lokal geliştirme ve basit deploy'lar için ideal).
|
||||||
|
// İleride reverse proxy arkasına alırsan, ilgili IP/CIDR bloklarını burada SetTrustedProxies ile tanımlayabilirsin.
|
||||||
|
if err := r.SetTrustedProxies(nil); err != nil {
|
||||||
|
log.Fatalf("failed to set trusted proxies: %v", err)
|
||||||
|
}
|
||||||
|
r.Use(middlewares.DynamicCORS())
|
||||||
|
r.Use(middlewares.RequireRateLimit("global", 100, 60))
|
||||||
|
// Uploads klasörünü statik olarak dışarı açıyoruz
|
||||||
|
r.Static("/uploads", "./uploads")
|
||||||
|
|
||||||
|
api := r.Group("/api/v1")
|
||||||
|
admin := r.Group("/api/v1/admin")
|
||||||
|
// Protect admin group with auth + admin requirement
|
||||||
|
admin.Use(middlewares.RequireAuth)
|
||||||
|
admin.Use(middlewares.RequireAdmin)
|
||||||
|
|
||||||
|
auth := r.Group("/api/v1/auth")
|
||||||
|
{
|
||||||
|
auth.POST("/register", controllers.Register, middlewares.RequireRateLimit("register", 10, 60))
|
||||||
|
auth.POST("/login", controllers.Login, middlewares.RequireRateLimit("login", 10, 60))
|
||||||
|
auth.POST("/refresh", controllers.Refresh)
|
||||||
|
auth.GET("/verify-email", controllers.VerifyEmail, middlewares.RequireRateLimit("verify_email", 10, 60))
|
||||||
|
|
||||||
|
// Protected auth endpoints
|
||||||
|
authProtected := auth.Group("")
|
||||||
|
authProtected.Use(middlewares.RequireAuth)
|
||||||
|
{
|
||||||
|
authProtected.GET("/me", controllers.Me)
|
||||||
|
}
|
||||||
|
|
||||||
|
auth.GET("/google", controllers.GoogleLogin)
|
||||||
|
auth.GET("/google/callback", controllers.GoogleCallback)
|
||||||
|
auth.GET("/github", controllers.GithubLogin)
|
||||||
|
auth.GET("/github/callback", controllers.GithubCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public GET endpoints
|
||||||
|
api.GET("/posts", controllers.ListPosts)
|
||||||
|
// use slug instead of numeric id
|
||||||
|
api.GET("/posts/:slug", controllers.GetPost)
|
||||||
|
api.GET("/categories", controllers.ListCategories)
|
||||||
|
// use slug for category retrieval as well
|
||||||
|
api.GET("/categories/:slug", controllers.GetCategory)
|
||||||
|
api.GET("/tags", controllers.ListTags)
|
||||||
|
api.GET("/tags/:id", controllers.GetTag)
|
||||||
|
api.GET("/comments", controllers.ListComments)
|
||||||
|
api.GET("/comments/:id", controllers.GetComment)
|
||||||
|
api.GET("/categoryviews", controllers.ListCategoryViews)
|
||||||
|
api.GET("/categoryviews/:id", controllers.GetCategoryView)
|
||||||
|
api.GET("/tags/:id/posts", controllers.FilterPostsByTag)
|
||||||
|
|
||||||
|
// Settings public endpoints
|
||||||
|
api.GET("/settings", controllers.GetSettings)
|
||||||
|
// optional public get by id
|
||||||
|
api.GET("/settings/:id", controllers.AdminGetSetting)
|
||||||
|
|
||||||
|
// Hero public endpoints
|
||||||
|
api.GET("/heroes", controllers.ListHeroes)
|
||||||
|
api.GET("/heroes/:id", controllers.GetHero)
|
||||||
|
|
||||||
|
// User routes (Profile)
|
||||||
|
userGroup := api.Group("/users")
|
||||||
|
userGroup.Use(middlewares.RequireAuth)
|
||||||
|
{
|
||||||
|
userGroup.GET("/profile", controllers.GetProfile)
|
||||||
|
userGroup.PUT("/profile", controllers.UpdateProfile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Admin POST, PUT, DELETE endpoints
|
||||||
|
admin.POST("/posts", controllers.CreatePost)
|
||||||
|
admin.GET("/posts/:id", controllers.AdminGetPost)
|
||||||
|
admin.PUT("/posts/:id", controllers.UpdatePost)
|
||||||
|
admin.DELETE("/posts/:id", controllers.DeletePost)
|
||||||
|
// Admin GET list (with soft-delete filters)
|
||||||
|
admin.GET("/posts", controllers.AdminListPosts)
|
||||||
|
// soft-delete management
|
||||||
|
admin.GET("/posts/deleted", controllers.ListDeletedPosts)
|
||||||
|
admin.POST("/posts/:id/restore", controllers.RestorePost)
|
||||||
|
|
||||||
|
admin.POST("/categories", controllers.CreateCategory)
|
||||||
|
admin.PUT("/categories/:id", controllers.UpdateCategory)
|
||||||
|
admin.DELETE("/categories/:id", controllers.DeleteCategory)
|
||||||
|
// Admin GET list (with soft-delete filters)
|
||||||
|
admin.GET("/categories", controllers.AdminListCategories)
|
||||||
|
// categories soft-delete management
|
||||||
|
admin.GET("/categories/deleted", controllers.ListDeletedCategories)
|
||||||
|
admin.POST("/categories/:id/restore", controllers.RestoreCategory)
|
||||||
|
|
||||||
|
admin.POST("/tags", controllers.CreateTag)
|
||||||
|
admin.PUT("/tags/:id", controllers.UpdateTag)
|
||||||
|
admin.DELETE("/tags/:id", controllers.DeleteTag)
|
||||||
|
// Admin GET list (with soft-delete filters)
|
||||||
|
admin.GET("/tags", controllers.AdminListTags)
|
||||||
|
admin.POST("/tags/:id/restore", controllers.RestoreTag)
|
||||||
|
|
||||||
|
admin.POST("/comments", controllers.CreateComment)
|
||||||
|
admin.PUT("/comments/:id", controllers.UpdateComment)
|
||||||
|
admin.DELETE("/comments/:id", controllers.DeleteComment)
|
||||||
|
// Admin GET list (with soft-delete filters)
|
||||||
|
admin.GET("/comments", controllers.AdminListComments)
|
||||||
|
|
||||||
|
admin.POST("/categoryviews", controllers.CreateCategoryView)
|
||||||
|
// Admin GET list (with soft-delete filters)
|
||||||
|
admin.GET("/categoryviews", controllers.AdminListCategoryViews)
|
||||||
|
|
||||||
|
// Admin Settings endpoints
|
||||||
|
admin.GET("/settings", controllers.AdminListSettings)
|
||||||
|
admin.POST("/settings", controllers.AdminCreateSetting)
|
||||||
|
admin.GET("/settings/:id", controllers.AdminGetSetting)
|
||||||
|
admin.PUT("/settings/:id", controllers.AdminUpdateSetting)
|
||||||
|
admin.DELETE("/settings/:id", controllers.AdminDeleteSetting)
|
||||||
|
admin.POST("/settings/:id/restore", controllers.AdminRestoreSetting)
|
||||||
|
|
||||||
|
// Hero Admin endpoints
|
||||||
|
admin.GET("/heroes", controllers.AdminListHeroes)
|
||||||
|
admin.POST("/heroes", controllers.CreateHero)
|
||||||
|
admin.GET("/heroes/:id", controllers.AdminGetHero)
|
||||||
|
admin.PUT("/heroes/:id", controllers.UpdateHero)
|
||||||
|
admin.DELETE("/heroes/:id", controllers.DeleteHero)
|
||||||
|
admin.POST("/heroes/:id/restore", controllers.RestoreHero)
|
||||||
|
|
||||||
|
// User Management
|
||||||
|
admin.GET("/users", controllers.AdminListUsers)
|
||||||
|
admin.GET("/users/:id", controllers.AdminGetUser)
|
||||||
|
admin.PUT("/users/:id", controllers.AdminUpdateUser)
|
||||||
|
admin.DELETE("/users/:id", controllers.AdminDeleteUser)
|
||||||
|
admin.POST("/users/:id/restore", controllers.AdminRestoreUser)
|
||||||
|
|
||||||
|
// İlişkili işlemler
|
||||||
|
admin.POST("/posts/:id/comments", controllers.AddCommentToPost)
|
||||||
|
admin.POST("/categories/:id/posts", controllers.AddPostToCategory)
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
127
app/services/jwt_service.go
Normal file
127
app/services/jwt_service.go
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
configs "goGin/config"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TokenTypeAccess sabiti, auth middleware'in beklediği token türünü temsil eder.
|
||||||
|
const TokenTypeAccess = "access"
|
||||||
|
|
||||||
|
// JWTClaim, authorization middleware'inin beklediği claim yapısını temsil eder.
|
||||||
|
// İleride ihtiyaç oldukça alanlar genişletilebilir.
|
||||||
|
type JWTClaim struct {
|
||||||
|
TokenType string
|
||||||
|
IsAdmin bool
|
||||||
|
UserID any
|
||||||
|
}
|
||||||
|
|
||||||
|
// JWTService, JWT ile ilgili operasyonları kapsayan servis.
|
||||||
|
type JWTService struct {
|
||||||
|
secret []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewJWTService yeni bir JWTService örneği döner.
|
||||||
|
// Secret, config içindeki JWT_SECRET üzerinden okunur.
|
||||||
|
func NewJWTService() *JWTService {
|
||||||
|
secret := ""
|
||||||
|
if configs.AppConfig != nil {
|
||||||
|
secret = configs.AppConfig.JWTSecret
|
||||||
|
}
|
||||||
|
return &JWTService{
|
||||||
|
secret: []byte(secret),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateToken verilen JWT'yi doğrular ve claim'leri döner.
|
||||||
|
// HMAC (HS256 vb.) ile imzalanmış token'lar beklenir.
|
||||||
|
func (s *JWTService) ValidateToken(tokenString string) (*JWTClaim, error) {
|
||||||
|
if len(s.secret) == 0 {
|
||||||
|
return nil, errors.New("jwt secret is not configured")
|
||||||
|
}
|
||||||
|
|
||||||
|
token, err := jwt.Parse(tokenString, func(t *jwt.Token) (interface{}, error) {
|
||||||
|
// Sadece HMAC algoritmalarına izin veriyoruz.
|
||||||
|
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected signing method: %v", t.Header["alg"])
|
||||||
|
}
|
||||||
|
return s.secret, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !token.Valid {
|
||||||
|
return nil, errors.New("invalid token")
|
||||||
|
}
|
||||||
|
|
||||||
|
claims, ok := token.Claims.(jwt.MapClaims)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("invalid token claims")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token tipi (access / refresh vs.)
|
||||||
|
var tokenType string
|
||||||
|
if v, ok := claims["token_type"].(string); ok {
|
||||||
|
tokenType = v
|
||||||
|
} else if v, ok := claims["tokenType"].(string); ok {
|
||||||
|
tokenType = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yönetici flag'i
|
||||||
|
var isAdmin bool
|
||||||
|
if v, ok := claims["is_admin"]; ok {
|
||||||
|
switch vv := v.(type) {
|
||||||
|
case bool:
|
||||||
|
isAdmin = vv
|
||||||
|
case float64:
|
||||||
|
isAdmin = vv != 0
|
||||||
|
}
|
||||||
|
} else if v, ok := claims["isAdmin"]; ok {
|
||||||
|
if vv, ok2 := v.(bool); ok2 {
|
||||||
|
isAdmin = vv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kullanıcı ID'si (sub claim'i üzerinden)
|
||||||
|
var userID any
|
||||||
|
if v, ok := claims["sub"]; ok {
|
||||||
|
userID = v
|
||||||
|
} else if v, ok := claims["user_id"]; ok {
|
||||||
|
userID = v
|
||||||
|
}
|
||||||
|
|
||||||
|
return &JWTClaim{
|
||||||
|
TokenType: tokenType,
|
||||||
|
IsAdmin: isAdmin,
|
||||||
|
UserID: userID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateToken creates a short-lived access token
|
||||||
|
func (s *JWTService) GenerateToken(userID uint, isAdmin bool) (string, error) {
|
||||||
|
claims := jwt.MapClaims{
|
||||||
|
"sub": userID,
|
||||||
|
"is_admin": isAdmin,
|
||||||
|
"token_type": TokenTypeAccess,
|
||||||
|
"exp": jwt.NewNumericDate(time.Now().Add(time.Duration(configs.AppConfig.AccessTokenExpireMinutes) * time.Minute)),
|
||||||
|
"iat": jwt.NewNumericDate(time.Now()),
|
||||||
|
}
|
||||||
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||||
|
return token.SignedString(s.secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateRefreshToken creates a long-lived refresh token
|
||||||
|
func (s *JWTService) GenerateRefreshToken(userID uint) (string, error) {
|
||||||
|
claims := jwt.MapClaims{
|
||||||
|
"sub": userID,
|
||||||
|
"token_type": "refresh",
|
||||||
|
"exp": jwt.NewNumericDate(time.Now().Add(time.Duration(configs.AppConfig.RefreshTokenExpireDays) * 24 * time.Hour)),
|
||||||
|
"iat": jwt.NewNumericDate(time.Now()),
|
||||||
|
}
|
||||||
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||||
|
return token.SignedString(s.secret)
|
||||||
|
}
|
||||||
99
belgeler/admin_panel.md
Normal file
99
belgeler/admin_panel.md
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
Bağlam:
|
||||||
|
- Proje Next.js 16, React 19, TypeScript kullanıyor.
|
||||||
|
- Mevcut bağımlılıklar (önemli olanlar): next@16.1.6, react@19.2.3, next-auth, tailwindcss@^4, shadcn, radix-ui, lucide-react, class-variance-authority, clsx, tailwind-merge, zod, sweetalert2, nextjs-turnstile, tw-animate-css.
|
||||||
|
- Yeni paket eklemeden önce önce onay iste.
|
||||||
|
|
||||||
|
Görev:
|
||||||
|
Tüm site temel olarak public olacak; ana içerik sayfaları (ana sayfa, blog/ürün listesi, ürün detay, hakkında, iletişim vb.) herkese açık. Bunun yanında /admin yolu altında ayrı, yetki kontrollü bir Admin Paneli olacak — bu alana sadece next-auth ile oturum açmış ve rolü "admin" olan kullanıcılar erişebilecek. Frontend Next.js 16 + TypeScript ile, mevcut bağımlılıkları kullanarak oluşturulacak; kod temiz, modüler ve production-ready olacak.
|
||||||
|
|
||||||
|
Mimari/Genel kurallar:
|
||||||
|
- Next.js 16, app router (tercih) ve TypeScript (strict).
|
||||||
|
- Styling: TailwindCSS v4 + shadcn komponentleri + Radix UI primitives. İkonlar: lucide-react.
|
||||||
|
- Form schema/validasyon: Zod (hem client hem server).
|
||||||
|
- Auth: next-auth ile role tabanlı erişim (user | admin). Login formunda Turnstile kullanılacak.
|
||||||
|
- UI yardımcıları: class-variance-authority, clsx, tailwind-merge.
|
||||||
|
- Uyarılar/confirm: SweetAlert2.
|
||||||
|
- Yeni bağımlılık eklenmeden önce onay iste.
|
||||||
|
- Veri katmanı: başlangıç mock/JSON veya isteğe göre Prisma+Postgres öner (ek paket için onay al).
|
||||||
|
|
||||||
|
Kapsam / Özellikler:
|
||||||
|
1. Public frontend
|
||||||
|
- Ana sayfa, katalog (liste), öğe detayı, hakkında, iletişim gibi public rotalar (SSR/SSG uygun yerlere göre).
|
||||||
|
- SEO meta, Open Graph etiketleri, erişilebilir markup.
|
||||||
|
- Responsive ve mobil-first tasarım.
|
||||||
|
2. Authentication & Authorization
|
||||||
|
- next-auth ile oturum yönetimi; kullanıcı nesnesinde role alanı.
|
||||||
|
- /auth/signin sayfası (Turnstile entegrasyonu).
|
||||||
|
- Admin alanına erişim: server-side guard (middleware veya server component) ve client-side koruma. Admin değilse /admin altında 403 veya redirect to /auth/signin.
|
||||||
|
3. Admin Panel (/admin)
|
||||||
|
- Layout: sidebar, header, responsive.
|
||||||
|
- Dashboard: KPI kartları (mock veya API), temel yönetim araçları.
|
||||||
|
- User Management: liste/arama/pagination, rol değiştir, aktif/pasif.
|
||||||
|
- Örnek CRUD: Products (create/read/update/delete) için tam çalışan UI ve API (Zod validasyonlu).
|
||||||
|
- Settings: admin için site ayarları (mock).
|
||||||
|
4. API & Veri
|
||||||
|
- Next.js route handlers (app router) veya /api altında tipli endpoints: /api/admin/users, /api/admin/products vb.
|
||||||
|
- Başlangıç için mock veri veya JSON file; gerçek DB istenirse Prisma + Postgres öner (migration ve .env örneği ile).
|
||||||
|
5. Formlar & Validasyon
|
||||||
|
- Zod şemaları hem client hem server tarafında kullanılsın.
|
||||||
|
- Hatalar kullanıcıya anlamlı gösterilsin.
|
||||||
|
6. UI & A11y
|
||||||
|
- shadcn komponentleri ve Radix primitives ile erişilebilir bileşenler.
|
||||||
|
- Lucide ikonları, SweetAlert2 confirm/toast.
|
||||||
|
- Keyboard erişimi ve aria-* attribute’ları.
|
||||||
|
7. Güvenlik
|
||||||
|
- Admin rotaları server-side yetki kontrolü.
|
||||||
|
- CSRF koruması next-auth ile sağlanmalı.
|
||||||
|
- Turnstile login/critical formlar için.
|
||||||
|
8. Tests (tercihli)
|
||||||
|
- Örnek birim testi ve en az 1 API entegrasyon testi (Jest veya testing-library; ek paket gerekiyorsa onay iste).
|
||||||
|
9. Kod kalitesi & teslimat
|
||||||
|
- TypeScript strict, ESLint ile uyumlu.
|
||||||
|
- Commit mesajları: feat/admin-*, fix/*, chore/*.
|
||||||
|
- PR: branch feat/admin-panel veya isteğe göre parça parça PR tercih edilebilir.
|
||||||
|
|
||||||
|
Klasör yapısı önerisi:
|
||||||
|
- app/
|
||||||
|
- layout.tsx (global)
|
||||||
|
- page.tsx (public ana sayfa)
|
||||||
|
- products/
|
||||||
|
- page.tsx
|
||||||
|
- [slug]/page.tsx
|
||||||
|
- (admin)/
|
||||||
|
- layout.tsx
|
||||||
|
- page.tsx (dashboard)
|
||||||
|
- users/
|
||||||
|
- page.tsx
|
||||||
|
- [id]/page.tsx
|
||||||
|
- products/
|
||||||
|
- ...
|
||||||
|
- components/
|
||||||
|
- ui/ (shadcn/radix wrappers)
|
||||||
|
- public/ (Hero, Footer, Header)
|
||||||
|
- admin/ (Sidebar, AdminTable, ProductForm)
|
||||||
|
- lib/
|
||||||
|
- auth.ts (next-auth config)
|
||||||
|
- db.ts (data access abstraction)
|
||||||
|
- schemas/ (zod schemas)
|
||||||
|
- pages/api/ or app/api/
|
||||||
|
- admin/
|
||||||
|
- users.ts
|
||||||
|
- products.ts
|
||||||
|
- styles/ (tailwind globals)
|
||||||
|
|
||||||
|
Acceptance kriterleri:
|
||||||
|
- Public sayfalar (ör. /, /products, /products/[slug]) herkes tarafından erişilebilir ve düzgün render oluyor.
|
||||||
|
- /admin sadece role === "admin" kullanıcılar tarafından erişilebilir; diğerleri redirect veya 403 alıyor.
|
||||||
|
- Login sayfası Turnstile çalışıyor.
|
||||||
|
- Product CRUD çalışıyor (Zod validasyon server+client).
|
||||||
|
- TypeScript derlemesi hatasız.
|
||||||
|
- README içinde gerekli env değişkenleri (NEXTAUTH_*, DATABASE_URL, TURNSTILE keys) ve çalıştırma talimatları var.
|
||||||
|
- PR açıklaması: hangi feature’lar eklendi, nasıl test edilir, eksikler/öneriler.
|
||||||
|
|
||||||
|
Teslim formatı:
|
||||||
|
- Tercih: tek PR (feat/admin-panel) veya küçük aşama PR’ları (her biri açıklamalı). README ve .env.example ekle.
|
||||||
|
- PR açıklamasında çalışma, test etme ve env değişkenleri belirtilmiş olacak.
|
||||||
|
|
||||||
|
Zaman tahmini (yaklaşık):
|
||||||
|
- Minimal (mock veri, temel public sayfalar + admin auth + temel CRUD): 3-5 iş günü.
|
||||||
|
- Tam (DB, testler, audit log, eksiksiz validasyon): 7-14 iş günü.
|
||||||
250
cmd/seeder/main.go
Normal file
250
cmd/seeder/main.go
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
database "goGin/app/database/config"
|
||||||
|
"goGin/app/database/models"
|
||||||
|
configs "goGin/config"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Config ve DB yükle
|
||||||
|
configs.LoadConfig()
|
||||||
|
database.ConnectDB()
|
||||||
|
|
||||||
|
db := database.DB
|
||||||
|
if db == nil {
|
||||||
|
log.Fatal("Veritabanı bağlantısı kurulamadı!")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Seeder başladı...")
|
||||||
|
|
||||||
|
// create a local random generator to avoid deprecated rand.Seed usage
|
||||||
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
|
||||||
|
// 1. Kullanıcıyı Kontrol Et / Oluştur (ID: 2)
|
||||||
|
var user models.User
|
||||||
|
result := db.First(&user, 2)
|
||||||
|
if result.Error != nil {
|
||||||
|
if result.Error == gorm.ErrRecordNotFound {
|
||||||
|
log.Println("Kullanıcı (ID: 2) bulunamadı, oluşturuluyor...")
|
||||||
|
user = models.User{
|
||||||
|
ID: 2,
|
||||||
|
UserName: "fakeuser",
|
||||||
|
Email: "fakeuser@example.com",
|
||||||
|
Password: "password123", // Hashlenmemiş, sadece test için
|
||||||
|
}
|
||||||
|
isAdmin := false
|
||||||
|
emailVerified := true
|
||||||
|
user.IsAdmin = &isAdmin
|
||||||
|
user.EmailVerified = &emailVerified
|
||||||
|
|
||||||
|
if err := db.Create(&user).Error; err != nil {
|
||||||
|
log.Printf("Kullanıcı oluşturulurken hata: %v", err)
|
||||||
|
user.ID = 0
|
||||||
|
if err2 := db.Create(&user).Error; err2 != nil {
|
||||||
|
log.Fatal("Kullanıcı oluşturulamadı:", err2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Fatal("Veritabanı hatası:", result.Error)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Println("Kullanıcı (ID: 2) mevcut.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Kategorileri Oluştur
|
||||||
|
categories := []struct {
|
||||||
|
Title string
|
||||||
|
Subs []string
|
||||||
|
}{
|
||||||
|
{"Teknoloji", []string{"Yazılım", "Donanım", "Yapay Zeka", "Mobil"}},
|
||||||
|
{"Yaşam", []string{"Sağlık", "Spor", "Gezi", "Dekorasyon"}},
|
||||||
|
{"Yemek", []string{"Tatlılar", "Ana Yemekler", "İçecekler"}},
|
||||||
|
{"Sanat", []string{"Sinema", "Müzik", "Edebiyat"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
var createdCategories []models.Category
|
||||||
|
|
||||||
|
for _, catData := range categories {
|
||||||
|
parent := models.Category{
|
||||||
|
Title: catData.Title,
|
||||||
|
Slug: slugify(catData.Title),
|
||||||
|
}
|
||||||
|
if err := db.Where("slug = ?", parent.Slug).FirstOrCreate(&parent).Error; err != nil {
|
||||||
|
log.Printf("Kategori hatası (%s): %v", parent.Title, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
createdCategories = append(createdCategories, parent)
|
||||||
|
|
||||||
|
for _, subTitle := range catData.Subs {
|
||||||
|
sub := models.Category{
|
||||||
|
Title: subTitle,
|
||||||
|
Slug: slugify(subTitle),
|
||||||
|
ParentID: &parent.ID,
|
||||||
|
}
|
||||||
|
if err := db.Where("slug = ?", sub.Slug).FirstOrCreate(&sub).Error; err != nil {
|
||||||
|
log.Printf("Alt kategori hatası (%s): %v", subTitle, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
createdCategories = append(createdCategories, sub)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Etiketleri Oluştur
|
||||||
|
tagNames := []string{"Go", "Gin", "Web", "Api", "Tutorial", "Coding", "Life", "Nature", "Food", "Travel"}
|
||||||
|
var createdTags []models.Tag
|
||||||
|
for _, name := range tagNames {
|
||||||
|
tag := models.Tag{Name: name}
|
||||||
|
if err := db.Where("name = ?", name).FirstOrCreate(&tag).Error; err != nil {
|
||||||
|
log.Printf("Etiket hatası (%s): %v", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
createdTags = append(createdTags, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Postları Oluştur (40 adet)
|
||||||
|
postCount := 40
|
||||||
|
titles := []string{
|
||||||
|
"Go ile Web Geliştirme", "Gin Framework İpuçları", "Veritabanı Optimizasyonu",
|
||||||
|
"Modern Web Tasarımı", "Yapay Zeka Geleceği", "sağlıklı Yaşam Sırları",
|
||||||
|
"Dünya Turu Rehberi", "Lezzetli Pizza Tarifi", "Film İncelemesi: Joker",
|
||||||
|
"Müzik ve Ruh Hali", "Kodlama Pratikleri", "Cloud Computing Temelleri",
|
||||||
|
}
|
||||||
|
|
||||||
|
images := []string{
|
||||||
|
"https://images.unsplash.com/photo-1518770660439-4636190af475?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1498050108023-c5249f4df085?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1461749280684-dccba630e2f6?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1504674900247-0877df9cc836?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1472214103451-9374bd1c798e?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1493770348161-369560ae357d?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1470225620780-dba8ba36b745?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1454165804606-c3d57bc86b40?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1542291026-7eec264c27ff?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
"https://images.unsplash.com/photo-1515378791036-0648a3ef77b2?auto=format&fit=crop&w=1000&q=80",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resimlerin indirileceği hedef klasör
|
||||||
|
uploadDir := "uploads/posts"
|
||||||
|
if err := os.MkdirAll(uploadDir, os.ModePerm); err != nil {
|
||||||
|
log.Fatalf("Klasör oluşturulamadı: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Postlar oluşturuluyor ve resimler indiriliyor...")
|
||||||
|
for i := 0; i < postCount; i++ {
|
||||||
|
// use local rand generator
|
||||||
|
title := fmt.Sprintf("%s %d", titles[r.Intn(len(titles))], i+1)
|
||||||
|
|
||||||
|
// Resim İndirme İşlemi
|
||||||
|
remoteURL := images[r.Intn(len(images))]
|
||||||
|
fileName := fmt.Sprintf("seed-post-%d-%d.jpg", i+1, time.Now().Unix())
|
||||||
|
filePath := filepath.Join(uploadDir, fileName)
|
||||||
|
|
||||||
|
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||||
|
if err := downloadFile(filePath, remoteURL); err != nil {
|
||||||
|
log.Printf("Resim indirilemedi (%s): %v", remoteURL, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbImagePath := fmt.Sprintf("/uploads/posts/%s", fileName)
|
||||||
|
|
||||||
|
post := models.Post{
|
||||||
|
Title: title,
|
||||||
|
Slug: slugify(title),
|
||||||
|
Content: fmt.Sprintf("<p>Bu otomatik oluşturulmuş bir içeriktir: %s. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>", title),
|
||||||
|
Images: dbImagePath,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.Create(&post).Error; err != nil {
|
||||||
|
log.Printf("Post oluşturma hatası: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// İlişkiler
|
||||||
|
numCats := r.Intn(3) + 1
|
||||||
|
for j := 0; j < numCats; j++ {
|
||||||
|
cat := createdCategories[r.Intn(len(createdCategories))]
|
||||||
|
if err := db.Model(&post).Association("Categories").Append(&cat); err != nil {
|
||||||
|
log.Printf("Kategori ilişkilendirme hatası (post %d, cat %d): %v", post.ID, cat.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
numTags := r.Intn(4) + 1
|
||||||
|
for j := 0; j < numTags; j++ {
|
||||||
|
tag := createdTags[r.Intn(len(createdTags))]
|
||||||
|
if err := db.Model(&post).Association("Tags").Append(&tag); err != nil {
|
||||||
|
log.Printf("Tag ilişkilendirme hatası (post %d, tag %d): %v", post.ID, tag.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
numComments := r.Intn(6)
|
||||||
|
for c := 0; c < numComments; c++ {
|
||||||
|
comment := models.Comment{
|
||||||
|
PostID: post.ID,
|
||||||
|
UserID: user.ID,
|
||||||
|
Body: fmt.Sprintf("Bu harika bir yazı! Yorum #%d", c+1),
|
||||||
|
}
|
||||||
|
if err := db.Create(&comment).Error; err != nil {
|
||||||
|
log.Printf("Yorum oluşturma hatası: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Tüm işlemler başarıyla tamamlandı!")
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadFile(filepath string, url string) error {
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if cerr := resp.Body.Close(); cerr != nil {
|
||||||
|
log.Printf("error closing response body: %v", cerr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("bad status: %s", resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := os.Create(filepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if cerr := out.Close(); cerr != nil {
|
||||||
|
log.Printf("error closing file: %v", cerr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func slugify(s string) string {
|
||||||
|
s = strings.ToLower(s)
|
||||||
|
s = strings.ReplaceAll(s, " ", "-")
|
||||||
|
s = strings.ReplaceAll(s, "ı", "i")
|
||||||
|
s = strings.ReplaceAll(s, "ğ", "g")
|
||||||
|
s = strings.ReplaceAll(s, "ü", "u")
|
||||||
|
s = strings.ReplaceAll(s, "ş", "s")
|
||||||
|
s = strings.ReplaceAll(s, "ö", "o")
|
||||||
|
s = strings.ReplaceAll(s, "ç", "c")
|
||||||
|
timestamp := time.Now().UnixNano()
|
||||||
|
return fmt.Sprintf("%s-%d", s, timestamp)
|
||||||
|
}
|
||||||
243
config/config.go
Normal file
243
config/config.go
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
package configs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Env string // örn. development, production
|
||||||
|
Port string
|
||||||
|
DBUrl string
|
||||||
|
JWTSecret string
|
||||||
|
AppURL string
|
||||||
|
ApiAppURL string // örn. https://api.example.com - e-posta doğrulama linkleri için kullanılır
|
||||||
|
GoogleClientID string
|
||||||
|
GoogleClientSecret string
|
||||||
|
GithubClientID string
|
||||||
|
GithubClientSecret string
|
||||||
|
GoogleRedirectURL string
|
||||||
|
GithubRedirectURL string
|
||||||
|
ClientCallbackURL string
|
||||||
|
OAuthRedirectURL string
|
||||||
|
RedisUrl string
|
||||||
|
AccessTokenExpireMinutes int
|
||||||
|
RefreshTokenExpireDays int
|
||||||
|
|
||||||
|
// Avatar Ayarları
|
||||||
|
AvatarHeight int
|
||||||
|
AvatarWidth int
|
||||||
|
AvatarQuality int
|
||||||
|
AvatarFormat string
|
||||||
|
AvatarMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Ana Sayfa Resim Ayarları
|
||||||
|
HomeImageHeight int
|
||||||
|
HomeImageWidth int
|
||||||
|
HomeImageQuality int
|
||||||
|
HomeImageFormat string
|
||||||
|
HomeImageMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Hakkında Resim Ayarları
|
||||||
|
AboutImageHeight int
|
||||||
|
AboutImageWidth int
|
||||||
|
AboutImageQuality int
|
||||||
|
AboutImageFormat string
|
||||||
|
AboutImageMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Servis Resim Ayarları
|
||||||
|
ServiceImageHeight int
|
||||||
|
ServiceImageWidth int
|
||||||
|
ServiceImageQuality int
|
||||||
|
ServiceImageFormat string
|
||||||
|
ServiceImageMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Gönderi Resim Ayarları
|
||||||
|
PostImageHeight int
|
||||||
|
PostImageWidth int
|
||||||
|
PostImageQuality int
|
||||||
|
PostImageFormat string
|
||||||
|
PostImageMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Gönderi Kategori Resim Ayarları
|
||||||
|
PostCategoryImageHeight int
|
||||||
|
PostCategoryImageWidth int
|
||||||
|
PostCategoryImageQuality int
|
||||||
|
PostCategoryImageFormat string
|
||||||
|
PostCategoryImageMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Site Logo Ayarları
|
||||||
|
SettingsLogoHeight int
|
||||||
|
SettingsLogoWidth int
|
||||||
|
SettingsLogoQuality int
|
||||||
|
SettingsLogoFormat string
|
||||||
|
SettingsLogoMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Afiş Resim Ayarları
|
||||||
|
BannerImageHeight int
|
||||||
|
BannerImageWidth int
|
||||||
|
BannerImageQuality int
|
||||||
|
BannerImageFormat string
|
||||||
|
BannerImageMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// Afiş Küçük Resim (Thumb) Ayarları
|
||||||
|
BannerThumbHeight int
|
||||||
|
BannerThumbWidth int
|
||||||
|
BannerThumbQuality int
|
||||||
|
BannerThumbFormat string
|
||||||
|
BannerThumbMode string // cover, contain, resize
|
||||||
|
|
||||||
|
// E-posta Ayarları
|
||||||
|
EmailHost string
|
||||||
|
EmailPort string
|
||||||
|
EmailHostUser string
|
||||||
|
EmailHostPassword string
|
||||||
|
EmailFrom string
|
||||||
|
|
||||||
|
// Debug / Logging
|
||||||
|
Debug bool // SET_DEBUG=true ise middleware ve diğer debug logları açılır
|
||||||
|
CorsDebug bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var AppConfig *Config
|
||||||
|
|
||||||
|
func LoadConfig() {
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
// Eğer proje kök dizininden çalıştırılmıyorsa (örn: cmd/app içinden), üst dizinleri kontrol et
|
||||||
|
err = godotenv.Load(".env")
|
||||||
|
//err = godotenv.Load("../../.env")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Uyarı: .env dosyası yüklenirken hata oluştu: %v — sistem ortam değişkenleriyle devam ediliyor", err)
|
||||||
|
}
|
||||||
|
log.Printf(".env ENV YUKLENDI")
|
||||||
|
AppConfig = &Config{
|
||||||
|
Env: getEnv("APP_ENV", "development"),
|
||||||
|
Port: getEnv("PORT", "8080"),
|
||||||
|
DBUrl: getEnv("DB_URL", ""),
|
||||||
|
JWTSecret: getEnv("JWT_SECRET", "go-gin-mTFY2jAOMWWxadVIWjRoPG9aOM3z9srCVoU35Gs1VZaRKgXet26cztUE8LLpwok9"),
|
||||||
|
AppURL: getEnv("APP_URL", "http://localhost:8080"),
|
||||||
|
ApiAppURL: getEnv("BASE_SITE_URL", "http://localhost:3000"),
|
||||||
|
GoogleClientID: getEnv("GOOGLE_CLIENT_ID", ""),
|
||||||
|
GoogleClientSecret: getEnv("GOOGLE_CLIENT_SECRET", ""),
|
||||||
|
GithubClientID: getEnv("GITHUB_CLIENT_ID", ""),
|
||||||
|
GithubClientSecret: getEnv("GITHUB_CLIENT_SECRET", ""),
|
||||||
|
GoogleRedirectURL: getEnv("GOOGLE_REDIRECT_URL", "http://localhost:8080/api/v1/auth/google/callback"),
|
||||||
|
GithubRedirectURL: getEnv("GITHUB_REDIRECT_URL", "http://localhost:8080/api/v1/auth/github/callback"),
|
||||||
|
ClientCallbackURL: getEnv("CLIENT_CALLBACK_URL", ""),
|
||||||
|
OAuthRedirectURL: getEnv("OAUTH_REDIRECT_URL", ""),
|
||||||
|
RedisUrl: getEnv("REDIS_URL", ""),
|
||||||
|
AccessTokenExpireMinutes: getEnvAsInt("ACCESS_TOKEN_EXPIRE_MINUTES", 120), // Varsayılan 120 dakika
|
||||||
|
RefreshTokenExpireDays: getEnvAsInt("REFRESH_TOKEN_EXPIRE_DAYS", 30), // Varsayılan 30 gün
|
||||||
|
|
||||||
|
// Avatar Varsayılanları
|
||||||
|
AvatarHeight: getEnvAsInt("AVATAR_H", 0), // Varsayılan 0 (otomatik)
|
||||||
|
AvatarWidth: getEnvAsInt("AVATAR_W", 800), // Varsayılan 800
|
||||||
|
AvatarQuality: getEnvAsInt("AVATAR_Q", 80), // Varsayılan 80
|
||||||
|
AvatarFormat: getEnv("AVATAR_F", "webp"), // Varsayılan webp
|
||||||
|
AvatarMode: getEnv("AVATAR_B", "contain"), // Varsayılan contain (Fit)
|
||||||
|
|
||||||
|
// Ana Sayfa Resim Varsayılanları
|
||||||
|
HomeImageHeight: getEnvAsInt("HOME_IMAGE_H", 0), // Varsayılan 0 (otomatik)
|
||||||
|
HomeImageWidth: getEnvAsInt("HOME_IMAGE_W", 800), // Varsayılan 800
|
||||||
|
HomeImageQuality: getEnvAsInt("HOME_IMAGE_Q", 80), // Varsayılan 80
|
||||||
|
HomeImageFormat: getEnv("HOME_IMAGE_F", "webp"), // Varsayılan webp
|
||||||
|
HomeImageMode: getEnv("HOME_IMAGE_B", "contain"), // Varsayılan contain (Fit)
|
||||||
|
|
||||||
|
// Hakkında Resim Varsayılanları
|
||||||
|
AboutImageHeight: getEnvAsInt("ABOUTME_IMAGE_H", getEnvAsInt("ABOUT_IMAGE_H", 0)),
|
||||||
|
AboutImageWidth: getEnvAsInt("ABOUTME_IMAGE_W", getEnvAsInt("ABOUT_IMAGE_W", 800)),
|
||||||
|
AboutImageQuality: getEnvAsInt("ABOUTME_IMAGE_Q", getEnvAsInt("ABOUT_IMAGE_Q", 80)),
|
||||||
|
AboutImageFormat: getEnv("ABOUTME_IMAGE_F", getEnv("ABOUT_IMAGE_F", "webp")),
|
||||||
|
AboutImageMode: getEnv("ABOUTME_IMAGE_B", getEnv("ABOUT_IMAGE_B", "contain")),
|
||||||
|
|
||||||
|
// Servis Resim Varsayılanları
|
||||||
|
ServiceImageHeight: getEnvAsInt("SERVICE_IMAGE_H", 256),
|
||||||
|
ServiceImageWidth: getEnvAsInt("SERVICE_IMAGE_W", 256),
|
||||||
|
ServiceImageQuality: getEnvAsInt("SERVICE_IMAGE_Q", 90),
|
||||||
|
ServiceImageFormat: getEnv("SERVICE_IMAGE_F", "png"),
|
||||||
|
ServiceImageMode: getEnv("SERVICE_IMAGE_B", "cover"),
|
||||||
|
|
||||||
|
// Gönderi Resim Varsayılanları
|
||||||
|
PostImageHeight: getEnvAsInt("POST_IMAGE_H", 450),
|
||||||
|
PostImageWidth: getEnvAsInt("POST_IMAGE_W", 700),
|
||||||
|
PostImageQuality: getEnvAsInt("POST_IMAGE_Q", 90),
|
||||||
|
PostImageFormat: getEnv("POST_IMAGE_F", "webp"),
|
||||||
|
PostImageMode: getEnv("POST_IMAGE_B", "cover"),
|
||||||
|
|
||||||
|
// Gönderi Kategori Resim Varsayılanları
|
||||||
|
PostCategoryImageHeight: getEnvAsInt("POST_CATEGORY_IMAGE_H", 300),
|
||||||
|
PostCategoryImageWidth: getEnvAsInt("POST_CATEGORY_IMAGE_W", 300),
|
||||||
|
PostCategoryImageQuality: getEnvAsInt("POST_CATEGORY_IMAGE_Q", 85),
|
||||||
|
PostCategoryImageFormat: getEnv("POST_CATEGORY_IMAGE_F", "png"),
|
||||||
|
PostCategoryImageMode: getEnv("POST_CATEGORY_IMAGE_B", "cover"),
|
||||||
|
|
||||||
|
// Site Logo Varsayılanları
|
||||||
|
SettingsLogoHeight: getEnvAsInt("SETTINGS_LOGO_H", 54),
|
||||||
|
SettingsLogoWidth: getEnvAsInt("SETTINGS_LOGO_W", 165),
|
||||||
|
SettingsLogoQuality: getEnvAsInt("SETTINGS_LOGO_Q", 85),
|
||||||
|
SettingsLogoFormat: getEnv("SETTINGS_LOGO_F", "png"),
|
||||||
|
SettingsLogoMode: getEnv("SETTINGS_LOGO_B", "cover"),
|
||||||
|
|
||||||
|
// Afiş Resim Varsayılanları
|
||||||
|
BannerImageHeight: getEnvAsInt("BANNER_IMAGE_H", 700),
|
||||||
|
BannerImageWidth: getEnvAsInt("BANNER_IMAGE_W", 1920),
|
||||||
|
BannerImageQuality: getEnvAsInt("BANNER_IMAGE_Q", 85),
|
||||||
|
BannerImageFormat: getEnv("BANNER_IMAGE_F", "webp"),
|
||||||
|
BannerImageMode: getEnv("BANNER_IMAGE_B", "cover"),
|
||||||
|
|
||||||
|
// Afiş Küçük Resim (Thumb) Varsayılanları
|
||||||
|
BannerThumbHeight: getEnvAsInt("BANNER_THUMB_H", 48),
|
||||||
|
BannerThumbWidth: getEnvAsInt("BANNER_THUMB_W", 48),
|
||||||
|
BannerThumbQuality: getEnvAsInt("BANNER_THUMB_Q", 90),
|
||||||
|
BannerThumbFormat: getEnv("BANNER_THUMB_F", "png"),
|
||||||
|
BannerThumbMode: getEnv("BANNER_THUMB_B", "cover"),
|
||||||
|
|
||||||
|
// E-posta Varsayılanları
|
||||||
|
EmailHost: getEnv("EMAIL_HOST", "localhost"),
|
||||||
|
EmailPort: getEnv("EMAIL_PORT", "1025"),
|
||||||
|
EmailHostUser: getEnv("EMAIL_HOST_USER", ""),
|
||||||
|
EmailHostPassword: getEnv("EMAIL_HOST_PASSWORD", ""),
|
||||||
|
EmailFrom: getEnv("EMAIL_FROM", "noreply@gauth.local"),
|
||||||
|
|
||||||
|
// Debug / Logging
|
||||||
|
Debug: getEnvAsBool("SET_DEBUG", false),
|
||||||
|
CorsDebug: getEnvAsBool("CORS_DEBUG", false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnv(key, fallback string) string {
|
||||||
|
if value, exists := os.LookupEnv(key); exists {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnvAsInt(key string, fallback int) int {
|
||||||
|
valueStr := getEnv(key, "")
|
||||||
|
if valueStr == "" {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
value, err := strconv.Atoi(valueStr)
|
||||||
|
if err != nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnvAsBool(key string, fallback bool) bool {
|
||||||
|
valueStr := strings.TrimSpace(getEnv(key, ""))
|
||||||
|
if valueStr == "" {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
value, err := strconv.ParseBool(valueStr)
|
||||||
|
if err != nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
4629
docs/docs.go
Normal file
4629
docs/docs.go
Normal file
File diff suppressed because it is too large
Load Diff
4605
docs/swagger.json
Normal file
4605
docs/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
3018
docs/swagger.yaml
Normal file
3018
docs/swagger.yaml
Normal file
File diff suppressed because it is too large
Load Diff
95
frontend/.env
Normal file
95
frontend/.env
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
NEXT_AUTH_SECRET=bFcOqf37V1DgSxsibuZ79jSIaI4MZ9TCB1Y7iWZFJZrtZdUJapesSi0dXo2Bx8xY
|
||||||
|
|
||||||
|
GITHUB_CLIENT_ID='Ov23liUt9B61O46Mdfm4'
|
||||||
|
GITHUB_CLIENT_SECRET='c7fc8dcb1b2c8f22120608425d07d5efd995baaf'
|
||||||
|
GITHUB_SCOPE=['user:email']
|
||||||
|
|
||||||
|
GOOGLE_CLIENT_ID='915364976256-691m0s87as2r5vdbqr96f6humblseobt.apps.googleusercontent.com'
|
||||||
|
GOOGLE_CLIENT_SECRET='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'
|
||||||
|
GOOGLE_REDIRECT_URL=http://localhost:8080/v1/auth/google/callback
|
||||||
|
|
||||||
|
AUTH_NO_SECRET=MlBdj44xjhZIlxQIiz4ZuszB1yvRMW0A
|
||||||
|
BASE_API_URL=http://localhost:8080
|
||||||
|
# BASE_API_URL=https://api.beyhano.com.tr
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:8080
|
||||||
|
BASE_SITE_URL=http://localhost:3000
|
||||||
|
AUTH_NO_ORIGIN=http://localhost:3000
|
||||||
|
BASE_SITE_NAME='Beyhan Oğur'
|
||||||
|
NODE_ENV='development'
|
||||||
|
NEXT_PORT=3000
|
||||||
|
APP_TITLE='Beyhan Oğur'
|
||||||
|
NEXT_API_SECRET='6YdkEwOZC0j5K9a5vJtJQGIuwAoqGG4c'
|
||||||
|
# NUXT_PUBLIC_API_BASE=https://api.beyhano.com.tr
|
||||||
|
CLOUD_FLARE_SITE_KEY='0x4AAAAAACHzHKvlEwMamxCM'
|
||||||
|
CLOUD_FLARE_SECRET='0x4AAAAAACHzHHisTSFzGw15HvwXF3yXRIg'
|
||||||
|
# JWT için gizli anahtar. Güvenlik için bunu daha karmaşık bir değerle değiştirin.
|
||||||
|
JWT_SECRET="go-gin-mTFY2jAOMWWxadVIWjRoPG9aOM3z9srCVoU35Gs1VZaRKgXet26cztUE8LLpwok9"
|
||||||
|
#####################GO###################
|
||||||
|
### Db Configuration
|
||||||
|
DB_URL="gogin:gg7678290@tcp(10.80.80.70:3306)/gogin?charset=utf8mb4&parseTime=True&loc=Local&timeout=10s&readTimeout=30s&writeTimeout=30s&multiStatements=true"
|
||||||
|
##########################
|
||||||
|
# Redis Configuration
|
||||||
|
REDIS_HOST=10.80.80.70
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_USER=default
|
||||||
|
REDIS_PASSWORD=gg7678290
|
||||||
|
REDIS_URL=redis://default:gg7678290@10.80.80.70:6379/4
|
||||||
|
#############################
|
||||||
|
# Email Settings (Mailpit)
|
||||||
|
EMAIL_HOST=10.80.80.70
|
||||||
|
EMAIL_PORT=1025
|
||||||
|
EMAIL_HOST_USER=""
|
||||||
|
EMAIL_HOST_PASSWORD=""
|
||||||
|
EMAIL_USE_TLS=false
|
||||||
|
EMAIL_USE_SSL=false
|
||||||
|
EMAIL_FROM=noreply@gauth.local
|
||||||
|
#############################
|
||||||
|
# App Genel Ayarları
|
||||||
|
PORT=8080
|
||||||
|
################################
|
||||||
|
# AVATANE IMAGES
|
||||||
|
AVATAR_H=150
|
||||||
|
AVATAR_W=150
|
||||||
|
AVATAR_Q=90
|
||||||
|
AVATAR_B=cover
|
||||||
|
AVATAR_F=webp
|
||||||
|
#######################
|
||||||
|
# Home IMAGES
|
||||||
|
HOME_IMAGE_H=400
|
||||||
|
HOME_IMAGE_W=400
|
||||||
|
HOME_IMAGE_Q=90
|
||||||
|
HOME_IMAGE_B=cover
|
||||||
|
HOME_IMAGE_F=webp
|
||||||
|
#######################
|
||||||
|
# Aboutme IMAGES
|
||||||
|
ABOUTME_IMAGE_H=400
|
||||||
|
ABOUTME_IMAGE_W=400
|
||||||
|
ABOUTME_IMAGE_Q=90
|
||||||
|
ABOUTME_IMAGE_B=cover
|
||||||
|
ABOUTME_IMAGE_F=webp
|
||||||
|
#######################
|
||||||
|
# MyService IMAGES
|
||||||
|
SERVICE_IMAGE_H=256
|
||||||
|
SERVICE_IMAGE_W=256
|
||||||
|
SERVICE_IMAGE_Q=90
|
||||||
|
SERVICE_IMAGE_B=cover
|
||||||
|
SERVICE_IMAGE_F=webp
|
||||||
|
#######################
|
||||||
|
# BANNER IMAGES
|
||||||
|
BANNER_IMAGE_H=700
|
||||||
|
BANNER_IMAGE_W=1920
|
||||||
|
BANNER_IMAGE_Q=85
|
||||||
|
BANNER_IMAGE_B=cover
|
||||||
|
BANNER_IMAGE_F=webp
|
||||||
|
################################
|
||||||
|
################################
|
||||||
|
SET_DEBUG=true
|
||||||
|
CORS_DEBUG=true
|
||||||
|
APP_ENV=development
|
||||||
|
VITE_API_BASE_URL=http://localhost:8080
|
||||||
|
FRONTEND_URL=http://localhost:3000
|
||||||
|
SESSION_SECRET=go-gin-mTFY2jAOMWWxadVIWjRoPG9aOM3z9srCVoU35Gs1VZaRKgXet26cztUE8LLpwok9
|
||||||
|
CLIENT_SECRET='2222'
|
||||||
|
CLIENT_ID='2222'
|
||||||
|
ACCESS_TOKEN_EXPIRE_MINUTES=180
|
||||||
|
REFRESH_TOKEN_EXPIRE_DAYS=60
|
||||||
11
frontend/.env.local
Normal file
11
frontend/.env.local
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# NextAuth
|
||||||
|
NEXTAUTH_URL=http://localhost:3000
|
||||||
|
NEXTAUTH_SECRET="bFcOqf37V1DgSxsibuZ79jSIaI4MZ9TCB1Y7iWZFJZrtZdUJapesSi0dXo2Bx8xY"
|
||||||
|
|
||||||
|
# Backend API
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:8080
|
||||||
|
BASE_API_URL=http://localhost:8080
|
||||||
|
|
||||||
|
# Turnstile (Cloudflare)
|
||||||
|
NEXT_PUBLIC_TURNSTILE_SITEKEY="0x4AAAAAACHzHKvlEwMamxCM"
|
||||||
|
TURNSTILE_SECRET_KEY="0x4AAAAAACHzHHisTSFzGw15HvwXF3yXRIg"
|
||||||
112
frontend/ADMIN_PANEL_GUIDE.md
Normal file
112
frontend/ADMIN_PANEL_GUIDE.md
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
# Admin Paneli Geliştirme Kılavuzu
|
||||||
|
|
||||||
|
Bu kılavuz, `admin_user.md` dosyasındaki gereksinimlere dayanarak **Next.js 16 + TypeScript + Tailwind v4 + shadcn** teknolojileriyle geliştirilecek Admin Paneli için mimari yapıyı ve geliştirme süreçlerini içerir.
|
||||||
|
|
||||||
|
## 1. Teknoloji Yığını ve Kurulum
|
||||||
|
|
||||||
|
Proje `frontend` klasörü altında yapılandırılmıştır. Gerekli tüm paketler (`package.json`) önceden yüklenmiştir:
|
||||||
|
- **Framework:** Next.js 16 (App Router)
|
||||||
|
- **UI:** React 19, Tailwind CSS v4, shadcn/ui
|
||||||
|
- **İkonlar:** lucide-react
|
||||||
|
- **Validasyon:** Zod
|
||||||
|
- **Auth:** NextAuth.js
|
||||||
|
- **Bildirimler:** SweetAlert2
|
||||||
|
- **Güvenlik:** nextjs-turnstile (Cloudflare)
|
||||||
|
|
||||||
|
### Kurulum ve Çalıştırma
|
||||||
|
```bash
|
||||||
|
cd frontend
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. Proje Klasör Yapısı (Önerilen)
|
||||||
|
|
||||||
|
Admin paneli için aşağıdaki klasör yapısını takip edeceğiz:
|
||||||
|
|
||||||
|
```
|
||||||
|
frontend/
|
||||||
|
├── app/
|
||||||
|
│ ├── admin/ # Admin paneli rotaları
|
||||||
|
│ │ ├── layout.tsx # Admin layout (Sidebar, Header, Auth Check)
|
||||||
|
│ │ ├── dashboard/ # Dashboard (KPI kartları)
|
||||||
|
│ │ ├── users/ # Kullanıcı yönetimi
|
||||||
|
│ │ ├── products/ # Ürün yönetimi
|
||||||
|
│ │ └── settings/ # Ayarlar
|
||||||
|
│ ├── api/auth/[...nextauth]/ # NextAuth API rotası
|
||||||
|
│ └── globals.css # Global stiller (Tailwind)
|
||||||
|
├── components/
|
||||||
|
│ ├── admin/ # Admin'e özel bileşenler
|
||||||
|
│ │ ├── sidebar.tsx
|
||||||
|
│ │ ├── header.tsx
|
||||||
|
│ │ ├── data-table.tsx # Reusable tablo yapısı
|
||||||
|
│ │ └── recent-sales.tsx
|
||||||
|
│ └── ui/ # shadcn bileşenleri (Button, Input, vb.)
|
||||||
|
├── lib/
|
||||||
|
│ ├── utils.ts # cn() ve diğer yardımcılar
|
||||||
|
│ ├── auth.ts # NextAuth konfigürasyonu
|
||||||
|
│ └── db.ts # Veritabanı bağlantısı (veya API client)
|
||||||
|
├── actions/ # Server Actions (Zod validasyonlu)
|
||||||
|
│ ├── auth-actions.ts
|
||||||
|
│ └── user-actions.ts
|
||||||
|
└── public/
|
||||||
|
└── admin/ # Admin ile ilgili statik dosyalar
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Ortam Değişkenleri (.env)
|
||||||
|
|
||||||
|
Kök dizindeki `.env` dosyasına aşağıdaki değişkenlerin eklenmesi gerekmektedir:
|
||||||
|
|
||||||
|
```env
|
||||||
|
# NextAuth
|
||||||
|
NEXTAUTH_URL=http://localhost:3000
|
||||||
|
NEXTAUTH_SECRET=gizli-bir-anahtar-olusturun
|
||||||
|
|
||||||
|
# Backend API (Go)
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:8080/api/v1
|
||||||
|
|
||||||
|
# Cloudflare Turnstile (Login güvenliği için)
|
||||||
|
NEXT_PUBLIC_TURNSTILE_SITEKEY=your-site-key
|
||||||
|
TURNSTILE_SECRET_KEY=your-secret-key
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. Geliştirme Adımları
|
||||||
|
|
||||||
|
Geliştirme süreci aşağıdaki sırayla ilerleyecektir:
|
||||||
|
|
||||||
|
1. **Temel Bileşenler:** shadcn kurulumunun doğrulanması ve temel bileşenlerin (Button, Input, Card, Form) eklenmesi.
|
||||||
|
2. **Auth Yapısı:** NextAuth yapılandırması ve `middleware.ts` ile `/admin` rotalarının korunması.
|
||||||
|
3. **Login Sayfası:** `/admin/login` sayfasının tasarımı ve Turnstile entegrasyonu.
|
||||||
|
4. **Admin Layout:** Sidebar ve Header içeren ana yerleşim düzeninin oluşturulması.
|
||||||
|
5. **Dashboard:** KPI kartları ve özet tabloların eklenmesi.
|
||||||
|
6. **CRUD Sayfaları:** Kullanıcılar (`/users`), Ürünler (`/products`) sayfalarının geliştirilmesi.
|
||||||
|
|
||||||
|
## 5. Güvenlik ve Validasyon Kuralları
|
||||||
|
|
||||||
|
- **Zod:** Tüm form verileri hem istemci (client) hem sunucu (server) tarafında Zod şemaları ile doğrulanmalıdır.
|
||||||
|
- **Server Actions:** Veri mutasyonları (Create, Update, Delete) Server Actions üzerinden yapılmalı ve oturum kontrolü içermelidir.
|
||||||
|
- **Role-Based Access:** Sadece `admin` veya `superadmin` rolüne sahip kullanıcılar `/admin` paneline erişebilmelidir.
|
||||||
|
|
||||||
|
## 6. Örnek Kullanım (Server Action ile Form)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// actions/login.ts
|
||||||
|
"use server"
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const loginSchema = z.object({
|
||||||
|
email: z.string().email(),
|
||||||
|
password: z.string().min(6),
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function loginAction(formData: FormData) {
|
||||||
|
const data = Object.fromEntries(formData);
|
||||||
|
const parsed = loginSchema.safeParse(data);
|
||||||
|
|
||||||
|
if (!parsed.success) {
|
||||||
|
return { error: "Geçersiz veri" };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auth işlemleri...
|
||||||
|
}
|
||||||
|
```
|
||||||
36
frontend/README.md
Normal file
36
frontend/README.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
First, run the development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
# or
|
||||||
|
yarn dev
|
||||||
|
# or
|
||||||
|
pnpm dev
|
||||||
|
# or
|
||||||
|
bun dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
|
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||||
|
|
||||||
|
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
To learn more about Next.js, take a look at the following resources:
|
||||||
|
|
||||||
|
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||||
|
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||||
|
|
||||||
|
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||||
|
|
||||||
|
## Deploy on Vercel
|
||||||
|
|
||||||
|
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||||
|
|
||||||
|
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||||
235
frontend/app/admin/categories/category-dialog.tsx
Normal file
235
frontend/app/admin/categories/category-dialog.tsx
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import { Category } from "@/types/category"
|
||||||
|
import { categoryService } from "@/services/categoryService"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
title: z.string().min(2, {
|
||||||
|
message: "Başlık en az 2 karakter olmalıdır.",
|
||||||
|
}),
|
||||||
|
slug: z.string().min(2, {
|
||||||
|
message: "Slug en az 2 karakter olmalıdır.",
|
||||||
|
}),
|
||||||
|
description: z.string().optional(),
|
||||||
|
parent_id: z.string().optional(), // Select value is string, will convert to number
|
||||||
|
})
|
||||||
|
|
||||||
|
interface CategoryDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
category?: Category | null
|
||||||
|
onSuccess?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function slugify(text: string) {
|
||||||
|
const trMap: { [key: string]: string } = {
|
||||||
|
'ç': 'c', 'Ç': 'c',
|
||||||
|
'ğ': 'g', 'Ğ': 'g',
|
||||||
|
'ş': 's', 'Ş': 's',
|
||||||
|
'ü': 'u', 'Ü': 'u',
|
||||||
|
'ı': 'i', 'İ': 'i',
|
||||||
|
'ö': 'o', 'Ö': 'o'
|
||||||
|
};
|
||||||
|
return text
|
||||||
|
.replace(/[çÇğĞşŞüÜıİöÖ]/g, (char) => trMap[char] || char)
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9\s-]/g, '') // Remove non-alphanumeric chars (except space and hyphen)
|
||||||
|
.trim()
|
||||||
|
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
||||||
|
.replace(/-+/g, '-'); // Remove duplicate hyphens
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CategoryDialog({ open, onOpenChange, category, onSuccess }: CategoryDialogProps) {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [categories, setCategories] = useState<Category[]>([])
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: {
|
||||||
|
title: "",
|
||||||
|
slug: "",
|
||||||
|
description: "",
|
||||||
|
parent_id: "0",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Watch title to auto-generate slug
|
||||||
|
const titleValue = form.watch("title")
|
||||||
|
useEffect(() => {
|
||||||
|
if (!category && titleValue) { // Only auto-generate if creating new category
|
||||||
|
const slug = slugify(titleValue)
|
||||||
|
form.setValue("slug", slug)
|
||||||
|
}
|
||||||
|
}, [titleValue, category, form])
|
||||||
|
|
||||||
|
// Fetch categories for check parent selection
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
categoryService.getCategories(1, 100, "", "active") // Get active categories
|
||||||
|
.then(res => {
|
||||||
|
// Ensure we don't list the current category (recursion check)
|
||||||
|
const validCategories = category
|
||||||
|
? (res.items || []).filter(c => c.id !== category.id)
|
||||||
|
: (res.items || []);
|
||||||
|
setCategories(validCategories)
|
||||||
|
})
|
||||||
|
.catch(err => console.error(err))
|
||||||
|
}
|
||||||
|
}, [open, category])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (category) {
|
||||||
|
form.reset({
|
||||||
|
title: category.title,
|
||||||
|
slug: category.slug,
|
||||||
|
description: category.description || "",
|
||||||
|
parent_id: category.parent_id ? category.parent_id.toString() : "0",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
form.reset({
|
||||||
|
title: "",
|
||||||
|
slug: "",
|
||||||
|
description: "",
|
||||||
|
parent_id: "0",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [category, form, open])
|
||||||
|
|
||||||
|
const onSubmit = async (values: z.infer<typeof formSchema>) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const payload: Partial<Category> = {
|
||||||
|
title: values.title,
|
||||||
|
slug: values.slug,
|
||||||
|
description: values.description,
|
||||||
|
parent_id: values.parent_id && values.parent_id !== "0" ? parseInt(values.parent_id) : null,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category) {
|
||||||
|
await categoryService.updateCategory(category.id, payload)
|
||||||
|
toast.success("Kategori güncellendi")
|
||||||
|
} else {
|
||||||
|
await categoryService.createCategory(payload)
|
||||||
|
toast.success("Kategori oluşturuldu")
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
if (onSuccess) {
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
toast.error((error as Error).message || "Bir hata oluştu")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[500px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{category ? "Kategori Düzenle" : "Yeni Kategori Ekle"}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Başlık</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Kategori Başlığı" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="slug"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Slug (URL)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="kategori-slug" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="parent_id"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Üst Kategori</FormLabel>
|
||||||
|
<Select
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
value={field.value} // Remove defaultValue to avoid conflicts
|
||||||
|
>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Üst Kategori Seçin" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="0">Yok (Ana Kategori)</SelectItem>
|
||||||
|
{categories.map((c) => (
|
||||||
|
<SelectItem key={c.id} value={c.id.toString()}>
|
||||||
|
{c.title}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Açıklama</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea placeholder="Kategori açıklaması..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
141
frontend/app/admin/categories/category-row-actions.tsx
Normal file
141
frontend/app/admin/categories/category-row-actions.tsx
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState } from "react"
|
||||||
|
import { Row } from "@tanstack/react-table"
|
||||||
|
import { MoreHorizontal, Pencil, Trash, RefreshCcw } from "lucide-react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Category } from "@/types/category"
|
||||||
|
import { categoryService } from "@/services/categoryService"
|
||||||
|
import { CategoryDialog } from "./category-dialog"
|
||||||
|
import Swal from 'sweetalert2'
|
||||||
|
import withReactContent from 'sweetalert2-react-content'
|
||||||
|
|
||||||
|
const MySwal = withReactContent(Swal)
|
||||||
|
|
||||||
|
interface DataTableRowActionsProps<TData> {
|
||||||
|
row: Row<TData>
|
||||||
|
onRefresh: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTableRowActions<TData>({
|
||||||
|
row,
|
||||||
|
onRefresh,
|
||||||
|
}: DataTableRowActionsProps<TData>) {
|
||||||
|
const category = row.original as Category
|
||||||
|
const [showEditDialog, setShowEditDialog] = useState(false)
|
||||||
|
const isDeleted = !!category.deleted_at
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: 'Emin misiniz?',
|
||||||
|
text: "Bu kategori silinecek!",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Evet, sil!',
|
||||||
|
cancelButtonText: 'İptal'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await categoryService.deleteCategory(category.id)
|
||||||
|
MySwal.fire(
|
||||||
|
'Silindi!',
|
||||||
|
'Kategori başarıyla silindi.',
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
onRefresh()
|
||||||
|
} catch {
|
||||||
|
MySwal.fire(
|
||||||
|
'Hata!',
|
||||||
|
'Bir hata oluştu.',
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRestore = async () => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: 'Geri Yükle?',
|
||||||
|
text: "Bu kategori geri yüklenecek!",
|
||||||
|
icon: 'question',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Evet, geri yükle!',
|
||||||
|
cancelButtonText: 'İptal'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await categoryService.restoreCategory(category.id)
|
||||||
|
MySwal.fire(
|
||||||
|
'Geri Yüklendi!',
|
||||||
|
'Kategori başarıyla geri yüklendi.',
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
onRefresh()
|
||||||
|
} catch {
|
||||||
|
MySwal.fire(
|
||||||
|
'Hata!',
|
||||||
|
'Bir hata oluştu.',
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CategoryDialog
|
||||||
|
open={showEditDialog}
|
||||||
|
onOpenChange={setShowEditDialog}
|
||||||
|
category={category}
|
||||||
|
onSuccess={onRefresh}
|
||||||
|
/>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||||
|
<span className="sr-only">Menü aç</span>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuLabel>İşlemler</DropdownMenuLabel>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => navigator.clipboard.writeText(category.id.toString())}
|
||||||
|
>
|
||||||
|
ID Kopyala
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
|
{!isDeleted && (
|
||||||
|
<DropdownMenuItem onClick={() => setShowEditDialog(true)}>
|
||||||
|
<Pencil className="mr-2 h-4 w-4" /> Düzenle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isDeleted ? (
|
||||||
|
<DropdownMenuItem onClick={handleRestore}>
|
||||||
|
<RefreshCcw className="mr-2 h-4 w-4 text-green-600" /> Geri Yükle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
) : (
|
||||||
|
<DropdownMenuItem onClick={handleDelete} className="text-red-600">
|
||||||
|
<Trash className="mr-2 h-4 w-4" /> Sil
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
70
frontend/app/admin/categories/columns.tsx
Normal file
70
frontend/app/admin/categories/columns.tsx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { ColumnDef } from "@tanstack/react-table"
|
||||||
|
import { Category } from "@/types/category"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { ArrowUpDown } from "lucide-react"
|
||||||
|
import { DataTableRowActions } from "./category-row-actions"
|
||||||
|
|
||||||
|
export const getColumns = (onRefresh: () => void, categories: Category[]): ColumnDef<Category>[] => [
|
||||||
|
{
|
||||||
|
accessorKey: "id",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
ID
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "title",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Başlık
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "slug",
|
||||||
|
header: "Slug",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "parent_id",
|
||||||
|
header: "Üst Kategori",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const pid = row.original.parent_id
|
||||||
|
if (!pid || pid === 0) return "-"
|
||||||
|
|
||||||
|
const parent = categories.find(c => c.id === pid)
|
||||||
|
return parent ? parent.title : pid
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "deleted_at",
|
||||||
|
header: "Durum",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const deletedAt = row.original.deleted_at
|
||||||
|
return deletedAt ? (
|
||||||
|
<Badge variant="destructive">Silindi</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="outline" className="bg-green-50 text-green-700 border-green-200">Aktif</Badge>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
cell: ({ row }) => <DataTableRowActions row={row} onRefresh={onRefresh} />,
|
||||||
|
},
|
||||||
|
]
|
||||||
91
frontend/app/admin/categories/data-table.tsx
Normal file
91
frontend/app/admin/categories/data-table.tsx
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
SortingState,
|
||||||
|
getSortedRowModel,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[]
|
||||||
|
data: TData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table.getRowModel().rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||||
|
Sonuç bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
115
frontend/app/admin/categories/page.tsx
Normal file
115
frontend/app/admin/categories/page.tsx
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState, useCallback } from "react"
|
||||||
|
import { DataTable } from "./data-table"
|
||||||
|
import { getColumns } from "./columns"
|
||||||
|
import { Category } from "@/types/category"
|
||||||
|
import { categoryService } from "@/services/categoryService"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import { CategoryDialog } from "./category-dialog"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
|
export default function CategoriesPage() {
|
||||||
|
const [data, setData] = useState<Category[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
|
const [perPage] = useState(20)
|
||||||
|
const [search, setSearch] = useState("")
|
||||||
|
const [statusFilter, setStatusFilter] = useState("with") // "with", "active", "only"
|
||||||
|
const [showCreateDialog, setShowCreateDialog] = useState(false)
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const apiSoftFilter = statusFilter === "active" ? "" : statusFilter
|
||||||
|
const res = await categoryService.getCategories(page, perPage, search, apiSoftFilter)
|
||||||
|
setData(res.items || [])
|
||||||
|
setTotal(res.total || 0)
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Categories fetch error:", error)
|
||||||
|
setData([])
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [page, perPage, search, statusFilter])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchData()
|
||||||
|
}, [fetchData])
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(total / perPage)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-8">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Kategori Yönetimi</h1>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Kategorileri oluşturun, düzenleyin veya silin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button onClick={() => setShowCreateDialog(true)}>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Kategori
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center py-4 gap-4">
|
||||||
|
<Input
|
||||||
|
placeholder="Kategori ara..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
className="max-w-sm"
|
||||||
|
/>
|
||||||
|
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Durum" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="with">Tümü (Kategoriler)</SelectItem>
|
||||||
|
<SelectItem value="active">Sadece Aktif</SelectItem>
|
||||||
|
<SelectItem value="only">Sadece Silinenler</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DataTable columns={getColumns(fetchData, data)} data={data} />
|
||||||
|
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPage((old) => Math.max(old - 1, 1))}
|
||||||
|
disabled={page === 1 || loading}
|
||||||
|
>
|
||||||
|
Önceki
|
||||||
|
</Button>
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
Sayfa {page} / {totalPages || 1}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPage((old) => (data.length === perPage ? old + 1 : old))}
|
||||||
|
disabled={page >= totalPages || loading}
|
||||||
|
>
|
||||||
|
Sonraki
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CategoryDialog
|
||||||
|
open={showCreateDialog}
|
||||||
|
onOpenChange={setShowCreateDialog}
|
||||||
|
onSuccess={fetchData}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
59
frontend/app/admin/heroes/_components/columns.tsx
Normal file
59
frontend/app/admin/heroes/_components/columns.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { ColumnDef } from "@tanstack/react-table"
|
||||||
|
import { Hero } from "@/types/hero"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { HeroRowActions } from "./hero-row-actions"
|
||||||
|
|
||||||
|
export const getColumns = (onSuccess: () => void): ColumnDef<Hero>[] => [
|
||||||
|
{
|
||||||
|
accessorKey: "image",
|
||||||
|
header: "Görsel",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const imagePath = row.getValue("image") as string
|
||||||
|
if (!imagePath) return <div className="w-16 h-9 bg-gray-100 rounded" />
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-24 h-14 relative rounded overflow-hidden border">
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img
|
||||||
|
src={`${process.env.NEXT_PUBLIC_API_URL}${imagePath}`}
|
||||||
|
alt={row.original.title}
|
||||||
|
className="object-cover w-full h-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "title",
|
||||||
|
header: "Başlık",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "is_active",
|
||||||
|
header: "Durum",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const isActive = row.getValue("is_active") as boolean
|
||||||
|
return (
|
||||||
|
<Badge variant={isActive ? "default" : "secondary"}>
|
||||||
|
{isActive ? "Aktif" : "Pasif"}
|
||||||
|
</Badge>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "DeletedAt",
|
||||||
|
header: "Silinme Durumu",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const deletedAt = row.getValue("DeletedAt")
|
||||||
|
if (deletedAt) {
|
||||||
|
return <Badge variant="destructive">Silinmiş</Badge>
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
cell: ({ row }) => <HeroRowActions row={row} onSuccess={onSuccess} />,
|
||||||
|
},
|
||||||
|
]
|
||||||
82
frontend/app/admin/heroes/_components/data-table.tsx
Normal file
82
frontend/app/admin/heroes/_components/data-table.tsx
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[]
|
||||||
|
data: TData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
// eslint-disable-next-line react-hooks/incompatible-library
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table.getRowModel().rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||||
|
Sonuç bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
384
frontend/app/admin/heroes/_components/hero-dialog.tsx
Normal file
384
frontend/app/admin/heroes/_components/hero-dialog.tsx
Normal file
@@ -0,0 +1,384 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
FormDescription,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Switch } from "@/components/ui/switch"
|
||||||
|
import { Hero } from "@/types/hero"
|
||||||
|
import { heroService } from "@/services/heroService"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
// Zod Schema
|
||||||
|
const formSchema = z.object({
|
||||||
|
title: z.string().min(2, "Başlık en az 2 karakter olmalıdır"),
|
||||||
|
text1: z.string().optional(),
|
||||||
|
text2: z.string().optional(),
|
||||||
|
text4: z.string().optional(),
|
||||||
|
text5: z.string().optional(),
|
||||||
|
color: z.string().optional(),
|
||||||
|
is_active: z.boolean(),
|
||||||
|
width: z.coerce.number().min(1, "Genişlik 0'dan büyük olmalıdır"),
|
||||||
|
height: z.coerce.number().min(1, "Yükseklik 0'dan büyük olmalıdır"),
|
||||||
|
quality: z.coerce.number().min(1).max(100).default(85),
|
||||||
|
format: z.string().optional().default("avif"),
|
||||||
|
image: z.any().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
interface HeroDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
hero?: Hero | null
|
||||||
|
onSuccess?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HeroDialog({ open, onOpenChange, hero, onSuccess }: HeroDialogProps) {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [preview, setPreview] = useState<string | null>(null)
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
resolver: zodResolver(formSchema) as any,
|
||||||
|
defaultValues: {
|
||||||
|
title: "",
|
||||||
|
text1: "",
|
||||||
|
text2: "",
|
||||||
|
text4: "",
|
||||||
|
text5: "",
|
||||||
|
color: "#000000",
|
||||||
|
is_active: true,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
quality: 85,
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hero) {
|
||||||
|
form.reset({
|
||||||
|
title: hero.title,
|
||||||
|
text1: hero.text1 || "",
|
||||||
|
text2: hero.text2 || "",
|
||||||
|
text4: hero.text4 || "",
|
||||||
|
text5: hero.text5 || "",
|
||||||
|
color: hero.color || "#000000",
|
||||||
|
is_active: !!hero.is_active,
|
||||||
|
width: hero.width || 0,
|
||||||
|
height: hero.height || 0,
|
||||||
|
quality: hero.quality || 85,
|
||||||
|
format: hero.format || "avif",
|
||||||
|
})
|
||||||
|
// Existing image preview
|
||||||
|
// Backend returns relative path usually, ensure full URL if needed or use as is
|
||||||
|
// Assuming backend/frontend serve static files correctly
|
||||||
|
setPreview(hero.image ? `${process.env.NEXT_PUBLIC_API_URL}${hero.image}` : null)
|
||||||
|
} else {
|
||||||
|
form.reset({
|
||||||
|
title: "",
|
||||||
|
text1: "",
|
||||||
|
text2: "",
|
||||||
|
text4: "",
|
||||||
|
text5: "",
|
||||||
|
color: "#000000",
|
||||||
|
is_active: true,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
quality: 85,
|
||||||
|
format: "avif",
|
||||||
|
})
|
||||||
|
setPreview(null)
|
||||||
|
}
|
||||||
|
}, [hero, form, open])
|
||||||
|
|
||||||
|
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const file = e.target.files?.[0]
|
||||||
|
if (file) {
|
||||||
|
form.setValue("image", file)
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onloadend = () => {
|
||||||
|
setPreview(reader.result as string)
|
||||||
|
}
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSubmit = async (values: z.infer<typeof formSchema>) => {
|
||||||
|
setLoading(true)
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append("title", values.title)
|
||||||
|
if (values.text1) formData.append("text1", values.text1)
|
||||||
|
if (values.text2) formData.append("text2", values.text2)
|
||||||
|
if (values.text4) formData.append("text4", values.text4)
|
||||||
|
if (values.text5) formData.append("text5", values.text5)
|
||||||
|
if (values.color) formData.append("color", values.color)
|
||||||
|
formData.append("is_active", String(values.is_active))
|
||||||
|
|
||||||
|
// New fields
|
||||||
|
formData.append("width", String(values.width))
|
||||||
|
formData.append("height", String(values.height))
|
||||||
|
formData.append("quality", String(values.quality))
|
||||||
|
if (values.format) formData.append("format", values.format)
|
||||||
|
|
||||||
|
if (values.image instanceof File) {
|
||||||
|
formData.append("image", values.image)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (hero) {
|
||||||
|
await heroService.updateHero(hero.ID, formData)
|
||||||
|
toast.success("Hero başarıyla güncellendi")
|
||||||
|
} else {
|
||||||
|
await heroService.createHero(formData)
|
||||||
|
toast.success("Hero başarıyla oluşturuldu")
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
if (onSuccess) onSuccess()
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.error("Hero save error:", error)
|
||||||
|
toast.error((error as Error).message || "Bir hata oluştu")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{hero ? "Hero Düzenle" : "Yeni Hero Ekle"}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Başlık</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Başlık" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="text1"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Text 1</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Text 1" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="text2"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Text 2</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Text 2" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="text4"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Text 4</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Text 4" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="text5"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Text 5</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Text 5" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="width"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Genişlik (px)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="number" placeholder="0" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="height"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Yükseklik (px)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="number" placeholder="0" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="quality"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Kalite (1-100)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="number" min="1" max="100" placeholder="80" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="format"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Format</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Format Seçin" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="avif">AVIF (Önerilen)</SelectItem>
|
||||||
|
<SelectItem value="webp">WebP</SelectItem>
|
||||||
|
<SelectItem value="jpeg">JPEG</SelectItem>
|
||||||
|
<SelectItem value="png">PNG</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="color"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Renk (Hex)</FormLabel>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<FormControl>
|
||||||
|
<Input type="color" className="w-12 h-10 p-1" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="#000000" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
</div>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="is_active"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm">
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
<FormLabel>Aktif</FormLabel>
|
||||||
|
<FormDescription>
|
||||||
|
Bu hero banner sitede görüntülensin mi?
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
<FormControl>
|
||||||
|
<Switch
|
||||||
|
checked={field.value}
|
||||||
|
onCheckedChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Görsel</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
onChange={handleImageChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
{preview && (
|
||||||
|
<div className="mt-2 relative w-full h-40 border rounded-md overflow-hidden">
|
||||||
|
{/* Note: Using standard img for now to avoid Next.js Image Config issues with localhost */}
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img
|
||||||
|
src={preview}
|
||||||
|
alt="Preview"
|
||||||
|
className="object-cover w-full h-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</FormItem>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
122
frontend/app/admin/heroes/_components/hero-row-actions.tsx
Normal file
122
frontend/app/admin/heroes/_components/hero-row-actions.tsx
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState } from "react"
|
||||||
|
import { Row } from "@tanstack/react-table"
|
||||||
|
import { MoreHorizontal, Pencil, Trash, Undo } from "lucide-react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Hero } from "@/types/hero"
|
||||||
|
import { heroService } from "@/services/heroService"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { HeroDialog } from "./hero-dialog"
|
||||||
|
import Swal from "sweetalert2"
|
||||||
|
|
||||||
|
interface DataTableRowActionsProps<TData> {
|
||||||
|
row: Row<TData>
|
||||||
|
onSuccess: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HeroRowActions<TData extends Hero>({
|
||||||
|
row,
|
||||||
|
onSuccess,
|
||||||
|
}: DataTableRowActionsProps<TData>) {
|
||||||
|
const hero = row.original
|
||||||
|
const [showEditDialog, setShowEditDialog] = useState(false)
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
const result = await Swal.fire({
|
||||||
|
title: "Emin misiniz?",
|
||||||
|
text: "Bu hero silinecek! (Geri alabilirsiniz)",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Evet, sil",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await heroService.deleteHero(hero.ID)
|
||||||
|
toast.success("Hero başarıyla silindi")
|
||||||
|
onSuccess()
|
||||||
|
} catch {
|
||||||
|
toast.error("Silme işlemi başarısız")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRestore = async () => {
|
||||||
|
const result = await Swal.fire({
|
||||||
|
title: "Geri yüklemek istiyor musunuz?",
|
||||||
|
text: "Bu hero tekrar aktif listeye alınacak.",
|
||||||
|
icon: "question",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Evet, geri yükle",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await heroService.restoreHero(hero.ID)
|
||||||
|
toast.success("Hero başarıyla geri yüklendi")
|
||||||
|
onSuccess()
|
||||||
|
} catch {
|
||||||
|
toast.error("Geri yükleme işlemi başarısız")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDeleted = !!hero.DeletedAt
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||||
|
<span className="sr-only">Menüyü aç</span>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuLabel>İşlemler</DropdownMenuLabel>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => navigator.clipboard.writeText(hero.ID.toString())}
|
||||||
|
>
|
||||||
|
Hero ID Kopyala
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
|
{!isDeleted && (
|
||||||
|
<>
|
||||||
|
<DropdownMenuItem onClick={() => setShowEditDialog(true)}>
|
||||||
|
<Pencil className="mr-2 h-3.5 w-3.5" /> Düzenle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={handleDelete} className="text-red-600">
|
||||||
|
<Trash className="mr-2 h-3.5 w-3.5" /> Sil
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isDeleted && (
|
||||||
|
<DropdownMenuItem onClick={handleRestore} className="text-green-600">
|
||||||
|
<Undo className="mr-2 h-3.5 w-3.5" /> Geri Yükle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
|
||||||
|
<HeroDialog
|
||||||
|
open={showEditDialog}
|
||||||
|
onOpenChange={setShowEditDialog}
|
||||||
|
hero={hero}
|
||||||
|
onSuccess={onSuccess}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
122
frontend/app/admin/heroes/page.tsx
Normal file
122
frontend/app/admin/heroes/page.tsx
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState, useCallback } from "react"
|
||||||
|
import { DataTable } from "./_components/data-table"
|
||||||
|
import { getColumns } from "./_components/columns"
|
||||||
|
import { Hero } from "@/types/hero"
|
||||||
|
import { heroService } from "@/services/heroService"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import { HeroDialog } from "./_components/hero-dialog"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
|
export default function HeroesPage() {
|
||||||
|
const [data, setData] = useState<Hero[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
|
const [perPage] = useState(20)
|
||||||
|
const [search, setSearch] = useState("")
|
||||||
|
const [statusFilter, setStatusFilter] = useState("with") // "with" shows active + deleted
|
||||||
|
const [showCreateDialog, setShowCreateDialog] = useState(false)
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
// API expects "active" logic differently perhaps?
|
||||||
|
// checking task.md/heroService docs:
|
||||||
|
// heroService.getHeroes(page, perPage, search, soft)
|
||||||
|
// soft: 'only' | 'with' | empty (defaults to active in some apis, but checking service impl)
|
||||||
|
|
||||||
|
// From service: soft param defaults to "with".
|
||||||
|
const apiSoftFilter = statusFilter === "active" ? "" : statusFilter
|
||||||
|
|
||||||
|
const res = await heroService.getHeroes(page, perPage, search, apiSoftFilter)
|
||||||
|
setData(res.items || [])
|
||||||
|
setTotal(res.total || 0)
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Heroes fetch error:", error)
|
||||||
|
setData([])
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [page, perPage, search, statusFilter])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchData()
|
||||||
|
}, [fetchData])
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(total / perPage)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-8">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Hero Banner Yönetimi</h1>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Ana sayfa banner alanlarını yönetin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button onClick={() => setShowCreateDialog(true)}>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Hero
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center py-4 gap-4">
|
||||||
|
<Input
|
||||||
|
placeholder="Başlık ara..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
className="max-w-sm"
|
||||||
|
/>
|
||||||
|
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Durum" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="with">Tümü (Dahil)</SelectItem>
|
||||||
|
<SelectItem value="active">Sadece Aktif</SelectItem>
|
||||||
|
<SelectItem value="only">Sadece Silinenler</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DataTable columns={getColumns(fetchData)} data={data} />
|
||||||
|
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPage((old) => Math.max(old - 1, 1))}
|
||||||
|
disabled={page === 1 || loading}
|
||||||
|
>
|
||||||
|
Önceki
|
||||||
|
</Button>
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
Sayfa {page} / {totalPages || 1}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPage((old) => (data.length === perPage || page < totalPages ? old + 1 : old))}
|
||||||
|
disabled={page >= totalPages || loading}
|
||||||
|
>
|
||||||
|
Sonraki
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<HeroDialog
|
||||||
|
open={showCreateDialog}
|
||||||
|
onOpenChange={setShowCreateDialog}
|
||||||
|
onSuccess={fetchData}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
22
frontend/app/admin/layout.tsx
Normal file
22
frontend/app/admin/layout.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { AdminHeader } from "@/components/admin/AdminHeader"
|
||||||
|
import { AdminSidebar } from "@/components/admin/AdminSidebar"
|
||||||
|
import { Toaster } from "@/components/ui/sonner"
|
||||||
|
|
||||||
|
export default function AdminLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen w-full bg-muted/40 font-sans">
|
||||||
|
<AdminSidebar />
|
||||||
|
<div className="flex flex-col flex-1 w-full">
|
||||||
|
<AdminHeader />
|
||||||
|
<main className="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-8">
|
||||||
|
{children}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
<Toaster />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
50
frontend/app/admin/page.tsx
Normal file
50
frontend/app/admin/page.tsx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useSession, signOut } from "next-auth/react"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useEffect } from "react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
|
export default function AdminDashboardPage() {
|
||||||
|
const { data: session, status } = useSession()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (status === "unauthenticated") {
|
||||||
|
router.push("/auth/login?callbackUrl=/admin")
|
||||||
|
}
|
||||||
|
}, [status, router])
|
||||||
|
|
||||||
|
if (status === "loading") {
|
||||||
|
return <div className="flex h-screen items-center justify-center">Yükleniyor...</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center justify-between mb-8">
|
||||||
|
<h1 className="text-3xl font-bold">Yönetici Paneli</h1>
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<span>Merhaba, {session?.user?.name || session?.user?.email}</span>
|
||||||
|
<Button variant="outline" onClick={() => signOut({ callbackUrl: "/auth/login" })}>
|
||||||
|
Çıkış Yap
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||||
|
<div className="p-6 bg-white rounded-lg shadow dark:bg-gray-800">
|
||||||
|
<h3 className="text-lg font-semibold mb-2">Toplam Kullanıcı</h3>
|
||||||
|
<p className="text-3xl font-bold">0</p>
|
||||||
|
</div>
|
||||||
|
<div className="p-6 bg-white rounded-lg shadow dark:bg-gray-800">
|
||||||
|
<h3 className="text-lg font-semibold mb-2">Toplam Satış</h3>
|
||||||
|
<p className="text-3xl font-bold">₺0.00</p>
|
||||||
|
</div>
|
||||||
|
<div className="p-6 bg-white rounded-lg shadow dark:bg-gray-800">
|
||||||
|
<h3 className="text-lg font-semibold mb-2">Aktif Siparişler</h3>
|
||||||
|
<p className="text-3xl font-bold">0</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
132
frontend/app/admin/posts/_components/columns.tsx
Normal file
132
frontend/app/admin/posts/_components/columns.tsx
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { ColumnDef } from "@tanstack/react-table"
|
||||||
|
import { Post } from "@/types/post"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Edit, Trash, RotateCcw } from "lucide-react"
|
||||||
|
|
||||||
|
interface PostColumnsProps {
|
||||||
|
onEdit: (post: Post) => void
|
||||||
|
onDelete: (id: number) => void
|
||||||
|
onRestore: (id: number) => void
|
||||||
|
statusFilter: string
|
||||||
|
deletedIds: number[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getPostColumns = ({ onEdit, onDelete, onRestore, statusFilter, deletedIds }: PostColumnsProps): ColumnDef<Post>[] => [
|
||||||
|
{
|
||||||
|
accessorKey: "images",
|
||||||
|
header: "Görsel",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const rawImages = row.original.images
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080"
|
||||||
|
|
||||||
|
// Backend tarafında "images" alanı virgülle ayrılmış birden fazla path içerebilir.
|
||||||
|
// Liste görünümünde ilk path'i küçük görsel için kullanalım.
|
||||||
|
const firstImage = rawImages
|
||||||
|
? rawImages
|
||||||
|
.split(",")
|
||||||
|
.map(p => p.trim())
|
||||||
|
.filter(Boolean)[0]
|
||||||
|
: null
|
||||||
|
|
||||||
|
const fullUrl = firstImage
|
||||||
|
? (firstImage.startsWith("http") ? firstImage : `${apiUrl}${firstImage}`)
|
||||||
|
: null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-16 h-10 bg-gray-100 rounded overflow-hidden flex items-center justify-center">
|
||||||
|
{fullUrl ? (
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
|
<img src={fullUrl} alt={row.original.title} className="w-full h-full object-cover" />
|
||||||
|
) : (
|
||||||
|
<span className="text-xs text-gray-400">Yok</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "title",
|
||||||
|
header: "Başlık",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "categories",
|
||||||
|
header: "Kategoriler",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
{row.original.categories?.map((cat, index) => (
|
||||||
|
<span key={cat.id || cat.title || index} className="px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded-full">
|
||||||
|
{cat.title}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "tags",
|
||||||
|
header: "Etiketler",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
{row.original.tags?.map((tag, index) => (
|
||||||
|
<span key={tag.id || tag.name || index} className="px-2 py-1 bg-gray-100 text-gray-800 text-xs rounded-full">
|
||||||
|
{tag.name}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updated_at",
|
||||||
|
header: "Son Güncelleme",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const updatedAt = row.original.updated_at || row.original.UpdatedAt
|
||||||
|
return updatedAt ? new Date(updatedAt).toLocaleDateString("tr-TR") : "-"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const id = row.original.id || row.original.ID
|
||||||
|
const inDeletedList = typeof id === "number" && deletedIds.includes(id)
|
||||||
|
|
||||||
|
// "Sadece Silinenler" filtresinde hepsi silinmiş kabul edilir.
|
||||||
|
// "Tümü (Dahil)" filtresinde ise deletedIds listesine bakılır.
|
||||||
|
const isDeleted = statusFilter === "only" || inDeletedList
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2 justify-end">
|
||||||
|
{isDeleted ? (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onRestore(row.original.id || row.original.ID!)}
|
||||||
|
className="h-8 w-8 p-0 text-green-600 hover:text-green-700 hover:bg-green-50"
|
||||||
|
title="Geri Yükle"
|
||||||
|
>
|
||||||
|
<RotateCcw className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onEdit(row.original)}
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onDelete(row.original.id || row.original.ID!)}
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
>
|
||||||
|
<Trash className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
437
frontend/app/admin/posts/_components/post-dialog.tsx
Normal file
437
frontend/app/admin/posts/_components/post-dialog.tsx
Normal file
@@ -0,0 +1,437 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import { Post } from "@/types/post"
|
||||||
|
import { categoryService } from "@/services/categoryService"
|
||||||
|
import { postService } from "@/services/postService"
|
||||||
|
import { tagService } from "@/services/tagService"
|
||||||
|
import { Category } from "@/types/category"
|
||||||
|
import { Tag } from "@/types/tag"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import { useSlug } from "@/hooks/useSlug"
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||||
|
|
||||||
|
// MultiSelect component specifically for Shadcn UI
|
||||||
|
// Since Shadcn doesn't have a native MultiSelect, we'll use a simple implementation or standard select with multiple
|
||||||
|
// For better UI, using a basic select list for now, ideally should use a proper MultiSelect component
|
||||||
|
const MultiSelect = ({
|
||||||
|
options,
|
||||||
|
selected,
|
||||||
|
onChange
|
||||||
|
}: {
|
||||||
|
options: { label: string; value: string }[]
|
||||||
|
selected: string[]
|
||||||
|
onChange: (values: string[]) => void
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div className="border rounded-md p-2 max-h-40 overflow-y-auto">
|
||||||
|
{options.map((option) => (
|
||||||
|
<div key={option.value} className="flex items-center gap-2 mb-1">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id={`opt-${option.value}`}
|
||||||
|
checked={selected.includes(option.value)}
|
||||||
|
onChange={(e) => {
|
||||||
|
if (e.target.checked) {
|
||||||
|
onChange([...selected, option.value])
|
||||||
|
} else {
|
||||||
|
onChange(selected.filter((v) => v !== option.value))
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary"
|
||||||
|
/>
|
||||||
|
<label htmlFor={`opt-${option.value}`} className="text-sm cursor-pointer select-none">
|
||||||
|
{option.label}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{options.length === 0 && <p className="text-sm text-gray-500 py-2 text-center">Veri bulunamadı.</p>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
title: z.string().min(2, "Başlık en az 2 karakter olmalı"),
|
||||||
|
slug: z.string().min(2, "Slug en az 2 karakter olmalı"),
|
||||||
|
content: z.string().min(10, "İçerik en az 10 karakter olmalı"),
|
||||||
|
category_ids: z.array(z.string()).min(1, "En az bir kategori seçilmelidir"),
|
||||||
|
tag_names: z.array(z.string()).optional(), // Changed to array for MultiSelect
|
||||||
|
|
||||||
|
// Image Config
|
||||||
|
images: z.any().optional(),
|
||||||
|
width: z.coerce.number().min(1).default(800),
|
||||||
|
height: z.coerce.number().min(1).default(600),
|
||||||
|
quality: z.coerce.number().min(1).max(100).default(85),
|
||||||
|
format: z.string().default("webp"),
|
||||||
|
})
|
||||||
|
|
||||||
|
interface PostDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
post?: Post | null
|
||||||
|
onSuccess?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PostDialog({ open, onOpenChange, post, onSuccess }: PostDialogProps) {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [categories, setCategories] = useState<Category[]>([])
|
||||||
|
const [tags, setTags] = useState<Tag[]>([])
|
||||||
|
const [preview, setPreview] = useState<string | null>(null)
|
||||||
|
const { slugify } = useSlug()
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
resolver: zodResolver(formSchema) as any,
|
||||||
|
defaultValues: {
|
||||||
|
title: "",
|
||||||
|
slug: "",
|
||||||
|
content: "",
|
||||||
|
category_ids: [],
|
||||||
|
tag_names: [],
|
||||||
|
width: 800,
|
||||||
|
height: 600,
|
||||||
|
quality: 85,
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadData = async () => {
|
||||||
|
try {
|
||||||
|
const catRes = await categoryService.getCategories(1, 100)
|
||||||
|
setCategories(catRes.items || [])
|
||||||
|
|
||||||
|
const tagRes = await tagService.getTags(1, 100)
|
||||||
|
setTags(tagRes.items || [])
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load categories/tags", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (open) {
|
||||||
|
loadData()
|
||||||
|
}
|
||||||
|
}, [open])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (post) {
|
||||||
|
const categoryIds =
|
||||||
|
post.categories
|
||||||
|
?.map(c => {
|
||||||
|
const id = c.id ?? c.ID
|
||||||
|
return id != null ? id.toString() : null
|
||||||
|
})
|
||||||
|
.filter((id): id is string => !!id) || []
|
||||||
|
|
||||||
|
form.reset({
|
||||||
|
title: post.title,
|
||||||
|
slug: post.slug,
|
||||||
|
content: post.content,
|
||||||
|
category_ids: categoryIds,
|
||||||
|
tag_names: post.tags?.map(t => t.name) || [],
|
||||||
|
width: post.width || 800,
|
||||||
|
height: post.height || 600,
|
||||||
|
quality: post.quality || 85,
|
||||||
|
format: post.format || "webp",
|
||||||
|
})
|
||||||
|
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080"
|
||||||
|
if (post.images) {
|
||||||
|
// Backend \"images\" alanı birden fazla path'i virgülle birleştirebiliyor.
|
||||||
|
// Dialog önizlemesi için ilk path'i kullan.
|
||||||
|
const firstImage = post.images
|
||||||
|
.split(",")
|
||||||
|
.map(p => p.trim())
|
||||||
|
.filter(Boolean)[0]
|
||||||
|
|
||||||
|
if (firstImage) {
|
||||||
|
setPreview(firstImage.startsWith("http") ? firstImage : `${apiUrl}${firstImage}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
form.reset({
|
||||||
|
title: "",
|
||||||
|
slug: "",
|
||||||
|
content: "",
|
||||||
|
category_ids: [],
|
||||||
|
tag_names: [],
|
||||||
|
width: 800,
|
||||||
|
height: 600,
|
||||||
|
quality: 85,
|
||||||
|
format: "webp",
|
||||||
|
})
|
||||||
|
setPreview(null)
|
||||||
|
}
|
||||||
|
}, [post, form, open])
|
||||||
|
|
||||||
|
const handleTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const title = e.target.value
|
||||||
|
form.setValue("title", title)
|
||||||
|
if (!post) { // Only auto-slug on create
|
||||||
|
form.setValue("slug", slugify(title))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const file = e.target.files?.[0]
|
||||||
|
if (file) {
|
||||||
|
form.setValue("images", file)
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onloadend = () => {
|
||||||
|
setPreview(reader.result as string)
|
||||||
|
}
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSubmit = async (values: z.infer<typeof formSchema>) => {
|
||||||
|
setLoading(true)
|
||||||
|
const formData = new FormData()
|
||||||
|
|
||||||
|
formData.append("title", values.title)
|
||||||
|
formData.append("slug", values.slug)
|
||||||
|
formData.append("content", values.content)
|
||||||
|
|
||||||
|
// Append categories - Backend likely expects multiple fields with same name or comma separated
|
||||||
|
// Based on curl example: -F 'category_ids=1'
|
||||||
|
// If multiple, standard is usually repeating the field
|
||||||
|
values.category_ids.forEach(id => {
|
||||||
|
formData.append("category_ids", id)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Tags - Backend, dokümana göre tekrar eden 'tag_names' alanlarını bekliyor:
|
||||||
|
// -F 'tag_names=tag1' -F 'tag_names=tag2'
|
||||||
|
if (values.tag_names && values.tag_names.length > 0) {
|
||||||
|
values.tag_names.forEach(name => {
|
||||||
|
formData.append("tag_names", name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image config
|
||||||
|
formData.append("width", values.width.toString())
|
||||||
|
formData.append("height", values.height.toString())
|
||||||
|
formData.append("quality", values.quality.toString())
|
||||||
|
formData.append("format", values.format)
|
||||||
|
|
||||||
|
if (values.images instanceof File) {
|
||||||
|
formData.append("images", values.images)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (post) {
|
||||||
|
await postService.updatePost(post.id || post.ID!, formData)
|
||||||
|
toast.success("Yazı başarıyla güncellendi")
|
||||||
|
} else {
|
||||||
|
await postService.createPost(formData)
|
||||||
|
toast.success("Yazı başarıyla oluşturuldu")
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
if (onSuccess) onSuccess()
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.error("Post save error:", error)
|
||||||
|
toast.error((error as Error).message || "Bir hata oluştu")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[800px] h-[90vh] overflow-y-auto flex flex-col">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{post ? "Yazı Düzenle" : "Yeni Yazı Ekle"}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto py-2">
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<Tabs defaultValue="content" className="w-full">
|
||||||
|
<TabsList className="grid w-full grid-cols-2">
|
||||||
|
<TabsTrigger value="content">İçerik</TabsTrigger>
|
||||||
|
<TabsTrigger value="media">Medya & SEO</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
{/* CONTENT TAB */}
|
||||||
|
<TabsContent value="content" className="space-y-4 pt-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Başlık</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Yazı Başlığı" {...field} onChange={handleTitleChange} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="slug"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>SEO URL (Slug)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="yazi-basligi" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="category_ids"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Kategoriler</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<MultiSelect
|
||||||
|
options={categories.map(c => ({ label: c.title, value: c.id.toString() }))}
|
||||||
|
selected={field.value}
|
||||||
|
onChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="tag_names"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Etiketler</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<MultiSelect
|
||||||
|
options={tags.map(t => ({ label: t.name, value: t.name }))}
|
||||||
|
selected={field.value || []}
|
||||||
|
onChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="content"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>İçerik</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea className="min-h-[300px]" placeholder="Yazı içeriği..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
{/* MEDIA TAB */}
|
||||||
|
<TabsContent value="media" className="space-y-4 pt-4">
|
||||||
|
<div className="border p-4 rounded-md space-y-4">
|
||||||
|
<h3 className="font-semibold text-lg">Öne Çıkan Görsel</h3>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="width"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Genişlik</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="height"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Yükseklik</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="quality"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Kalite</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="format"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Format</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger><SelectValue placeholder="Format" /></SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="webp">WebP</SelectItem>
|
||||||
|
<SelectItem value="avif">AVIF</SelectItem>
|
||||||
|
<SelectItem value="jpeg">JPEG</SelectItem>
|
||||||
|
<SelectItem value="png">PNG</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Görsel Dosyası</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="file" accept="image/*" onChange={handleImageChange} />
|
||||||
|
</FormControl>
|
||||||
|
{preview && (
|
||||||
|
<div className="mt-2 w-full h-48 bg-gray-100 rounded flex items-center justify-center overflow-hidden border">
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img src={preview} alt="Preview" className="h-full object-contain" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</FormItem>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
238
frontend/app/admin/posts/page.tsx
Normal file
238
frontend/app/admin/posts/page.tsx
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState, useCallback } from "react"
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
import { DataTable } from "@/components/ui/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import { postService } from "@/services/postService"
|
||||||
|
import { Post } from "@/types/post"
|
||||||
|
import { PostDialog } from "./_components/post-dialog"
|
||||||
|
import { getPostColumns } from "./_components/columns"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import Swal from "sweetalert2"
|
||||||
|
import withReactContent from "sweetalert2-react-content"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
|
const MySwal = withReactContent(Swal)
|
||||||
|
|
||||||
|
export default function PostsPage() {
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const [posts, setPosts] = useState<Post[]>([])
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [perPage] = useState(10)
|
||||||
|
const [search, setSearch] = useState("")
|
||||||
|
const [statusFilter, setStatusFilter] = useState("with") // "with" | "only" (backend defaults to active if not with/only)
|
||||||
|
const [dialogOpen, setDialogOpen] = useState(false)
|
||||||
|
const [deletedIds, setDeletedIds] = useState<number[]>([])
|
||||||
|
const [selectedPost, setSelectedPost] = useState<Post | null>(null)
|
||||||
|
|
||||||
|
const fetchPosts = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const res = await postService.getPosts(page, perPage, search, statusFilter)
|
||||||
|
|
||||||
|
// Liste verisini al
|
||||||
|
const baseItems = res.items || []
|
||||||
|
|
||||||
|
// images alanı boş olanlar için, detay endpoint'inden gerçek images değerini çek
|
||||||
|
const itemsWithImages = await Promise.all(
|
||||||
|
baseItems.map(async (p) => {
|
||||||
|
if (p.images && p.images.trim() !== "") {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
const id = p.id || p.ID
|
||||||
|
if (!id) {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const detail = await postService.getPost(id)
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
images: detail.data.images,
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
setPosts(itemsWithImages)
|
||||||
|
setTotal(res.total)
|
||||||
|
|
||||||
|
// Silinmiş post ID'lerini ayrıca takip et:
|
||||||
|
if (statusFilter === "only") {
|
||||||
|
const ids = itemsWithImages
|
||||||
|
.map(p => p.id || p.ID)
|
||||||
|
.filter((id): id is number => typeof id === "number")
|
||||||
|
setDeletedIds(ids)
|
||||||
|
} else if (statusFilter === "with") {
|
||||||
|
// 'with' görünümünde, silinmişleri ayrı bir çağrı ile çekelim
|
||||||
|
try {
|
||||||
|
const deletedRes = await postService.getPosts(1, 200, search, "only")
|
||||||
|
const ids = (deletedRes.items || [])
|
||||||
|
.map(p => p.id || p.ID)
|
||||||
|
.filter((id): id is number => typeof id === "number")
|
||||||
|
setDeletedIds(ids)
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Silinmiş yazılar alınamadı:", e)
|
||||||
|
setDeletedIds([])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Sadece aktif filtresinde silinmiş saymayalım
|
||||||
|
setDeletedIds([])
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Yazılar yüklenirken hata oluştu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}, [page, perPage, search, statusFilter])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (session) {
|
||||||
|
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||||
|
fetchPosts()
|
||||||
|
}
|
||||||
|
}, [session, fetchPosts])
|
||||||
|
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: "Emin misiniz?",
|
||||||
|
text: "Bu yazıyı silmek istediğinize emin misiniz?",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Evet, Sil",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
customClass: {
|
||||||
|
popup: "dark:bg-gray-800 dark:text-white",
|
||||||
|
title: "dark:text-white",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await postService.deletePost(id)
|
||||||
|
toast.success("Yazı başarıyla silindi")
|
||||||
|
fetchPosts()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Silme işlemi başarısız oldu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRestore = async (id: number) => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: "Geri Yükle?",
|
||||||
|
text: "Bu yazıyı geri yüklemek istediğinize emin misiniz?",
|
||||||
|
icon: "question",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Evet, Geri Yükle",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
customClass: {
|
||||||
|
popup: "dark:bg-gray-800 dark:text-white",
|
||||||
|
title: "dark:text-white",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await postService.restorePost(id)
|
||||||
|
toast.success("Yazı başarıyla geri yüklendi")
|
||||||
|
fetchPosts()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Geri yükleme başarısız oldu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEdit = async (post: Post) => {
|
||||||
|
try {
|
||||||
|
const id = post.id || post.ID
|
||||||
|
if (!id) {
|
||||||
|
toast.error("Yazı ID'si bulunamadı")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detay endpoint'inden güncel veriyi çek
|
||||||
|
const res = await postService.getPost(id)
|
||||||
|
setSelectedPost(res.data)
|
||||||
|
setDialogOpen(true)
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Yazı detayı alınamadı:", error)
|
||||||
|
toast.error("Yazı detayı alınamadı")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCreate = () => {
|
||||||
|
setSelectedPost(null)
|
||||||
|
setDialogOpen(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = getPostColumns({
|
||||||
|
onEdit: handleEdit,
|
||||||
|
onDelete: handleDelete,
|
||||||
|
onRestore: handleRestore,
|
||||||
|
statusFilter,
|
||||||
|
deletedIds,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-8">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Blog Yazıları</h1>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Blog içeriğini, kategorileri ve etiketleri yönetin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button onClick={handleCreate}>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Yazı
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center py-4 gap-4">
|
||||||
|
<Input
|
||||||
|
placeholder="Başlık ara..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
className="max-w-sm"
|
||||||
|
/>
|
||||||
|
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Durum" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="with">Tümü (Dahil)</SelectItem>
|
||||||
|
{/* Backend logic: empty 'soft' param usually means active only, 'only' means deleted only */}
|
||||||
|
<SelectItem value="active">Sadece Aktif</SelectItem>
|
||||||
|
<SelectItem value="only">Sadece Silinenler</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={posts}
|
||||||
|
pageCount={Math.ceil(total / perPage)}
|
||||||
|
page={page}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<PostDialog
|
||||||
|
open={dialogOpen}
|
||||||
|
onOpenChange={setDialogOpen}
|
||||||
|
post={selectedPost}
|
||||||
|
onSuccess={fetchPosts}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
582
frontend/app/admin/settings/_components/setting-dialog.tsx
Normal file
582
frontend/app/admin/settings/_components/setting-dialog.tsx
Normal file
@@ -0,0 +1,582 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
FormDescription,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Switch } from "@/components/ui/switch"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" // Assume these exist or need verify
|
||||||
|
import { Setting } from "@/types/setting"
|
||||||
|
import { settingService } from "@/services/settingService"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
title: z.string().min(2, "Başlık en az 2 karakter olmalı"),
|
||||||
|
slogan: z.string().optional(),
|
||||||
|
url: z.string().url("Geçerli bir URL giriniz").optional().or(z.literal("")),
|
||||||
|
email: z.string().email("Geçerli bir e-posta giriniz").optional().or(z.literal("")),
|
||||||
|
phone: z.string().optional(),
|
||||||
|
address: z.string().optional(),
|
||||||
|
copyright: z.string().optional(),
|
||||||
|
map_embed: z.string().optional(),
|
||||||
|
meta_title: z.string().optional(),
|
||||||
|
meta_description: z.string().optional(),
|
||||||
|
|
||||||
|
// Social
|
||||||
|
facebook: z.string().url().optional().or(z.literal("")),
|
||||||
|
x: z.string().url().optional().or(z.literal("")),
|
||||||
|
instagram: z.string().url().optional().or(z.literal("")),
|
||||||
|
whatsapp: z.string().optional(), // clean number usually
|
||||||
|
linkedin: z.string().url().optional().or(z.literal("")),
|
||||||
|
pinterest: z.string().url().optional().or(z.literal("")),
|
||||||
|
|
||||||
|
// Config
|
||||||
|
is_active: z.boolean().default(false),
|
||||||
|
|
||||||
|
// Images W Logo
|
||||||
|
w_logo: z.any().optional(),
|
||||||
|
w_width: z.coerce.number().min(1).default(100),
|
||||||
|
w_height: z.coerce.number().min(1).default(100),
|
||||||
|
w_quality: z.coerce.number().min(1).max(100).default(85),
|
||||||
|
w_format: z.string().default("avif"),
|
||||||
|
|
||||||
|
// Images B Logo
|
||||||
|
b_logo: z.any().optional(),
|
||||||
|
b_width: z.coerce.number().min(1).default(100),
|
||||||
|
b_height: z.coerce.number().min(1).default(100),
|
||||||
|
b_quality: z.coerce.number().min(1).max(100).default(85),
|
||||||
|
b_format: z.string().default("avif"),
|
||||||
|
})
|
||||||
|
|
||||||
|
interface SettingDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
setting?: Setting | null
|
||||||
|
onSuccess?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SettingDialog({ open, onOpenChange, setting, onSuccess }: SettingDialogProps) {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [wPreview, setWPreview] = useState<string | null>(null)
|
||||||
|
const [bPreview, setBPreview] = useState<string | null>(null)
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
resolver: zodResolver(formSchema) as any,
|
||||||
|
defaultValues: {
|
||||||
|
title: "",
|
||||||
|
slogan: "",
|
||||||
|
url: "",
|
||||||
|
email: "",
|
||||||
|
phone: "",
|
||||||
|
address: "",
|
||||||
|
copyright: "",
|
||||||
|
map_embed: "",
|
||||||
|
meta_title: "",
|
||||||
|
meta_description: "",
|
||||||
|
facebook: "",
|
||||||
|
x: "",
|
||||||
|
instagram: "",
|
||||||
|
whatsapp: "",
|
||||||
|
linkedin: "",
|
||||||
|
pinterest: "",
|
||||||
|
is_active: false,
|
||||||
|
w_width: 100,
|
||||||
|
w_height: 100,
|
||||||
|
w_quality: 85,
|
||||||
|
w_format: "avif",
|
||||||
|
b_width: 100,
|
||||||
|
b_height: 100,
|
||||||
|
b_quality: 85,
|
||||||
|
b_format: "avif",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (setting) {
|
||||||
|
form.reset({
|
||||||
|
title: setting.title,
|
||||||
|
slogan: setting.slogan || "",
|
||||||
|
url: setting.url || "",
|
||||||
|
email: setting.email || "",
|
||||||
|
phone: setting.phone || "",
|
||||||
|
address: setting.address || "",
|
||||||
|
copyright: setting.copyright || "",
|
||||||
|
map_embed: setting.map_embed || "",
|
||||||
|
meta_title: setting.meta_title || "",
|
||||||
|
meta_description: setting.meta_description || "",
|
||||||
|
facebook: setting.facebook || "",
|
||||||
|
x: setting.x || "",
|
||||||
|
instagram: setting.instagram || "",
|
||||||
|
whatsapp: setting.whatsapp || "",
|
||||||
|
linkedin: setting.linkedin || "",
|
||||||
|
pinterest: setting.pinterest || "",
|
||||||
|
is_active: !!setting.is_active,
|
||||||
|
w_width: setting.w_width || 100,
|
||||||
|
w_height: setting.w_height || 100,
|
||||||
|
w_quality: setting.w_quality || 85,
|
||||||
|
w_format: setting.w_format || "avif",
|
||||||
|
b_width: setting.b_width || 100,
|
||||||
|
b_height: setting.b_height || 100,
|
||||||
|
b_quality: setting.b_quality || 85,
|
||||||
|
b_format: setting.b_format || "avif",
|
||||||
|
})
|
||||||
|
|
||||||
|
// Set previews
|
||||||
|
// Assuming backend serves images from a static path, need env URL
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080"
|
||||||
|
if (setting.w_logo) {
|
||||||
|
// Check if it's already a full URL or relative
|
||||||
|
setWPreview(setting.w_logo.startsWith("http") ? setting.w_logo : `${apiUrl}${setting.w_logo}`)
|
||||||
|
}
|
||||||
|
if (setting.b_logo) {
|
||||||
|
setBPreview(setting.b_logo.startsWith("http") ? setting.b_logo : `${apiUrl}${setting.b_logo}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
form.reset({
|
||||||
|
title: "",
|
||||||
|
slogan: "",
|
||||||
|
url: "",
|
||||||
|
email: "",
|
||||||
|
phone: "",
|
||||||
|
address: "",
|
||||||
|
copyright: "",
|
||||||
|
map_embed: "",
|
||||||
|
meta_title: "",
|
||||||
|
meta_description: "",
|
||||||
|
facebook: "",
|
||||||
|
x: "",
|
||||||
|
instagram: "",
|
||||||
|
whatsapp: "",
|
||||||
|
linkedin: "",
|
||||||
|
pinterest: "",
|
||||||
|
is_active: false,
|
||||||
|
w_width: 100,
|
||||||
|
w_height: 100,
|
||||||
|
w_quality: 85,
|
||||||
|
w_format: "avif",
|
||||||
|
b_width: 100,
|
||||||
|
b_height: 100,
|
||||||
|
b_quality: 85,
|
||||||
|
b_format: "avif",
|
||||||
|
})
|
||||||
|
setWPreview(null)
|
||||||
|
setBPreview(null)
|
||||||
|
}
|
||||||
|
}, [setting, form, open])
|
||||||
|
|
||||||
|
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>, fieldName: "w_logo" | "b_logo") => {
|
||||||
|
const file = e.target.files?.[0]
|
||||||
|
if (file) {
|
||||||
|
form.setValue(fieldName, file)
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onloadend = () => {
|
||||||
|
if (fieldName === "w_logo") setWPreview(reader.result as string)
|
||||||
|
else setBPreview(reader.result as string)
|
||||||
|
}
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSubmit = async (values: z.infer<typeof formSchema>) => {
|
||||||
|
setLoading(true)
|
||||||
|
const formData = new FormData()
|
||||||
|
|
||||||
|
// Append basic fields
|
||||||
|
Object.entries(values).forEach(([key, value]) => {
|
||||||
|
if (key !== "w_logo" && key !== "b_logo") {
|
||||||
|
formData.append(key, String(value))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Append images if they are files
|
||||||
|
if (values.w_logo instanceof File) {
|
||||||
|
formData.append("w_logo", values.w_logo)
|
||||||
|
}
|
||||||
|
if (values.b_logo instanceof File) {
|
||||||
|
formData.append("b_logo", values.b_logo)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (setting) {
|
||||||
|
await settingService.updateSetting(setting.ID, formData)
|
||||||
|
toast.success("Ayar başarıyla güncellendi")
|
||||||
|
} else {
|
||||||
|
await settingService.createSetting(formData)
|
||||||
|
toast.success("Ayar başarıyla oluşturuldu")
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
if (onSuccess) onSuccess()
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.error("Setting save error:", error)
|
||||||
|
toast.error((error as Error).message || "Bir hata oluştu")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[800px] h-[90vh] overflow-y-auto flex flex-col">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{setting ? "Ayar Düzenle" : "Yeni Ayar Ekle"}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto py-2">
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<Tabs defaultValue="general" className="w-full">
|
||||||
|
<TabsList className="grid w-full grid-cols-4">
|
||||||
|
<TabsTrigger value="general">Genel</TabsTrigger>
|
||||||
|
<TabsTrigger value="contact">İletişim</TabsTrigger>
|
||||||
|
<TabsTrigger value="social">Sosyal Medya</TabsTrigger>
|
||||||
|
<TabsTrigger value="images">Görseller</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
{/* GENERAL TAB */}
|
||||||
|
<TabsContent value="general" className="space-y-4 pt-4">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Site Başlığı</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Site Başlığı" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="slogan"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Slogan</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Slogan" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="meta_title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Meta Başlığı</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="SEO için Başlık" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="meta_description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Meta Açıklama</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="SEO için Açıklama" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="is_active"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm bg-destructive/10">
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
<FormLabel className="font-bold text-destructive">Aktif Ayar</FormLabel>
|
||||||
|
<FormDescription>
|
||||||
|
Bu ayarı aktif yaparsanız, diğer tüm ayarlar otomatik olarak pasif duruma geçer.
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
<FormControl>
|
||||||
|
<Switch
|
||||||
|
checked={field.value}
|
||||||
|
onCheckedChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
{/* CONTACT TAB */}
|
||||||
|
<TabsContent value="contact" className="space-y-4 pt-4">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="email"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>E-posta</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="ornek@site.com" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="phone"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Telefon</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="+90 555 ..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="url"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Site URL</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="https://site.com" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="address"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Adres</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea placeholder="Adres bilgisi" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="map_embed"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Harita Embed Kodu (Iframe)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea placeholder='<iframe src="..." ...></iframe>' {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="copyright"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Telif Hakkı Metni</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="© 2024 Tüm hakları saklıdır." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
{/* SOCIAL TAB */}
|
||||||
|
<TabsContent value="social" className="space-y-4 pt-4">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField control={form.control} name="facebook" render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Facebook</FormLabel><FormControl><Input placeholder="URL" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)} />
|
||||||
|
<FormField control={form.control} name="x" render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>X (Twitter)</FormLabel><FormControl><Input placeholder="URL" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)} />
|
||||||
|
<FormField control={form.control} name="instagram" render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Instagram</FormLabel><FormControl><Input placeholder="URL" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)} />
|
||||||
|
<FormField control={form.control} name="linkedin" render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>LinkedIn</FormLabel><FormControl><Input placeholder="URL" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)} />
|
||||||
|
<FormField control={form.control} name="pinterest" render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Pinterest</FormLabel><FormControl><Input placeholder="URL" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)} />
|
||||||
|
<FormField control={form.control} name="whatsapp" render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Whatsapp</FormLabel><FormControl><Input placeholder="Numara" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)} />
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
{/* IMAGES TAB */}
|
||||||
|
<TabsContent value="images" className="space-y-4 pt-4">
|
||||||
|
{/* White Logo Config */}
|
||||||
|
<div className="border p-4 rounded-md space-y-4">
|
||||||
|
<h3 className="font-semibold text-lg">Beyaz Yazılı Logo (w_logo)</h3>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="w_width"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Genişlik</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="w_height"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Yükseklik</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="w_quality"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Kalite</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="w_format"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Format</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger><SelectValue placeholder="Format" /></SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="avif">AVIF</SelectItem>
|
||||||
|
<SelectItem value="webp">WebP</SelectItem>
|
||||||
|
<SelectItem value="png">PNG</SelectItem>
|
||||||
|
<SelectItem value="jpeg">JPEG</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Logo Dosyası</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="file" accept="image/*" onChange={(e) => handleImageChange(e, "w_logo")} />
|
||||||
|
</FormControl>
|
||||||
|
{wPreview && (
|
||||||
|
<div className="mt-2 w-full h-20 bg-gray-100 rounded flex items-center justify-center overflow-hidden border">
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img src={wPreview} alt="W Logo Preview" className="h-full object-contain" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</FormItem>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Black Logo Config */}
|
||||||
|
<div className="border p-4 rounded-md space-y-4">
|
||||||
|
<h3 className="font-semibold text-lg">Siyah Yazılı Logo (b_logo)</h3>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="b_width"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Genişlik</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="b_height"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Yükseklik</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="b_quality"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem><FormLabel>Kalite</FormLabel><FormControl><Input type="number" {...field} /></FormControl><FormMessage /></FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="b_format"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Format</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger><SelectValue placeholder="Format" /></SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="avif">AVIF</SelectItem>
|
||||||
|
<SelectItem value="webp">WebP</SelectItem>
|
||||||
|
<SelectItem value="png">PNG</SelectItem>
|
||||||
|
<SelectItem value="jpeg">JPEG</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Logo Dosyası</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="file" accept="image/*" onChange={(e) => handleImageChange(e, "b_logo")} />
|
||||||
|
</FormControl>
|
||||||
|
{bPreview && (
|
||||||
|
<div className="mt-2 w-full h-20 bg-gray-100 rounded flex items-center justify-center overflow-hidden border">
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img src={bPreview} alt="B Logo Preview" className="h-full object-contain" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</FormItem>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
229
frontend/app/admin/settings/page.tsx
Normal file
229
frontend/app/admin/settings/page.tsx
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState, useCallback } from "react"
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
import { DataTable } from "@/components/ui/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Plus, Edit, Trash, RotateCcw } from "lucide-react"
|
||||||
|
import { settingService } from "@/services/settingService"
|
||||||
|
import { Setting } from "@/types/setting"
|
||||||
|
import { SettingDialog } from "./_components/setting-dialog"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import Swal from "sweetalert2"
|
||||||
|
import withReactContent from "sweetalert2-react-content"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
|
const MySwal = withReactContent(Swal)
|
||||||
|
|
||||||
|
export default function SettingsPage() {
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const [settings, setSettings] = useState<Setting[]>([])
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [perPage] = useState(10)
|
||||||
|
const [search, setSearch] = useState("")
|
||||||
|
const [statusFilter, setStatusFilter] = useState("with") // "with" | "active" | "only"
|
||||||
|
const [dialogOpen, setDialogOpen] = useState(false)
|
||||||
|
const [selectedSetting, setSelectedSetting] = useState<Setting | null>(null)
|
||||||
|
|
||||||
|
const fetchSettings = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
// "active" -> "" (backend default?), "with" -> "with", "only" -> "only"
|
||||||
|
const apiSoftFilter = statusFilter === "active" ? "" : statusFilter
|
||||||
|
const res = await settingService.getSettings(page, perPage, search, apiSoftFilter)
|
||||||
|
setSettings(res.items || [])
|
||||||
|
setTotal(res.total)
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Ayarlar yüklenirken hata oluştu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}, [page, perPage, search, statusFilter])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (session) {
|
||||||
|
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||||
|
fetchSettings()
|
||||||
|
}
|
||||||
|
}, [session, fetchSettings])
|
||||||
|
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: "Emin misiniz?",
|
||||||
|
text: "Bu ayarı silmek istediğinize emin misiniz?",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Evet, Sil",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
customClass: {
|
||||||
|
popup: "dark:bg-gray-800 dark:text-white",
|
||||||
|
title: "dark:text-white",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await settingService.deleteSetting(id)
|
||||||
|
toast.success("Ayar başarıyla silindi")
|
||||||
|
fetchSettings()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Silme işlemi başarısız oldu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRestore = async (id: number) => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: "Geri Yükle?",
|
||||||
|
text: "Bu ayarı geri yüklemek istediğinize emin misiniz?",
|
||||||
|
icon: "question",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Evet, Geri Yükle",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
customClass: {
|
||||||
|
popup: "dark:bg-gray-800 dark:text-white",
|
||||||
|
title: "dark:text-white",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await settingService.restoreSetting(id)
|
||||||
|
toast.success("Ayar başarıyla geri yüklendi")
|
||||||
|
fetchSettings()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Geri yükleme başarısız oldu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
accessorKey: "title",
|
||||||
|
header: "Başlık",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "is_active",
|
||||||
|
header: "Durum",
|
||||||
|
cell: ({ row }: { row: { original: Setting } }) => (
|
||||||
|
<span
|
||||||
|
className={`px-2 py-1 rounded-full text-xs ${row.original.is_active ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{row.original.is_active ? "Aktif" : "Pasif"}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "UpdatedAt",
|
||||||
|
header: "Son Güncelleme",
|
||||||
|
cell: ({ row }: { row: { original: Setting } }) => {
|
||||||
|
return new Date(row.original.UpdatedAt).toLocaleDateString("tr-TR")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
cell: ({ row }: { row: { original: Setting } }) => {
|
||||||
|
const isDeleted = !!row.original.DeletedAt
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2 justify-end">
|
||||||
|
{isDeleted ? (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleRestore(row.original.ID)}
|
||||||
|
className="h-8 w-8 p-0 text-green-600 hover:text-green-700 hover:bg-green-50"
|
||||||
|
title="Geri Yükle"
|
||||||
|
>
|
||||||
|
<RotateCcw className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedSetting(row.original)
|
||||||
|
setDialogOpen(true)
|
||||||
|
}}
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleDelete(row.original.ID)}
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
>
|
||||||
|
<Trash className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-8">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Site Ayarları</h1>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Genel site ayarlarını ve SEO yapılandırmalarını yönetin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button onClick={() => {
|
||||||
|
setSelectedSetting(null)
|
||||||
|
setDialogOpen(true)
|
||||||
|
}}>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Ayar
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center py-4 gap-4">
|
||||||
|
<Input
|
||||||
|
placeholder="Başlık ara..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
className="max-w-sm"
|
||||||
|
/>
|
||||||
|
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Durum" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="with">Tümü (Dahil)</SelectItem>
|
||||||
|
<SelectItem value="active">Sadece Aktif</SelectItem>
|
||||||
|
<SelectItem value="only">Sadece Silinenler</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={settings}
|
||||||
|
pageCount={Math.ceil(total / perPage)}
|
||||||
|
page={page}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SettingDialog
|
||||||
|
open={dialogOpen}
|
||||||
|
onOpenChange={setDialogOpen}
|
||||||
|
setting={selectedSetting}
|
||||||
|
onSuccess={fetchSettings}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
55
frontend/app/admin/tags/columns.tsx
Normal file
55
frontend/app/admin/tags/columns.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { ColumnDef } from "@tanstack/react-table"
|
||||||
|
import { Tag } from "@/types/tag"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { ArrowUpDown } from "lucide-react"
|
||||||
|
import { DataTableRowActions } from "./tag-row-actions"
|
||||||
|
|
||||||
|
export const getColumns = (onRefresh: () => void): ColumnDef<Tag>[] => [
|
||||||
|
{
|
||||||
|
accessorKey: "id",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
ID
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "name",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Tag Adı
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "deleted_at",
|
||||||
|
header: "Durum",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const deletedAt = row.original.deleted_at
|
||||||
|
return deletedAt ? (
|
||||||
|
<Badge variant="destructive">Silindi</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="outline" className="bg-green-50 text-green-700 border-green-200">Aktif</Badge>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
cell: ({ row }) => <DataTableRowActions row={row} onRefresh={onRefresh} />,
|
||||||
|
},
|
||||||
|
]
|
||||||
91
frontend/app/admin/tags/data-table.tsx
Normal file
91
frontend/app/admin/tags/data-table.tsx
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
SortingState,
|
||||||
|
getSortedRowModel,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[]
|
||||||
|
data: TData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table.getRowModel().rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||||
|
Sonuç bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
115
frontend/app/admin/tags/page.tsx
Normal file
115
frontend/app/admin/tags/page.tsx
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState, useCallback } from "react"
|
||||||
|
import { DataTable } from "./data-table"
|
||||||
|
import { getColumns } from "./columns"
|
||||||
|
import { Tag } from "@/types/tag"
|
||||||
|
import { tagService } from "@/services/tagService"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import { TagDialog } from "./tag-dialog"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
|
export default function TagsPage() {
|
||||||
|
const [data, setData] = useState<Tag[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
|
const [perPage] = useState(20)
|
||||||
|
const [search, setSearch] = useState("")
|
||||||
|
const [statusFilter, setStatusFilter] = useState("with") // "with" shows active + deleted
|
||||||
|
const [showCreateDialog, setShowCreateDialog] = useState(false)
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const apiSoftFilter = statusFilter === "active" ? "" : statusFilter
|
||||||
|
const res = await tagService.getTags(page, perPage, search, apiSoftFilter)
|
||||||
|
setData(res.items || [])
|
||||||
|
setTotal(res.total || 0)
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Tags fetch error:", error)
|
||||||
|
setData([])
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [page, perPage, search, statusFilter])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchData()
|
||||||
|
}, [fetchData])
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(total / perPage)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-8">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Tag Yönetimi</h1>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Tagları oluşturun, düzenleyin veya silin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button onClick={() => setShowCreateDialog(true)}>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Tag
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center py-4 gap-4">
|
||||||
|
<Input
|
||||||
|
placeholder="Tag ara..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
className="max-w-sm"
|
||||||
|
/>
|
||||||
|
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Durum" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="with">Tümü (Tags)</SelectItem>
|
||||||
|
<SelectItem value="active">Sadece Aktif</SelectItem>
|
||||||
|
<SelectItem value="only">Sadece Silinenler</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DataTable columns={getColumns(fetchData)} data={data} />
|
||||||
|
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPage((old) => Math.max(old - 1, 1))}
|
||||||
|
disabled={page === 1 || loading}
|
||||||
|
>
|
||||||
|
Önceki
|
||||||
|
</Button>
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
Sayfa {page} / {totalPages || 1}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPage((old) => (data.length === perPage ? old + 1 : old))}
|
||||||
|
disabled={page >= totalPages || loading}
|
||||||
|
>
|
||||||
|
Sonraki
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<TagDialog
|
||||||
|
open={showCreateDialog}
|
||||||
|
onOpenChange={setShowCreateDialog}
|
||||||
|
onSuccess={fetchData}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
110
frontend/app/admin/tags/tag-dialog.tsx
Normal file
110
frontend/app/admin/tags/tag-dialog.tsx
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Tag } from "@/types/tag"
|
||||||
|
import { tagService } from "@/services/tagService"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
name: z.string().min(2, {
|
||||||
|
message: "Tag adı en az 2 karakter olmalıdır.",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
interface TagDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
tag?: Tag | null // Editing if provided
|
||||||
|
onSuccess?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TagDialog({ open, onOpenChange, tag, onSuccess }: TagDialogProps) {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: {
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Reset form when dialog opens or tag changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (tag) {
|
||||||
|
form.reset({
|
||||||
|
name: tag.name,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
form.reset({
|
||||||
|
name: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [tag, form, open])
|
||||||
|
|
||||||
|
const onSubmit = async (values: z.infer<typeof formSchema>) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
if (tag) {
|
||||||
|
await tagService.updateTag(tag.id, values.name)
|
||||||
|
toast.success("Tag başarıyla güncellendi")
|
||||||
|
} else {
|
||||||
|
await tagService.createTag(values.name)
|
||||||
|
toast.success("Tag başarıyla oluşturuldu")
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
if (onSuccess) {
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
toast.error((error as Error).message || "Bir hata oluştu")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{tag ? "Tag Düzenle" : "Yeni Tag Ekle"}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="name"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Tag Adı</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Teknoloji" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
141
frontend/app/admin/tags/tag-row-actions.tsx
Normal file
141
frontend/app/admin/tags/tag-row-actions.tsx
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState } from "react"
|
||||||
|
import { Row } from "@tanstack/react-table"
|
||||||
|
import { MoreHorizontal, Pencil, Trash, RefreshCcw } from "lucide-react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Tag } from "@/types/tag"
|
||||||
|
import { tagService } from "@/services/tagService"
|
||||||
|
import { TagDialog } from "./tag-dialog"
|
||||||
|
import Swal from 'sweetalert2'
|
||||||
|
import withReactContent from 'sweetalert2-react-content'
|
||||||
|
|
||||||
|
const MySwal = withReactContent(Swal)
|
||||||
|
|
||||||
|
interface DataTableRowActionsProps<TData> {
|
||||||
|
row: Row<TData>
|
||||||
|
onRefresh: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTableRowActions<TData>({
|
||||||
|
row,
|
||||||
|
onRefresh,
|
||||||
|
}: DataTableRowActionsProps<TData>) {
|
||||||
|
const tag = row.original as Tag
|
||||||
|
const [showEditDialog, setShowEditDialog] = useState(false)
|
||||||
|
const isDeleted = !!tag.deleted_at
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: 'Emin misiniz?',
|
||||||
|
text: "Bu tag silinecek!",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Evet, sil!',
|
||||||
|
cancelButtonText: 'İptal'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await tagService.deleteTag(tag.id)
|
||||||
|
MySwal.fire(
|
||||||
|
'Silindi!',
|
||||||
|
'Tag başarıyla silindi.',
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
onRefresh()
|
||||||
|
} catch {
|
||||||
|
MySwal.fire(
|
||||||
|
'Hata!',
|
||||||
|
'Bir hata oluştu.',
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRestore = async () => {
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: 'Geri Yükle?',
|
||||||
|
text: "Bu tag geri yüklenecek!",
|
||||||
|
icon: 'question',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Evet, geri yükle!',
|
||||||
|
cancelButtonText: 'İptal'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
await tagService.restoreTag(tag.id)
|
||||||
|
MySwal.fire(
|
||||||
|
'Geri Yüklendi!',
|
||||||
|
'Tag başarıyla geri yüklendi.',
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
onRefresh()
|
||||||
|
} catch {
|
||||||
|
MySwal.fire(
|
||||||
|
'Hata!',
|
||||||
|
'Bir hata oluştu.',
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<TagDialog
|
||||||
|
open={showEditDialog}
|
||||||
|
onOpenChange={setShowEditDialog}
|
||||||
|
tag={tag}
|
||||||
|
onSuccess={onRefresh}
|
||||||
|
/>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||||
|
<span className="sr-only">Menü aç</span>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuLabel>İşlemler</DropdownMenuLabel>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => navigator.clipboard.writeText(tag.id.toString())}
|
||||||
|
>
|
||||||
|
Tag ID Kopyala
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
|
{!isDeleted && (
|
||||||
|
<DropdownMenuItem onClick={() => setShowEditDialog(true)}>
|
||||||
|
<Pencil className="mr-2 h-4 w-4" /> Düzenle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isDeleted ? (
|
||||||
|
<DropdownMenuItem onClick={handleRestore}>
|
||||||
|
<RefreshCcw className="mr-2 h-4 w-4 text-green-600" /> Geri Yükle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
) : (
|
||||||
|
<DropdownMenuItem onClick={handleDelete} className="text-red-600">
|
||||||
|
<Trash className="mr-2 h-4 w-4" /> Sil
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
94
frontend/app/admin/users/columns.tsx
Normal file
94
frontend/app/admin/users/columns.tsx
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { ColumnDef, HeaderContext, CellContext } from "@tanstack/react-table"
|
||||||
|
import { User } from "@/types/user"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Check, X } from "lucide-react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { ArrowUpDown } from "lucide-react"
|
||||||
|
|
||||||
|
// Actions cell component will be added later or inline if simple
|
||||||
|
import { DataTableRowActions } from "./user-row-actions"
|
||||||
|
|
||||||
|
export const getColumns = (onRefresh: () => void): ColumnDef<User>[] => [
|
||||||
|
{
|
||||||
|
accessorKey: "id",
|
||||||
|
header: ({ column }: HeaderContext<User, unknown>) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
ID
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "username",
|
||||||
|
header: ({ column }: HeaderContext<User, unknown>) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Kullanıcı Adı
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "email",
|
||||||
|
header: ({ column }: HeaderContext<User, unknown>) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Email
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "email_verified",
|
||||||
|
header: "Doğrulandı",
|
||||||
|
cell: ({ row }: CellContext<User, unknown>) => {
|
||||||
|
return row.getValue("email_verified") ? (
|
||||||
|
<Badge variant="secondary" className="bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300"><Check className="w-3 h-3 mr-1" /> Evet</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="outline" className="text-gray-500"><X className="w-3 h-3 mr-1" /> Hayır</Badge>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "deleted_at",
|
||||||
|
header: "Durum",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const deletedAt = row.original.deleted_at
|
||||||
|
return deletedAt ? (
|
||||||
|
<Badge variant="destructive">Silindi</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="outline" className="bg-green-50 text-green-700 border-green-200">Aktif</Badge>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "is_admin",
|
||||||
|
header: "Rol",
|
||||||
|
cell: ({ row }: CellContext<User, unknown>) => {
|
||||||
|
return row.getValue("is_admin") ? (
|
||||||
|
<Badge variant="default">Admin</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="secondary">User</Badge>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
cell: ({ row }: CellContext<User, unknown>) => <DataTableRowActions row={row} onRefresh={onRefresh} />,
|
||||||
|
},
|
||||||
|
]
|
||||||
100
frontend/app/admin/users/data-table.tsx
Normal file
100
frontend/app/admin/users/data-table.tsx
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
SortingState,
|
||||||
|
getSortedRowModel,
|
||||||
|
HeaderGroup,
|
||||||
|
Header,
|
||||||
|
Row,
|
||||||
|
Cell
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[]
|
||||||
|
data: TData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/incompatible-library
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
// Pagination is handled server-side in the main page, so we don't strictly need client-side pagination here
|
||||||
|
// unless we mix both. For now, let's keep it simple and just render rows.
|
||||||
|
// If we pass 20 items, it renders 20 items.
|
||||||
|
// getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
},
|
||||||
|
manualPagination: true, // Tell table we handle pagination manually
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup: HeaderGroup<TData>) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header: Header<TData, unknown>) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table.getRowModel().rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row: Row<TData>) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell: Cell<TData, unknown>) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||||
|
Sonuç bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
151
frontend/app/admin/users/page.tsx
Normal file
151
frontend/app/admin/users/page.tsx
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { useEffect, useState, Suspense } from "react"
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
|
import { getColumns } from "./columns"
|
||||||
|
import { DataTable } from "./data-table"
|
||||||
|
import { User } from "@/types/user"
|
||||||
|
import { userService } from "@/services/userService"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||||
|
import { Loader2 } from "lucide-react"
|
||||||
|
|
||||||
|
function UsersPageContent() {
|
||||||
|
const { data: session, status } = useSession()
|
||||||
|
const router = useRouter()
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
|
const [data, setData] = useState<User[]>([])
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
const page = Number(searchParams.get("page")) || 1
|
||||||
|
const perPage = Number(searchParams.get("per_page")) || 20
|
||||||
|
const soft = searchParams.get("soft") || "" // "", "only", "with"
|
||||||
|
|
||||||
|
const fetchData = React.useCallback(async () => {
|
||||||
|
if (!session?.user?.accessToken) {
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setLoading(true)
|
||||||
|
setError(null)
|
||||||
|
try {
|
||||||
|
const response = await userService.getUsers(session.user.accessToken, page, perPage, soft)
|
||||||
|
setData(response.items || [])
|
||||||
|
setTotal(response.total)
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch users:", error)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
setError((error as any).message || "Kullanıcılar getirilirken bir hata oluştu")
|
||||||
|
setData([])
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [session, page, perPage, soft])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (status === "loading") return
|
||||||
|
|
||||||
|
if (status === "unauthenticated" || !session?.user?.accessToken) {
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchData()
|
||||||
|
}, [fetchData, status, session])
|
||||||
|
|
||||||
|
const columns = React.useMemo(() => getColumns(fetchData), [fetchData])
|
||||||
|
|
||||||
|
const handleFilterChange = (value: string) => {
|
||||||
|
const params = new URLSearchParams(searchParams.toString())
|
||||||
|
if (value && value !== "active") {
|
||||||
|
params.set("soft", value)
|
||||||
|
} else {
|
||||||
|
params.delete("soft")
|
||||||
|
}
|
||||||
|
params.set("page", "1")
|
||||||
|
router.push(`/admin/users?${params.toString()}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePageChange = (newPage: number) => {
|
||||||
|
const params = new URLSearchParams(searchParams.toString())
|
||||||
|
params.set("page", newPage.toString())
|
||||||
|
router.push(`/admin/users?${params.toString()}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(total / perPage)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="container mx-auto py-10">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Kullanıcı Yönetimi</h1>
|
||||||
|
<div className="flex gap-4">
|
||||||
|
<Select
|
||||||
|
value={soft || "active"}
|
||||||
|
onValueChange={handleFilterChange}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Durum Seç" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="active">Aktif Kullanıcılar</SelectItem>
|
||||||
|
<SelectItem value="only">Silinmişler (Çöp Kutusu)</SelectItem>
|
||||||
|
<SelectItem value="with">Tümü (Aktif + Silinmiş)</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="bg-destructive/15 text-destructive p-4 rounded-md mb-6">
|
||||||
|
Hata: {error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loading && data.length === 0 ? (
|
||||||
|
<div className="flex justify-center items-center h-64">
|
||||||
|
<Loader2 className="h-8 w-8 animate-spin" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<DataTable columns={columns} data={data} />
|
||||||
|
{/* Pagination Controls */}
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handlePageChange(page - 1)}
|
||||||
|
disabled={page <= 1}
|
||||||
|
>
|
||||||
|
Önceki
|
||||||
|
</Button>
|
||||||
|
<div className="text-sm">
|
||||||
|
Sayfa {page} / {totalPages || 1}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handlePageChange(page + 1)}
|
||||||
|
disabled={page >= totalPages}
|
||||||
|
>
|
||||||
|
Sonraki
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function UsersPage() {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<div className="flex justify-center p-10"><Loader2 className="h-8 w-8 animate-spin" /></div>}>
|
||||||
|
<UsersPageContent />
|
||||||
|
</Suspense>
|
||||||
|
)
|
||||||
|
}
|
||||||
123
frontend/app/admin/users/user-dialog.tsx
Normal file
123
frontend/app/admin/users/user-dialog.tsx
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { User, UserPayload } from "@/types/user"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { userService } from "@/services/userService"
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
|
||||||
|
interface UserDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
user: User
|
||||||
|
onSuccess?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UserDialog({ open, onOpenChange, user, onSuccess }: UserDialogProps) {
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const router = useRouter()
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [formData, setFormData] = useState<UserPayload>({
|
||||||
|
username: user.username,
|
||||||
|
email: user.email,
|
||||||
|
is_admin: user.is_admin,
|
||||||
|
password: "",
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
if (!session?.user?.accessToken) return
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
// Create a payload copy to manipulate
|
||||||
|
const payload = { ...formData }
|
||||||
|
// Remove password if it's empty so we don't overwrite with empty string
|
||||||
|
if (!payload.password || payload.password.trim() === "") {
|
||||||
|
delete payload.password
|
||||||
|
}
|
||||||
|
|
||||||
|
await userService.updateUser(session.user.accessToken, user.id, payload)
|
||||||
|
toast.success("Kullanıcı güncellendi")
|
||||||
|
onOpenChange(false)
|
||||||
|
if (onSuccess) onSuccess() // Trigger parent refresh
|
||||||
|
router.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Kullanıcı güncellenirken bir hata oluştu")
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Kullanıcı Düzenle</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Kullanıcı bilgilerini buradan güncelleyebilirsiniz. Şifre alanını boş bırakırsanız değişmez.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="grid gap-4 py-4">
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="username" className="text-right">
|
||||||
|
Kullanıcı Adı
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="username"
|
||||||
|
value={formData.username}
|
||||||
|
onChange={(e) => setFormData({ ...formData, username: e.target.value })}
|
||||||
|
className="col-span-3"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="email" className="text-right">
|
||||||
|
Email
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
value={formData.email}
|
||||||
|
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
||||||
|
className="col-span-3"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="password" className="text-right">
|
||||||
|
Yeni Şifre
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
placeholder="Değişmeyecekse boş bırakın"
|
||||||
|
value={formData.password || ""}
|
||||||
|
onChange={(e) => setFormData({ ...formData, password: e.target.value })}
|
||||||
|
className="col-span-3"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/* Admin role toggle could be added here if needed */}
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
132
frontend/app/admin/users/user-row-actions.tsx
Normal file
132
frontend/app/admin/users/user-row-actions.tsx
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
import { Row } from "@tanstack/react-table"
|
||||||
|
import { MoreHorizontal, Pen, Trash, RotateCcw } from "lucide-react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { User } from "@/types/user"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { UserDialog } from "./user-dialog"
|
||||||
|
import { userService } from "@/services/userService"
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import Swal from 'sweetalert2'
|
||||||
|
import withReactContent from 'sweetalert2-react-content'
|
||||||
|
|
||||||
|
const MySwal = withReactContent(Swal)
|
||||||
|
|
||||||
|
interface DataTableRowActionsProps<TData> {
|
||||||
|
row: Row<TData>
|
||||||
|
onRefresh: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTableRowActions<TData extends User>({
|
||||||
|
row,
|
||||||
|
onRefresh,
|
||||||
|
}: DataTableRowActionsProps<TData>) {
|
||||||
|
const user = row.original as User
|
||||||
|
const [showEditDialog, setShowEditDialog] = useState(false)
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
if (!session?.user?.accessToken) return
|
||||||
|
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: 'Emin misiniz?',
|
||||||
|
text: "Bu kullanıcıyı silmek istediğinize emin misiniz? Bu işlem geri alınabilir (Soft Delete).",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#d33',
|
||||||
|
cancelButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Evet, Sil!',
|
||||||
|
cancelButtonText: 'İptal'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!result.isConfirmed) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await userService.deleteUser(session.user.accessToken, user.id)
|
||||||
|
MySwal.fire(
|
||||||
|
'Silindi!',
|
||||||
|
'Kullanıcı başarıyla silindi.',
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
onRefresh()
|
||||||
|
router.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Kullanıcı silinirken bir hata oluştu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRestore = async () => {
|
||||||
|
if (!session?.user?.accessToken) return
|
||||||
|
|
||||||
|
const result = await MySwal.fire({
|
||||||
|
title: 'Geri Yükle?',
|
||||||
|
text: "Bu kullanıcıyı geri yüklemek istediğinize emin misiniz?",
|
||||||
|
icon: 'question',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Evet, Geri Yükle!',
|
||||||
|
cancelButtonText: 'İptal'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!result.isConfirmed) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await userService.restoreUser(session.user.accessToken, user.id)
|
||||||
|
MySwal.fire(
|
||||||
|
'Geri Yüklendi!',
|
||||||
|
'Kullanıcı başarıyla geri yüklendi.',
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
onRefresh()
|
||||||
|
router.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Kullanıcı geri yüklenirken bir hata oluştu")
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<UserDialog
|
||||||
|
open={showEditDialog}
|
||||||
|
onOpenChange={setShowEditDialog}
|
||||||
|
user={user}
|
||||||
|
onSuccess={onRefresh} // Trigger refresh on success
|
||||||
|
/>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||||
|
<span className="sr-only">Menü aç</span>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem onClick={() => setShowEditDialog(true)}>
|
||||||
|
<Pen className="mr-2 h-3.5 w-3.5 text-muted-foreground/70" />
|
||||||
|
Düzenle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuItem onClick={handleDelete} className="text-red-600">
|
||||||
|
<Trash className="mr-2 h-3.5 w-3.5" />
|
||||||
|
Sil
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={handleRestore}>
|
||||||
|
<RotateCcw className="mr-2 h-3.5 w-3.5" />
|
||||||
|
Geri Yükle
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
10
frontend/app/api/admin/heroes/[id]/route.ts
Normal file
10
frontend/app/api/admin/heroes/[id]/route.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { NextRequest } from "next/server"
|
||||||
|
import { handleImageProxyRequest } from "@/lib/api-proxy"
|
||||||
|
|
||||||
|
export async function PUT(
|
||||||
|
req: NextRequest,
|
||||||
|
context: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const { id } = await context.params
|
||||||
|
return handleImageProxyRequest(req, `/admin/heroes/${id}`)
|
||||||
|
}
|
||||||
6
frontend/app/api/admin/heroes/route.ts
Normal file
6
frontend/app/api/admin/heroes/route.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { NextRequest } from "next/server"
|
||||||
|
import { handleImageProxyRequest } from "@/lib/api-proxy"
|
||||||
|
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
return handleImageProxyRequest(req, "/admin/heroes")
|
||||||
|
}
|
||||||
11
frontend/app/api/admin/posts/[id]/route.ts
Normal file
11
frontend/app/api/admin/posts/[id]/route.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { NextRequest } from "next/server";
|
||||||
|
import { handleImageProxyRequest } from "@/lib/api-proxy";
|
||||||
|
|
||||||
|
export async function PUT(
|
||||||
|
req: NextRequest,
|
||||||
|
context: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const { id } = await context.params;
|
||||||
|
console.log("API Route PUT called with id:", id);
|
||||||
|
return handleImageProxyRequest(req, `/admin/posts/${id}`);
|
||||||
|
}
|
||||||
6
frontend/app/api/admin/posts/route.ts
Normal file
6
frontend/app/api/admin/posts/route.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { NextRequest } from "next/server";
|
||||||
|
import { handleImageProxyRequest } from "@/lib/api-proxy";
|
||||||
|
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
return handleImageProxyRequest(req, "/admin/posts");
|
||||||
|
}
|
||||||
10
frontend/app/api/admin/settings/[id]/route.ts
Normal file
10
frontend/app/api/admin/settings/[id]/route.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { NextRequest } from "next/server"
|
||||||
|
import { handleImageProxyRequest } from "@/lib/api-proxy"
|
||||||
|
|
||||||
|
export async function PUT(
|
||||||
|
req: NextRequest,
|
||||||
|
context: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const { id } = await context.params
|
||||||
|
return handleImageProxyRequest(req, `/admin/settings/${id}`)
|
||||||
|
}
|
||||||
6
frontend/app/api/admin/settings/route.ts
Normal file
6
frontend/app/api/admin/settings/route.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { NextRequest } from "next/server"
|
||||||
|
import { handleImageProxyRequest } from "@/lib/api-proxy"
|
||||||
|
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
return handleImageProxyRequest(req, "/admin/settings")
|
||||||
|
}
|
||||||
187
frontend/app/api/auth/[...nextauth]/route.ts
Normal file
187
frontend/app/api/auth/[...nextauth]/route.ts
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
import NextAuth, { NextAuthOptions } from "next-auth";
|
||||||
|
import CredentialsProvider from "next-auth/providers/credentials";
|
||||||
|
import GitHubProvider from "next-auth/providers/github";
|
||||||
|
import GoogleProvider from "next-auth/providers/google";
|
||||||
|
import { JWT } from "next-auth/jwt";
|
||||||
|
|
||||||
|
// Helper to get API URL consistently
|
||||||
|
const API_URL = process.env.NEXT_PUBLIC_API_URL || process.env.BASE_API_URL || "http://localhost:8080/api";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh token ile yeni access token al
|
||||||
|
*/
|
||||||
|
async function refreshAccessToken(token: JWT) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_URL}/api/v1/auth/refresh`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
refresh_token: token.refreshToken,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to refresh token");
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshedTokens = await response.json();
|
||||||
|
|
||||||
|
return {
|
||||||
|
...token,
|
||||||
|
accessToken: refreshedTokens.access_token,
|
||||||
|
refreshToken: refreshedTokens.refresh_token ?? token.refreshToken,
|
||||||
|
accessTokenExpires: Date.now() + 15 * 60 * 1000, // 15 dakika (Time should ideally come from backend)
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error refreshing access token:", error);
|
||||||
|
return {
|
||||||
|
...token,
|
||||||
|
error: "RefreshAccessTokenError",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const authOptions: NextAuthOptions = {
|
||||||
|
providers: [
|
||||||
|
CredentialsProvider({
|
||||||
|
name: "Credentials",
|
||||||
|
credentials: {
|
||||||
|
email: { label: "Email", type: "email" },
|
||||||
|
password: { label: "Password", type: "password" },
|
||||||
|
// Optional: used if redirecting from a separate auth flow
|
||||||
|
accessToken: { label: "Access Token", type: "text" },
|
||||||
|
refreshToken: { label: "Refresh Token", type: "text" },
|
||||||
|
},
|
||||||
|
async authorize(credentials) {
|
||||||
|
// 1. External Token Flow (if tokens are passed directly, e.g. from OAuth on backend)
|
||||||
|
if (credentials?.accessToken && credentials?.refreshToken) {
|
||||||
|
try {
|
||||||
|
// Validate token and get user info
|
||||||
|
const meResponse = await fetch(`${API_URL}/api/v1/auth/me`, {
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${credentials.accessToken}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!meResponse.ok) return null;
|
||||||
|
|
||||||
|
const userData = await meResponse.json();
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: userData.id?.toString(),
|
||||||
|
email: userData.email,
|
||||||
|
name: userData.username,
|
||||||
|
username: userData.username, // Added to satisfy User interface
|
||||||
|
is_admin: userData.is_admin, // Capture is_admin
|
||||||
|
accessToken: credentials.accessToken,
|
||||||
|
refreshToken: credentials.refreshToken,
|
||||||
|
accessTokenExpires: Date.now() + 15 * 60 * 1000,
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Standard Email/Password Flow
|
||||||
|
if (!credentials?.email || !credentials?.password) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_URL}/api/v1/auth/login`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: credentials.email,
|
||||||
|
password: credentials.password,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
// Structure matches user's provided JSON example
|
||||||
|
return {
|
||||||
|
id: data.user.id.toString(),
|
||||||
|
email: data.user.email,
|
||||||
|
name: data.user.username,
|
||||||
|
username: data.user.username, // Added to satisfy User interface
|
||||||
|
is_admin: data.user.is_admin, // Capture is_admin
|
||||||
|
accessToken: data.access_token,
|
||||||
|
refreshToken: data.refresh_token,
|
||||||
|
accessTokenExpires: Date.now() + 15 * 60 * 1000,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Login error:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
// Keep existing providers if they are configured
|
||||||
|
GitHubProvider({
|
||||||
|
clientId: process.env.GITHUB_CLIENT_ID || "",
|
||||||
|
clientSecret: process.env.GITHUB_CLIENT_SECRET || "",
|
||||||
|
}),
|
||||||
|
GoogleProvider({
|
||||||
|
clientId: process.env.GOOGLE_CLIENT_ID || "",
|
||||||
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
pages: {
|
||||||
|
signIn: "/auth/login",
|
||||||
|
signOut: "/auth/login",
|
||||||
|
error: "/auth/login",
|
||||||
|
},
|
||||||
|
callbacks: {
|
||||||
|
async jwt({ token, user }) {
|
||||||
|
// Initial sign in
|
||||||
|
if (user) {
|
||||||
|
token.id = user.id;
|
||||||
|
token.email = user.email;
|
||||||
|
token.name = user.name || undefined;
|
||||||
|
token.username = user.username;
|
||||||
|
token.accessToken = user.accessToken;
|
||||||
|
token.refreshToken = user.refreshToken;
|
||||||
|
token.roles = user.roles;
|
||||||
|
token.is_admin = user.is_admin;
|
||||||
|
token.accessTokenExpires = user.accessTokenExpires;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return previous token if the access token has not expired yet
|
||||||
|
if (Date.now() < (token.accessTokenExpires as number)) {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Access token has expired, try to update it
|
||||||
|
return refreshAccessToken(token);
|
||||||
|
},
|
||||||
|
async session({ session, token }) {
|
||||||
|
if (token) {
|
||||||
|
session.user.id = token.id as string;
|
||||||
|
session.user.email = token.email as string;
|
||||||
|
session.user.name = token.name as string;
|
||||||
|
session.user.username = token.username as string;
|
||||||
|
session.user.is_admin = token.is_admin as boolean; // Expose is_admin to session
|
||||||
|
session.accessToken = token.accessToken as string;
|
||||||
|
session.user.accessToken = token.accessToken as string;
|
||||||
|
session.error = token.error as string;
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
session: {
|
||||||
|
strategy: "jwt",
|
||||||
|
},
|
||||||
|
secret: process.env.NEXTAUTH_SECRET, // Ensure this matches .env
|
||||||
|
};
|
||||||
|
|
||||||
|
const handler = NextAuth(authOptions);
|
||||||
|
|
||||||
|
export { handler as GET, handler as POST };
|
||||||
156
frontend/app/auth/login/page.tsx
Normal file
156
frontend/app/auth/login/page.tsx
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
import { useForm } from 'react-hook-form'
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
|
import { loginSchema, LoginInput } from '@/lib/auth-schema'
|
||||||
|
import { Input } from '@/components/ui/input'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
|
import { Label } from '@/components/ui/label'
|
||||||
|
import { Turnstile } from 'nextjs-turnstile'
|
||||||
|
import { signIn } from 'next-auth/react'
|
||||||
|
import Swal from 'sweetalert2'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
|
const LoginPage = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [turnstileToken, setTurnstileToken] = useState<string | null>(null)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm<LoginInput>({
|
||||||
|
resolver: zodResolver(loginSchema),
|
||||||
|
})
|
||||||
|
|
||||||
|
const siteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITEKEY
|
||||||
|
|
||||||
|
const onSubmit = async (data: LoginInput) => {
|
||||||
|
if (siteKey && !turnstileToken) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'warning',
|
||||||
|
title: 'Güvenlik Doğrulaması',
|
||||||
|
text: 'Lütfen robot olmadığınızı doğrulayın.',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await signIn('credentials', {
|
||||||
|
redirect: false,
|
||||||
|
email: data.email,
|
||||||
|
password: data.password,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result?.error) {
|
||||||
|
throw new Error(result.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result?.ok) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'success',
|
||||||
|
title: 'Giriş Başarılı',
|
||||||
|
text: 'Yönlendiriliyorsunuz...',
|
||||||
|
timer: 1500,
|
||||||
|
showConfirmButton: false,
|
||||||
|
}).then(() => {
|
||||||
|
const callbackUrl = new URLSearchParams(window.location.search).get("callbackUrl") || "/"
|
||||||
|
router.push(callbackUrl)
|
||||||
|
router.refresh()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Giriş Başarısız',
|
||||||
|
text: 'E-posta veya şifre hatalı olabilir.',
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center bg-gray-100 p-4 dark:bg-gray-900">
|
||||||
|
<Card className="w-full max-w-md shadow-xl">
|
||||||
|
<CardHeader className="space-y-1">
|
||||||
|
<CardTitle className="text-2xl font-bold text-center">Giriş Yap</CardTitle>
|
||||||
|
<CardDescription className="text-center">
|
||||||
|
Hesabınıza erişmek için bilgilerinizi girin
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="email">E-posta</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
placeholder="ornek@domain.com"
|
||||||
|
{...register('email')}
|
||||||
|
className={errors.email ? 'border-red-500' : ''}
|
||||||
|
/>
|
||||||
|
{errors.email && (
|
||||||
|
<p className="text-sm text-red-500">{errors.email.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Label htmlFor="password">Şifre</Label>
|
||||||
|
<Link
|
||||||
|
href="/auth/forgot-password"
|
||||||
|
className="text-sm text-blue-600 hover:underline"
|
||||||
|
>
|
||||||
|
Şifremi Unuttum?
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
placeholder="********"
|
||||||
|
{...register('password')}
|
||||||
|
className={errors.password ? 'border-red-500' : ''}
|
||||||
|
/>
|
||||||
|
{errors.password && (
|
||||||
|
<p className="text-sm text-red-500">{errors.password.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{siteKey && (
|
||||||
|
<div className="flex justify-center my-4">
|
||||||
|
<Turnstile
|
||||||
|
siteKey={siteKey}
|
||||||
|
onSuccess={(token) => setTurnstileToken(token)}
|
||||||
|
onError={() => setTurnstileToken(null)}
|
||||||
|
onExpire={() => setTurnstileToken(null)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button type="submit" className="w-full" disabled={isLoading}>
|
||||||
|
{isLoading ? 'Giriş Yapılıyor...' : 'Giriş Yap'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter className="justify-center">
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
Hesabınız yok mu?{' '}
|
||||||
|
<Link href="/auth/register" className="text-blue-600 hover:underline">
|
||||||
|
Kayıt Ol
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoginPage
|
||||||
176
frontend/app/auth/register/page.tsx
Normal file
176
frontend/app/auth/register/page.tsx
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
import { useForm } from 'react-hook-form'
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
|
import { registerSchema, RegisterInput } from '@/lib/auth-schema'
|
||||||
|
import { Input } from '@/components/ui/input'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
|
import { Label } from '@/components/ui/label'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import Swal from 'sweetalert2'
|
||||||
|
import { Turnstile } from 'nextjs-turnstile'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
const RegisterPage = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const [turnstileToken, setTurnstileToken] = useState<string | null>(null)
|
||||||
|
const router = useRouter()
|
||||||
|
const siteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITEKEY
|
||||||
|
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm<RegisterInput>({
|
||||||
|
resolver: zodResolver(registerSchema),
|
||||||
|
})
|
||||||
|
|
||||||
|
const onSubmit = async (data: RegisterInput) => {
|
||||||
|
if (siteKey && !turnstileToken) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'warning',
|
||||||
|
title: 'Güvenlik Doğrulaması',
|
||||||
|
text: 'Lütfen robot olmadığınızı doğrulayın.',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true)
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/register`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
username: data.username,
|
||||||
|
email: data.email,
|
||||||
|
password: data.password
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await response.json()
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(result.error || result.message || 'Kayıt işlemi başarısız oldu.')
|
||||||
|
}
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Başarılı!',
|
||||||
|
text: 'Kayıt işlemi başarıyla tamamlandı. Lütfen e-posta adresinizi doğrulayın.',
|
||||||
|
icon: 'success',
|
||||||
|
confirmButtonText: 'Giriş Yap',
|
||||||
|
}).then(() => {
|
||||||
|
router.push('/auth/login')
|
||||||
|
})
|
||||||
|
|
||||||
|
} catch (error: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Hata!',
|
||||||
|
text: error.message || 'Bir sorun oluştu.',
|
||||||
|
icon: 'error',
|
||||||
|
confirmButtonText: 'Tamam',
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center bg-gray-100 p-4 dark:bg-gray-900">
|
||||||
|
<Card className="w-full max-w-md shadow-xl">
|
||||||
|
<CardHeader className="space-y-1">
|
||||||
|
<CardTitle className="text-2xl font-bold text-center">Kayıt Ol</CardTitle>
|
||||||
|
<CardDescription className="text-center">
|
||||||
|
Yeni bir hesap oluşturmak için bilgilerinizi girin
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="username">Kullanıcı Adı</Label>
|
||||||
|
<Input
|
||||||
|
id="username"
|
||||||
|
placeholder="johndoe"
|
||||||
|
{...register('username')}
|
||||||
|
className={errors.username ? 'border-red-500' : ''}
|
||||||
|
/>
|
||||||
|
{errors.username && (
|
||||||
|
<p className="text-sm text-red-500">{errors.username.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="email">E-posta</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
placeholder="ornek@domain.com"
|
||||||
|
{...register('email')}
|
||||||
|
className={errors.email ? 'border-red-500' : ''}
|
||||||
|
/>
|
||||||
|
{errors.email && (
|
||||||
|
<p className="text-sm text-red-500">{errors.email.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="password">Şifre</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
placeholder="********"
|
||||||
|
{...register('password')}
|
||||||
|
className={errors.password ? 'border-red-500' : ''}
|
||||||
|
/>
|
||||||
|
{errors.password && (
|
||||||
|
<p className="text-sm text-red-500">{errors.password.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="confirmPassword">Şifre Tekrar</Label>
|
||||||
|
<Input
|
||||||
|
id="confirmPassword"
|
||||||
|
type="password"
|
||||||
|
placeholder="********"
|
||||||
|
{...register('confirmPassword')}
|
||||||
|
className={errors.confirmPassword ? 'border-red-500' : ''}
|
||||||
|
/>
|
||||||
|
{errors.confirmPassword && (
|
||||||
|
<p className="text-sm text-red-500">{errors.confirmPassword.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{siteKey && (
|
||||||
|
<div className="flex justify-center my-4">
|
||||||
|
<Turnstile
|
||||||
|
siteKey={siteKey}
|
||||||
|
onSuccess={(token) => setTurnstileToken(token)}
|
||||||
|
onError={() => setTurnstileToken(null)}
|
||||||
|
onExpire={() => setTurnstileToken(null)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button type="submit" className="w-full" disabled={isLoading}>
|
||||||
|
{isLoading ? 'Kaydediliyor...' : 'Kayıt Ol'}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter className="justify-center">
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
Zaten hesabınız var mı?{' '}
|
||||||
|
<Link href="/auth/login" className="text-blue-600 hover:underline">
|
||||||
|
Giriş Yap
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RegisterPage
|
||||||
126
frontend/app/auth/verify-email/page.tsx
Normal file
126
frontend/app/auth/verify-email/page.tsx
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import React, { useEffect, useState, Suspense } from 'react'
|
||||||
|
import { useSearchParams } from 'next/navigation'
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from '@/components/ui/card'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Loader2, CheckCircle2, XCircle, AlertCircle } from 'lucide-react'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
|
const VerifyEmailContent = () => {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const token = searchParams.get('token')
|
||||||
|
const [status, setStatus] = useState<'loading' | 'success' | 'error' | 'invalid'>(token ? 'loading' : 'invalid')
|
||||||
|
const [message, setMessage] = useState('')
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!token) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const verifyEmail = async () => {
|
||||||
|
try {
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080'
|
||||||
|
const response = await fetch(`${apiUrl}/api/v1/auth/verify-email?token=${token}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Backend responses might modify status
|
||||||
|
const data = await response.json().catch(() => ({}))
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
setStatus('success')
|
||||||
|
setMessage(data.message || 'E-posta adresiniz başarıyla doğrulandı.')
|
||||||
|
} else {
|
||||||
|
setStatus('error')
|
||||||
|
setMessage(data.error || data.message || 'Doğrulama işlemi başarısız oldu. Link süresi dolmuş veya geçersiz olabilir.')
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
setStatus('error')
|
||||||
|
setMessage('Sunucu ile iletişim kurulurken bir hata oluştu.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verifyEmail()
|
||||||
|
}, [token])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="w-full max-w-md shadow-xl">
|
||||||
|
<CardHeader className="space-y-1">
|
||||||
|
<CardTitle className="text-2xl font-bold text-center">E-posta Doğrulama</CardTitle>
|
||||||
|
<CardDescription className="text-center">
|
||||||
|
Hesap aktivasyon durumu
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="flex flex-col items-center justify-center py-6 space-y-4">
|
||||||
|
{status === 'loading' && (
|
||||||
|
<>
|
||||||
|
<Loader2 className="h-16 w-16 animate-spin text-blue-500" />
|
||||||
|
<p className="text-gray-500">Doğrulanıyor, lütfen bekleyin...</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{status === 'success' && (
|
||||||
|
<>
|
||||||
|
<CheckCircle2 className="h-16 w-16 text-green-500" />
|
||||||
|
<div className="text-center space-y-2">
|
||||||
|
<h3 className="text-xl font-semibold text-green-600">Başarılı!</h3>
|
||||||
|
<p className="text-gray-600">{message}</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{status === 'error' && (
|
||||||
|
<>
|
||||||
|
<XCircle className="h-16 w-16 text-red-500" />
|
||||||
|
<div className="text-center space-y-2">
|
||||||
|
<h3 className="text-xl font-semibold text-red-600">Hata!</h3>
|
||||||
|
<p className="text-gray-600">{message}</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{status === 'invalid' && (
|
||||||
|
<>
|
||||||
|
<AlertCircle className="h-16 w-16 text-amber-500" />
|
||||||
|
<div className="text-center space-y-2">
|
||||||
|
<h3 className="text-xl font-semibold text-amber-600">Geçersiz Bağlantı</h3>
|
||||||
|
<p className="text-gray-600">Doğrulama bağlantısı geçersiz veya eksik.</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter className="justify-center">
|
||||||
|
{status === 'loading' ? (
|
||||||
|
<Button disabled variant="outline" className="w-full">İşlem Sürüyor</Button>
|
||||||
|
) : (
|
||||||
|
<Link href="/auth/login" className="w-full">
|
||||||
|
<Button className="w-full">
|
||||||
|
{status === 'success' ? 'Giriş Yap' : 'Giriş Sayfasına Dön'}
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const VerifyEmailPage = () => {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center bg-gray-100 p-4 dark:bg-gray-900">
|
||||||
|
<Suspense fallback={
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin" />
|
||||||
|
<span>Yükleniyor...</span>
|
||||||
|
</div>
|
||||||
|
}>
|
||||||
|
<VerifyEmailContent />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default VerifyEmailPage
|
||||||
BIN
frontend/app/favicon.ico
Normal file
BIN
frontend/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
126
frontend/app/globals.css
Normal file
126
frontend/app/globals.css
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
@import "tw-animate-css";
|
||||||
|
@import "shadcn/tailwind.css";
|
||||||
|
|
||||||
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
--color-background: var(--background);
|
||||||
|
--color-foreground: var(--foreground);
|
||||||
|
--font-sans: var(--font-geist-sans);
|
||||||
|
--font-mono: var(--font-geist-mono);
|
||||||
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
|
--color-sidebar-accent: var(--sidebar-accent);
|
||||||
|
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||||
|
--color-sidebar-primary: var(--sidebar-primary);
|
||||||
|
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||||
|
--color-sidebar: var(--sidebar);
|
||||||
|
--color-chart-5: var(--chart-5);
|
||||||
|
--color-chart-4: var(--chart-4);
|
||||||
|
--color-chart-3: var(--chart-3);
|
||||||
|
--color-chart-2: var(--chart-2);
|
||||||
|
--color-chart-1: var(--chart-1);
|
||||||
|
--color-ring: var(--ring);
|
||||||
|
--color-input: var(--input);
|
||||||
|
--color-border: var(--border);
|
||||||
|
--color-destructive: var(--destructive);
|
||||||
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
|
--color-accent: var(--accent);
|
||||||
|
--color-muted-foreground: var(--muted-foreground);
|
||||||
|
--color-muted: var(--muted);
|
||||||
|
--color-secondary-foreground: var(--secondary-foreground);
|
||||||
|
--color-secondary: var(--secondary);
|
||||||
|
--color-primary-foreground: var(--primary-foreground);
|
||||||
|
--color-primary: var(--primary);
|
||||||
|
--color-popover-foreground: var(--popover-foreground);
|
||||||
|
--color-popover: var(--popover);
|
||||||
|
--color-card-foreground: var(--card-foreground);
|
||||||
|
--color-card: var(--card);
|
||||||
|
--radius-sm: calc(var(--radius) - 4px);
|
||||||
|
--radius-md: calc(var(--radius) - 2px);
|
||||||
|
--radius-lg: var(--radius);
|
||||||
|
--radius-xl: calc(var(--radius) + 4px);
|
||||||
|
--radius-2xl: calc(var(--radius) + 8px);
|
||||||
|
--radius-3xl: calc(var(--radius) + 12px);
|
||||||
|
--radius-4xl: calc(var(--radius) + 16px);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--radius: 0.625rem;
|
||||||
|
--background: oklch(1 0 0);
|
||||||
|
--foreground: oklch(0.145 0 0);
|
||||||
|
--card: oklch(1 0 0);
|
||||||
|
--card-foreground: oklch(0.145 0 0);
|
||||||
|
--popover: oklch(1 0 0);
|
||||||
|
--popover-foreground: oklch(0.145 0 0);
|
||||||
|
--primary: oklch(0.205 0 0);
|
||||||
|
--primary-foreground: oklch(0.985 0 0);
|
||||||
|
--secondary: oklch(0.97 0 0);
|
||||||
|
--secondary-foreground: oklch(0.205 0 0);
|
||||||
|
--muted: oklch(0.97 0 0);
|
||||||
|
--muted-foreground: oklch(0.556 0 0);
|
||||||
|
--accent: oklch(0.97 0 0);
|
||||||
|
--accent-foreground: oklch(0.205 0 0);
|
||||||
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
|
--border: oklch(0.922 0 0);
|
||||||
|
--input: oklch(0.922 0 0);
|
||||||
|
--ring: oklch(0.708 0 0);
|
||||||
|
--chart-1: oklch(0.646 0.222 41.116);
|
||||||
|
--chart-2: oklch(0.6 0.118 184.704);
|
||||||
|
--chart-3: oklch(0.398 0.07 227.392);
|
||||||
|
--chart-4: oklch(0.828 0.189 84.429);
|
||||||
|
--chart-5: oklch(0.769 0.188 70.08);
|
||||||
|
--sidebar: oklch(0.985 0 0);
|
||||||
|
--sidebar-foreground: oklch(0.145 0 0);
|
||||||
|
--sidebar-primary: oklch(0.205 0 0);
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-accent: oklch(0.97 0 0);
|
||||||
|
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||||
|
--sidebar-border: oklch(0.922 0 0);
|
||||||
|
--sidebar-ring: oklch(0.708 0 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
--background: oklch(0.145 0 0);
|
||||||
|
--foreground: oklch(0.985 0 0);
|
||||||
|
--card: oklch(0.205 0 0);
|
||||||
|
--card-foreground: oklch(0.985 0 0);
|
||||||
|
--popover: oklch(0.205 0 0);
|
||||||
|
--popover-foreground: oklch(0.985 0 0);
|
||||||
|
--primary: oklch(0.922 0 0);
|
||||||
|
--primary-foreground: oklch(0.205 0 0);
|
||||||
|
--secondary: oklch(0.269 0 0);
|
||||||
|
--secondary-foreground: oklch(0.985 0 0);
|
||||||
|
--muted: oklch(0.269 0 0);
|
||||||
|
--muted-foreground: oklch(0.708 0 0);
|
||||||
|
--accent: oklch(0.269 0 0);
|
||||||
|
--accent-foreground: oklch(0.985 0 0);
|
||||||
|
--destructive: oklch(0.704 0.191 22.216);
|
||||||
|
--border: oklch(1 0 0 / 10%);
|
||||||
|
--input: oklch(1 0 0 / 15%);
|
||||||
|
--ring: oklch(0.556 0 0);
|
||||||
|
--chart-1: oklch(0.488 0.243 264.376);
|
||||||
|
--chart-2: oklch(0.696 0.17 162.48);
|
||||||
|
--chart-3: oklch(0.769 0.188 70.08);
|
||||||
|
--chart-4: oklch(0.627 0.265 303.9);
|
||||||
|
--chart-5: oklch(0.645 0.246 16.439);
|
||||||
|
--sidebar: oklch(0.205 0 0);
|
||||||
|
--sidebar-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-accent: oklch(0.269 0 0);
|
||||||
|
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-border: oklch(1 0 0 / 10%);
|
||||||
|
--sidebar-ring: oklch(0.556 0 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
@apply border-border outline-ring/50;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
@apply bg-background text-foreground;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
frontend/app/layout.tsx
Normal file
45
frontend/app/layout.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import { Geist, Geist_Mono } from "next/font/google";
|
||||||
|
import { NextAuthProvider } from "@/components/providers/NextAuthProvider";
|
||||||
|
import { ThemeProvider } from "@/components/providers/ThemeProvider";
|
||||||
|
import "./globals.css";
|
||||||
|
|
||||||
|
const geistSans = Geist({
|
||||||
|
variable: "--font-geist-sans",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const geistMono = Geist_Mono({
|
||||||
|
variable: "--font-geist-mono",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Create Next App",
|
||||||
|
description: "Generated by create next app",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<html lang="en" suppressHydrationWarning>
|
||||||
|
<body
|
||||||
|
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||||
|
>
|
||||||
|
<NextAuthProvider>
|
||||||
|
<ThemeProvider
|
||||||
|
attribute="class"
|
||||||
|
defaultTheme="system"
|
||||||
|
enableSystem
|
||||||
|
disableTransitionOnChange
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</ThemeProvider>
|
||||||
|
</NextAuthProvider>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
8
frontend/app/page.tsx
Normal file
8
frontend/app/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||||
|
<Button>Click me</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
2025
frontend/belgeler/admin_blog_post.md
Normal file
2025
frontend/belgeler/admin_blog_post.md
Normal file
File diff suppressed because it is too large
Load Diff
377
frontend/belgeler/admin_hero_crud.md
Normal file
377
frontend/belgeler/admin_hero_crud.md
Normal file
@@ -0,0 +1,377 @@
|
|||||||
|
Proje `frontend` klasörü altında yapılandırılmıştır. Gerekli tüm paketler (`package.json`) önceden yüklenmiştir:
|
||||||
|
- **Framework:** Next.js 16 (App Router)
|
||||||
|
- **UI:** React 19, Tailwind CSS v4, shadcn/ui
|
||||||
|
- **İkonlar:** lucide-react
|
||||||
|
- **Validasyon:** Zod
|
||||||
|
- **Auth:** NextAuth.js
|
||||||
|
- **Bildirimler:** SweetAlert2
|
||||||
|
- **Güvenlik:** nextjs-turnstile (Cloudflare)
|
||||||
|
- **Senin ile sadece Frontend Üstünde Çalışıyorum**
|
||||||
|
- **Backend ile ilgili bir şey Yapman Gerekirse Bana Söylemen Yeterli**
|
||||||
|
|
||||||
|
##############
|
||||||
|
Yeni Hero Kaydi
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/heroes' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MDU3NjYsImlhdCI6MTc3MTM5NDk2NiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.pKMS0trKymCVgLZL-fTSUWB8QDAzfRVikHD_-I2iC-A' \
|
||||||
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
-F 'color=11111' \
|
||||||
|
-F 'title=Title' \
|
||||||
|
-F 'text1=Text1' \
|
||||||
|
-F 'text2=Text2' \
|
||||||
|
-F 'text4=Text4' \
|
||||||
|
-F 'text5=Text5' \
|
||||||
|
-F 'is_active=true' \
|
||||||
|
-F 'image=@845575.png;type=image/png'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/heroes
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
201
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 1,
|
||||||
|
"CreatedAt": "2026-02-18T06:17:46.077799Z",
|
||||||
|
"UpdatedAt": "2026-02-18T06:17:46.077799Z",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"color": "11111",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395466075911000.png",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 286
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 06:17:46 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
##################
|
||||||
|
restore hero
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/heroes/2/restore' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MDU3NjYsImlhdCI6MTc3MTM5NDk2NiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.pKMS0trKymCVgLZL-fTSUWB8QDAzfRVikHD_-I2iC-A' \
|
||||||
|
-d ''
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/heroes/2/restore
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T09:18:32.257+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T06:19:40.645922Z",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"color": "22222",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395512255077000.png",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 288
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 06:19:40 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
##################
|
||||||
|
hero silmek
|
||||||
|
curl -X 'DELETE' \
|
||||||
|
'http://localhost:8080/api/v1/admin/heroes/3' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MDU3NjYsImlhdCI6MTc3MTM5NDk2NiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.pKMS0trKymCVgLZL-fTSUWB8QDAzfRVikHD_-I2iC-A'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/heroes/3
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Undocumented
|
||||||
|
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"message": "hero deleted successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 46
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 06:20:49 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
##################
|
||||||
|
sadece soft delete olmuslar
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/heroes?soft=only' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MDU3NjYsImlhdCI6MTc3MTM5NDk2NiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.pKMS0trKymCVgLZL-fTSUWB8QDAzfRVikHD_-I2iC-A'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/heroes?soft=only
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"ID": 3,
|
||||||
|
"CreatedAt": "2026-02-18T09:20:43.16+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:20:43.16+03:00",
|
||||||
|
"DeletedAt": "2026-02-18T09:20:49.969+03:00",
|
||||||
|
"color": "22222",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395643158537000.png",
|
||||||
|
"is_active": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T09:18:32.257+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:18:32.257+03:00",
|
||||||
|
"DeletedAt": "2026-02-18T09:19:05.81+03:00",
|
||||||
|
"color": "22222",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395512255077000.png",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 2
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 659
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 06:22:05 GMT
|
||||||
|
|
||||||
|
##################
|
||||||
|
soft delete olmuslar ve silinmeyenler yani hepsi
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/heroes?soft=with' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MDU3NjYsImlhdCI6MTc3MTM5NDk2NiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.pKMS0trKymCVgLZL-fTSUWB8QDAzfRVikHD_-I2iC-A'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/heroes?soft=with
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"ID": 3,
|
||||||
|
"CreatedAt": "2026-02-18T09:20:43.16+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:20:43.16+03:00",
|
||||||
|
"DeletedAt": "2026-02-18T09:20:49.969+03:00",
|
||||||
|
"color": "22222",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395643158537000.png",
|
||||||
|
"is_active": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T09:18:32.257+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:18:32.257+03:00",
|
||||||
|
"DeletedAt": "2026-02-18T09:19:05.81+03:00",
|
||||||
|
"color": "22222",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395512255077000.png",
|
||||||
|
"is_active": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ID": 1,
|
||||||
|
"CreatedAt": "2026-02-18T09:17:46.077+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:17:46.077+03:00",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"color": "11111",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395466075911000.png",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 3
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 941
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 06:22:49 GMT
|
||||||
|
|
||||||
|
##################
|
||||||
|
tek getiröe
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/heroes/2' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MDU3NjYsImlhdCI6MTc3MTM5NDk2NiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.pKMS0trKymCVgLZL-fTSUWB8QDAzfRVikHD_-I2iC-A'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/heroes/2
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T09:18:32.257+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:18:32.257+03:00",
|
||||||
|
"DeletedAt": "2026-02-18T09:19:05.81+03:00",
|
||||||
|
"color": "22222",
|
||||||
|
"title": "Title",
|
||||||
|
"text1": "Text1",
|
||||||
|
"text2": "Text2",
|
||||||
|
"text4": "Text4",
|
||||||
|
"text5": "Text5",
|
||||||
|
"image": "/uploads/heroes/hero-1771395512255077000.png",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 316
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 06:24:07 GMT
|
||||||
|
|
||||||
|
##################
|
||||||
|
hero guncelleme
|
||||||
|
curl -X 'PUT' \
|
||||||
|
'http://localhost:8080/api/v1/admin/heroes/1' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MDU3NjYsImlhdCI6MTc3MTM5NDk2NiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.pKMS0trKymCVgLZL-fTSUWB8QDAzfRVikHD_-I2iC-A' \
|
||||||
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
-F 'color=ee' \
|
||||||
|
-F 'title=ee' \
|
||||||
|
-F 'text1=ee' \
|
||||||
|
-F 'text2=ee' \
|
||||||
|
-F 'text4=ee' \
|
||||||
|
-F 'text5=ee' \
|
||||||
|
-F 'is_active=true' \
|
||||||
|
-F 'image=@accounts.jpg;type=image/jpeg'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/heroes/1
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 1,
|
||||||
|
"CreatedAt": "2026-02-18T09:17:46.077+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T06:25:06.633353Z",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"color": "ee",
|
||||||
|
"title": "ee",
|
||||||
|
"text1": "ee",
|
||||||
|
"text2": "ee",
|
||||||
|
"text4": "ee",
|
||||||
|
"text5": "ee",
|
||||||
|
"image": "/uploads/heroes/hero-1771395906631296000.jpg",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 270
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 06:25:06 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
##################
|
||||||
|
Eklenen alanlari
|
||||||
|
"width": 0,
|
||||||
|
"height": 0,
|
||||||
|
"quality": 0,
|
||||||
|
"format": ""
|
||||||
|
|
||||||
|
|
||||||
369
frontend/belgeler/admin_kategori_crud.md
Normal file
369
frontend/belgeler/admin_kategori_crud.md
Normal file
@@ -0,0 +1,369 @@
|
|||||||
|
Proje `frontend` klasörü altında yapılandırılmıştır. Gerekli tüm paketler (`package.json`) önceden yüklenmiştir:
|
||||||
|
- **Framework:** Next.js 16 (App Router)
|
||||||
|
- **UI:** React 19, Tailwind CSS v4, shadcn/ui
|
||||||
|
- **İkonlar:** lucide-react
|
||||||
|
- **Validasyon:** Zod
|
||||||
|
- **Auth:** NextAuth.js
|
||||||
|
- **Bildirimler:** SweetAlert2
|
||||||
|
- **Güvenlik:** nextjs-turnstile (Cloudflare)
|
||||||
|
- **Senin ile sadece Frontend Üstünde Çalışıyorum**
|
||||||
|
- **Backend ile ilgili bir şey Yapman Gerekirse Bana Söylemen Yeterli**
|
||||||
|
|
||||||
|
#######################
|
||||||
|
Silnmis ve silinmemiş kategorileri hepsini getirir
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/categories?soft=with' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/categories?soft=with
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": 126,
|
||||||
|
"title": "Edebiyat",
|
||||||
|
"slug": "edebiyat-1771357850441632000",
|
||||||
|
"deleted_at": "2026-02-18T07:13:44.315+03:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 125,
|
||||||
|
"title": "Müzik",
|
||||||
|
"slug": "muzik-1771357850322048000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 124,
|
||||||
|
"title": "Sinema",
|
||||||
|
"slug": "sinema-1771357850310914000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 123,
|
||||||
|
"title": "Sanat",
|
||||||
|
"slug": "sanat-1771357850300423000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 122,
|
||||||
|
"title": "İçecekler",
|
||||||
|
"slug": "icecekler-1771357850183010000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 121,
|
||||||
|
"title": "Ana Yemekler",
|
||||||
|
"slug": "ana-yemekler-1771357850172046000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 120,
|
||||||
|
"title": "Tatlılar",
|
||||||
|
"slug": "tatlilar-1771357850161422000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 119,
|
||||||
|
"title": "Yemek",
|
||||||
|
"slug": "yemek-1771357850149748000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 118,
|
||||||
|
"title": "Dekorasyon",
|
||||||
|
"slug": "dekorasyon-1771357850137823000",
|
||||||
|
"deleted_at": "2026-02-18T07:11:49.576+03:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 117,
|
||||||
|
"title": "Gezi",
|
||||||
|
"slug": "gezi-1771357850126021000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 116,
|
||||||
|
"title": "Spor",
|
||||||
|
"slug": "spor-1771357850110558000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 115,
|
||||||
|
"title": "Sağlık",
|
||||||
|
"slug": "saglik-1771357850098589000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 114,
|
||||||
|
"title": "Yaşam",
|
||||||
|
"slug": "yasam-1771357850085843000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 113,
|
||||||
|
"title": "Mobil",
|
||||||
|
"slug": "mobil-1771357850074407000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 112,
|
||||||
|
"title": "Yapay Zeka",
|
||||||
|
"slug": "yapay-zeka-1771357850062505000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 111,
|
||||||
|
"title": "Donanım",
|
||||||
|
"slug": "donanim-1771357850051551000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 110,
|
||||||
|
"title": "Yazılım",
|
||||||
|
"slug": "yazilim-1771357850031651000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 109,
|
||||||
|
"title": "Teknoloji",
|
||||||
|
"slug": "teknoloji-1771357849936045000"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 18
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 1331
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 04:14:02 GMT
|
||||||
|
|
||||||
|
#######################
|
||||||
|
sadece silinmisleri getirir
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/categories?soft=only' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/categories?soft=only
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": 126,
|
||||||
|
"title": "Edebiyat",
|
||||||
|
"slug": "edebiyat-1771357850441632000",
|
||||||
|
"deleted_at": "2026-02-18T07:13:44.315+03:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 118,
|
||||||
|
"title": "Dekorasyon",
|
||||||
|
"slug": "dekorasyon-1771357850137823000",
|
||||||
|
"deleted_at": "2026-02-18T07:11:49.576+03:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 2
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 274
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 04:15:47 GMT
|
||||||
|
|
||||||
|
Responses
|
||||||
|
|
||||||
|
#######################
|
||||||
|
yeni kategori ekler
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/categories' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"description": "yeni kategori",
|
||||||
|
"parent_id": null,
|
||||||
|
"slug": "eni-kategori",
|
||||||
|
"title": "yeni kategori"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/categories
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
201
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 128,
|
||||||
|
"title": "yeni kategori",
|
||||||
|
"slug": "eni-kategori"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 65
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 04:17:18 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
#######################
|
||||||
|
yeni alt kategori ekler
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/categories' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"description": "yeni alt kategori",
|
||||||
|
"parent_id": 128,
|
||||||
|
"slug": "yeni-alt-kategori",
|
||||||
|
"title": "yeni alt kategori"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/categories
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
201
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 129,
|
||||||
|
"title": "yeni alt kategori",
|
||||||
|
"slug": "yeni-alt-kategori"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 74
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 04:18:15 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
Responses
|
||||||
|
|
||||||
|
#######################
|
||||||
|
kategori gunceller
|
||||||
|
curl -X 'PUT' \
|
||||||
|
'http://localhost:8080/api/v1/admin/categories/128' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"description": "update",
|
||||||
|
"parent_id": null,
|
||||||
|
"slug": "update",
|
||||||
|
"title": "update"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/categories/128
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 128,
|
||||||
|
"title": "update",
|
||||||
|
"slug": "update"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Respons
|
||||||
|
|
||||||
|
#######################
|
||||||
|
siler
|
||||||
|
curl -X 'DELETE' \
|
||||||
|
'http://localhost:8080/api/v1/admin/categories/122' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/categories/122
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Undocumented
|
||||||
|
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": 122,
|
||||||
|
"message": "category deleted successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 52
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 04:20:35 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
#######################
|
||||||
|
soft delte restore
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/categories/122/restore' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64' \
|
||||||
|
-d ''
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/categories/122/restore
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 122,
|
||||||
|
"title": "İçecekler",
|
||||||
|
"slug": "icecekler-1771357850183010000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 80
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 04:21:57 GMT
|
||||||
|
vary: Origin
|
||||||
624
frontend/belgeler/admin_settings_crud.md
Normal file
624
frontend/belgeler/admin_settings_crud.md
Normal file
@@ -0,0 +1,624 @@
|
|||||||
|
Settigns ekleme
|
||||||
|
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs' \
|
||||||
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
-F 'title=Title' \
|
||||||
|
-F 'meta_title=Meta title' \
|
||||||
|
-F 'meta_description=Meta description' \
|
||||||
|
-F 'phone=Phone' \
|
||||||
|
-F 'url=URL' \
|
||||||
|
-F 'email=Email' \
|
||||||
|
-F 'facebook=Facebook' \
|
||||||
|
-F 'x=x' \
|
||||||
|
-F 'instagram=Instagram' \
|
||||||
|
-F 'whatsapp=Whatsapp' \
|
||||||
|
-F 'pinterest=Pinterest' \
|
||||||
|
-F 'linkedin=Linkedin' \
|
||||||
|
-F 'slogan=Slogan' \
|
||||||
|
-F 'address=Address' \
|
||||||
|
-F 'copyright=Copyright' \
|
||||||
|
-F 'map_embed=Map embed' \
|
||||||
|
-F 'w_logo=@354473ed-59e9-41cf-a655-ec5f7a77ccaa.png;type=image/png' \
|
||||||
|
-F 'b_logo=@354473ed-59e9-41cf-a655-ec5f7a77ccaa.png;type=image/png' \
|
||||||
|
-F 'is_active=true' \
|
||||||
|
-F 'w_width=100' \
|
||||||
|
-F 'w_height=100' \
|
||||||
|
-F 'w_quality=100' \
|
||||||
|
-F 'w_format=avif' \
|
||||||
|
-F 'b_width=100' \
|
||||||
|
-F 'b_height=100' \
|
||||||
|
-F 'b_quality=100' \
|
||||||
|
-F 'b_format=avif'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
201
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 1,
|
||||||
|
"CreatedAt": "2026-02-18T09:06:07.242338Z",
|
||||||
|
"UpdatedAt": "2026-02-18T09:06:07.242338Z",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"title": "Title",
|
||||||
|
"meta_title": "Meta title",
|
||||||
|
"meta_description": "Meta description",
|
||||||
|
"phone": "Phone",
|
||||||
|
"url": "URL",
|
||||||
|
"email": "Email",
|
||||||
|
"facebook": "Facebook",
|
||||||
|
"x": "x",
|
||||||
|
"instagram": "Instagram",
|
||||||
|
"whatsapp": "Whatsapp",
|
||||||
|
"pinterest": "Pinterest",
|
||||||
|
"linkedin": "Linkedin",
|
||||||
|
"slogan": "Slogan",
|
||||||
|
"address": "Address",
|
||||||
|
"copyright": "Copyright",
|
||||||
|
"map_embed": "Map embed",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405567230290000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405567233377000.png",
|
||||||
|
"is_active": true,
|
||||||
|
"w_width": 100,
|
||||||
|
"w_height": 100,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 100,
|
||||||
|
"b_height": 100,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 705
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:06:07 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
##################
|
||||||
|
|
||||||
|
Setiiggs tek gor
|
||||||
|
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings/2' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings/2
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T12:07:50+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T12:07:50+03:00",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"title": "Title",
|
||||||
|
"meta_title": "Meta title",
|
||||||
|
"meta_description": "Meta description",
|
||||||
|
"phone": "Phone",
|
||||||
|
"url": "URL",
|
||||||
|
"email": "Email",
|
||||||
|
"facebook": "Facebook",
|
||||||
|
"x": "x",
|
||||||
|
"instagram": "Instagram",
|
||||||
|
"whatsapp": "Whatsapp",
|
||||||
|
"pinterest": "Pinterest",
|
||||||
|
"linkedin": "Linkedin",
|
||||||
|
"slogan": "Slogan",
|
||||||
|
"address": "Address",
|
||||||
|
"copyright": "Copyright",
|
||||||
|
"map_embed": "Map embed",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405669986265000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405669989575000.png",
|
||||||
|
"is_active": true,
|
||||||
|
"w_width": 100,
|
||||||
|
"w_height": 100,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 100,
|
||||||
|
"b_height": 100,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 701
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:08:04 GMT
|
||||||
|
|
||||||
|
###############
|
||||||
|
setting guncelleme
|
||||||
|
|
||||||
|
curl -X 'PUT' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings/2' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs' \
|
||||||
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
-F 'title=ewr' \
|
||||||
|
-F 'meta_title=wer' \
|
||||||
|
-F 'meta_description=werwer' \
|
||||||
|
-F 'phone=wer' \
|
||||||
|
-F 'url=wer' \
|
||||||
|
-F 'email=wer' \
|
||||||
|
-F 'facebook=wer' \
|
||||||
|
-F 'x=wer' \
|
||||||
|
-F 'instagram=wer' \
|
||||||
|
-F 'whatsapp=ewr' \
|
||||||
|
-F 'pinterest=wer' \
|
||||||
|
-F 'linkedin=wer' \
|
||||||
|
-F 'slogan=wer' \
|
||||||
|
-F 'address=wre' \
|
||||||
|
-F 'copyright=wer' \
|
||||||
|
-F 'map_embed=wer' \
|
||||||
|
-F 'w_logo=@1657955547black-google-icon.png;type=image/png' \
|
||||||
|
-F 'b_logo=@845660.png;type=image/png' \
|
||||||
|
-F 'is_active=false' \
|
||||||
|
-F 'w_width=111' \
|
||||||
|
-F 'w_height=111' \
|
||||||
|
-F 'w_quality=100' \
|
||||||
|
-F 'w_format=avif' \
|
||||||
|
-F 'b_width=111' \
|
||||||
|
-F 'b_height=111' \
|
||||||
|
-F 'b_quality=100' \
|
||||||
|
-F 'b_format=avif'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings/2
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T12:07:50+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:10:27.629761Z",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"title": "ewr",
|
||||||
|
"meta_title": "wer",
|
||||||
|
"meta_description": "werwer",
|
||||||
|
"phone": "wer",
|
||||||
|
"url": "wer",
|
||||||
|
"email": "wer",
|
||||||
|
"facebook": "wer",
|
||||||
|
"x": "wer",
|
||||||
|
"instagram": "wer",
|
||||||
|
"whatsapp": "ewr",
|
||||||
|
"pinterest": "wer",
|
||||||
|
"linkedin": "wer",
|
||||||
|
"slogan": "wer",
|
||||||
|
"address": "wre",
|
||||||
|
"copyright": "wer",
|
||||||
|
"map_embed": "wer",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405827623476000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405827627412000.png",
|
||||||
|
"is_active": false,
|
||||||
|
"w_width": 111,
|
||||||
|
"w_height": 111,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 111,
|
||||||
|
"b_height": 111,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 637
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:10:27 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
settings restore
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings/2/restore' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs' \
|
||||||
|
-d ''
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings/2/restore
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T12:07:50+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T09:11:59.255443Z",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"title": "ewr",
|
||||||
|
"meta_title": "wer",
|
||||||
|
"meta_description": "werwer",
|
||||||
|
"phone": "wer",
|
||||||
|
"url": "wer",
|
||||||
|
"email": "wer",
|
||||||
|
"facebook": "wer",
|
||||||
|
"x": "wer",
|
||||||
|
"instagram": "wer",
|
||||||
|
"whatsapp": "ewr",
|
||||||
|
"pinterest": "wer",
|
||||||
|
"linkedin": "wer",
|
||||||
|
"slogan": "wer",
|
||||||
|
"address": "wre",
|
||||||
|
"copyright": "wer",
|
||||||
|
"map_embed": "wer",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405827623476000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405827627412000.png",
|
||||||
|
"is_active": false,
|
||||||
|
"w_width": 111,
|
||||||
|
"w_height": 111,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 111,
|
||||||
|
"b_height": 111,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 637
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:11:59 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
Responses
|
||||||
|
Code Description
|
||||||
|
200
|
||||||
|
|
||||||
|
##################
|
||||||
|
settings silmek
|
||||||
|
|
||||||
|
curl -X 'DELETE' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings/2' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings/2
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Undocumented
|
||||||
|
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"message": "setting deleted successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 49
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:13:23 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
Responses
|
||||||
|
Code Description
|
||||||
|
204
|
||||||
|
|
||||||
|
No Content
|
||||||
|
400
|
||||||
|
|
||||||
|
Bad Request
|
||||||
|
|
||||||
|
{
|
||||||
|
"additionalProp1":
|
||||||
|
|
||||||
|
|
||||||
|
####################
|
||||||
|
hepsini listele
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T12:07:50+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T12:10:27.629+03:00",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"title": "ewr",
|
||||||
|
"meta_title": "wer",
|
||||||
|
"meta_description": "werwer",
|
||||||
|
"phone": "wer",
|
||||||
|
"url": "wer",
|
||||||
|
"email": "wer",
|
||||||
|
"facebook": "wer",
|
||||||
|
"x": "wer",
|
||||||
|
"instagram": "wer",
|
||||||
|
"whatsapp": "ewr",
|
||||||
|
"pinterest": "wer",
|
||||||
|
"linkedin": "wer",
|
||||||
|
"slogan": "wer",
|
||||||
|
"address": "wre",
|
||||||
|
"copyright": "wer",
|
||||||
|
"map_embed": "wer",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405827623476000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405827627412000.png",
|
||||||
|
"is_active": false,
|
||||||
|
"w_width": 111,
|
||||||
|
"w_height": 111,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 111,
|
||||||
|
"b_height": 111,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ID": 1,
|
||||||
|
"CreatedAt": "2026-02-18T12:06:07.242+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T12:06:07.242+03:00",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"title": "Title",
|
||||||
|
"meta_title": "Meta title",
|
||||||
|
"meta_description": "Meta description",
|
||||||
|
"phone": "Phone",
|
||||||
|
"url": "URL",
|
||||||
|
"email": "Email",
|
||||||
|
"facebook": "Facebook",
|
||||||
|
"x": "x",
|
||||||
|
"instagram": "Instagram",
|
||||||
|
"whatsapp": "Whatsapp",
|
||||||
|
"pinterest": "Pinterest",
|
||||||
|
"linkedin": "Linkedin",
|
||||||
|
"slogan": "Slogan",
|
||||||
|
"address": "Address",
|
||||||
|
"copyright": "Copyright",
|
||||||
|
"map_embed": "Map embed",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405567230290000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405567233377000.png",
|
||||||
|
"is_active": true,
|
||||||
|
"w_width": 100,
|
||||||
|
"w_height": 100,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 100,
|
||||||
|
"b_height": 100,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 2
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 1376
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:31:04 GMT
|
||||||
|
|
||||||
|
sadece softdelete edilmisleri listele
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings?soft=only' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings?soft=only
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T12:07:50+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T12:10:27.629+03:00",
|
||||||
|
"DeletedAt": "2026-02-18T12:32:38.237+03:00",
|
||||||
|
"title": "ewr",
|
||||||
|
"meta_title": "wer",
|
||||||
|
"meta_description": "werwer",
|
||||||
|
"phone": "wer",
|
||||||
|
"url": "wer",
|
||||||
|
"email": "wer",
|
||||||
|
"facebook": "wer",
|
||||||
|
"x": "wer",
|
||||||
|
"instagram": "wer",
|
||||||
|
"whatsapp": "ewr",
|
||||||
|
"pinterest": "wer",
|
||||||
|
"linkedin": "wer",
|
||||||
|
"slogan": "wer",
|
||||||
|
"address": "wre",
|
||||||
|
"copyright": "wer",
|
||||||
|
"map_embed": "wer",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405827623476000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405827627412000.png",
|
||||||
|
"is_active": false,
|
||||||
|
"w_width": 111,
|
||||||
|
"w_height": 111,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 111,
|
||||||
|
"b_height": 111,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 702
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:32:56 GMT
|
||||||
|
|
||||||
|
Responses
|
||||||
|
Code
|
||||||
|
|
||||||
|
hem soft delete hemde delete olmayan lari listele
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/settings?soft=with' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzE0MTYyMjcsImlhdCI6MTc3MTQwNTQyNywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.X6mTnoiYJ1CUlarQlmwka0VpuDxYTIAV0QfS72AuBXs'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/settings?soft=with
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"ID": 2,
|
||||||
|
"CreatedAt": "2026-02-18T12:07:50+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T12:10:27.629+03:00",
|
||||||
|
"DeletedAt": "2026-02-18T12:32:38.237+03:00",
|
||||||
|
"title": "ewr",
|
||||||
|
"meta_title": "wer",
|
||||||
|
"meta_description": "werwer",
|
||||||
|
"phone": "wer",
|
||||||
|
"url": "wer",
|
||||||
|
"email": "wer",
|
||||||
|
"facebook": "wer",
|
||||||
|
"x": "wer",
|
||||||
|
"instagram": "wer",
|
||||||
|
"whatsapp": "ewr",
|
||||||
|
"pinterest": "wer",
|
||||||
|
"linkedin": "wer",
|
||||||
|
"slogan": "wer",
|
||||||
|
"address": "wre",
|
||||||
|
"copyright": "wer",
|
||||||
|
"map_embed": "wer",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405827623476000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405827627412000.png",
|
||||||
|
"is_active": false,
|
||||||
|
"w_width": 111,
|
||||||
|
"w_height": 111,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 111,
|
||||||
|
"b_height": 111,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ID": 1,
|
||||||
|
"CreatedAt": "2026-02-18T12:06:07.242+03:00",
|
||||||
|
"UpdatedAt": "2026-02-18T12:06:07.242+03:00",
|
||||||
|
"DeletedAt": null,
|
||||||
|
"title": "Title",
|
||||||
|
"meta_title": "Meta title",
|
||||||
|
"meta_description": "Meta description",
|
||||||
|
"phone": "Phone",
|
||||||
|
"url": "URL",
|
||||||
|
"email": "Email",
|
||||||
|
"facebook": "Facebook",
|
||||||
|
"x": "x",
|
||||||
|
"instagram": "Instagram",
|
||||||
|
"whatsapp": "Whatsapp",
|
||||||
|
"pinterest": "Pinterest",
|
||||||
|
"linkedin": "Linkedin",
|
||||||
|
"slogan": "Slogan",
|
||||||
|
"address": "Address",
|
||||||
|
"copyright": "Copyright",
|
||||||
|
"map_embed": "Map embed",
|
||||||
|
"w_logo": "/uploads/logos/wlogo-1771405567230290000.png",
|
||||||
|
"b_logo": "/uploads/logos/blogo-1771405567233377000.png",
|
||||||
|
"is_active": true,
|
||||||
|
"w_width": 100,
|
||||||
|
"w_height": 100,
|
||||||
|
"w_quality": 100,
|
||||||
|
"w_format": "avif",
|
||||||
|
"b_width": 100,
|
||||||
|
"b_height": 100,
|
||||||
|
"b_quality": 100,
|
||||||
|
"b_format": "avif"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 2
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 1403
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 09:34:15 GMT
|
||||||
|
|
||||||
|
Responses
|
||||||
|
Code Description
|
||||||
|
200
|
||||||
|
|
||||||
|
OK
|
||||||
|
|
||||||
259
frontend/belgeler/admin_tags.md
Normal file
259
frontend/belgeler/admin_tags.md
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
Proje `frontend` klasörü altında yapılandırılmıştır. Gerekli tüm paketler (`package.json`) önceden yüklenmiştir:
|
||||||
|
- **Framework:** Next.js 16 (App Router)
|
||||||
|
- **UI:** React 19, Tailwind CSS v4, shadcn/ui
|
||||||
|
- **İkonlar:** lucide-react
|
||||||
|
- **Validasyon:** Zod
|
||||||
|
- **Auth:** NextAuth.js
|
||||||
|
- **Bildirimler:** SweetAlert2
|
||||||
|
- **Güvenlik:** nextjs-turnstile (Cloudflare)
|
||||||
|
- **Senin ile sadece Frontend Üstünde Çalışıyorum**
|
||||||
|
- **Backend ile ilgili bir şey Yapman Gerekirse Bana Söylemen Yeterli**
|
||||||
|
|
||||||
|
#######################
|
||||||
|
Silnmis ve silinmemiş hepsini getirir
|
||||||
|
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/tags?soft=with' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTY3NDEsImlhdCI6MTc3MTM4NTk0MSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.yFU_fmErhi50MgvP7PYHDr0E-Dp5FUlSnJP5OmYgqG8'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/tags?soft=with
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"name": "Travel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"name": "Food"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"name": "Nature"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"name": "Life"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"name": "Coding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"name": "Tutorial"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"name": "Api"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Web"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Gin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Go"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 10
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 281
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 03:41:13 GMT
|
||||||
|
|
||||||
|
#######################
|
||||||
|
Sadece silinmiş tagları getir
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/tags?soft=only' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTY3NDEsImlhdCI6MTc3MTM4NTk0MSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.yFU_fmErhi50MgvP7PYHDr0E-Dp5FUlSnJP5OmYgqG8'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/tags?soft=only
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": null,
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 47
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 03:39:38 GMT
|
||||||
|
|
||||||
|
Responses
|
||||||
|
Code Description
|
||||||
|
200
|
||||||
|
|
||||||
|
OK
|
||||||
|
|
||||||
|
#######################
|
||||||
|
Yeni Tag Olusturu
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/tags' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTY3NDEsImlhdCI6MTc3MTM4NTk0MSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.yFU_fmErhi50MgvP7PYHDr0E-Dp5FUlSnJP5OmYgqG8' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"name": "yenitag"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/tags
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
201
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 11,
|
||||||
|
"name": "yenitag"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 35
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 03:42:05 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
#######################
|
||||||
|
|
||||||
|
tagi gunceller
|
||||||
|
curl -X 'PUT' \
|
||||||
|
'http://localhost:8080/api/v1/admin/tags/11' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTY3NDEsImlhdCI6MTc3MTM4NTk0MSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.yFU_fmErhi50MgvP7PYHDr0E-Dp5FUlSnJP5OmYgqG8' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"name": "update"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/tags/11
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 11,
|
||||||
|
"name": "update"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 34
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 03:43:10 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
#######################
|
||||||
|
|
||||||
|
tagi siler
|
||||||
|
curl -X 'DELETE' \
|
||||||
|
'http://localhost:8080/api/v1/admin/tags/11' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTY3NDEsImlhdCI6MTc3MTM4NTk0MSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.yFU_fmErhi50MgvP7PYHDr0E-Dp5FUlSnJP5OmYgqG8'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/tags/11
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
204
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
date: Wed,18 Feb 2026 03:43:45 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
Responses
|
||||||
|
|
||||||
|
#######################
|
||||||
|
|
||||||
|
tag restore
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/tags/11/restore' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTcyMzksImlhdCI6MTc3MTM4NjQzOSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.ueKzmNpcFfyZlwruom6odx3ZegIJG_WCr5xJuepiG64' \
|
||||||
|
-d ''
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/tags/11/restore
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 11,
|
||||||
|
"name": "update"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 34
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 03:47:36 GMT
|
||||||
|
vary: Origin
|
||||||
112
frontend/belgeler/admin_user.md
Normal file
112
frontend/belgeler/admin_user.md
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
# Admin Panel — Görev Tanımı (Next.js 16 + TypeScript)
|
||||||
|
|
||||||
|
## Kısa Özet
|
||||||
|
Bu görevde Next.js 16 ve paylaştığın paketler kullanılarak önce masaüstü öncelikli,
|
||||||
|
responsive bir Admin Paneli geliştirilecek; Admin
|
||||||
|
Kod üretimi için aşağıdaki gereksinimler ve kabul kriterleri tam
|
||||||
|
uygulanmalıdır.
|
||||||
|
|
||||||
|
## Teknoloji Yığını (Zorunlu)
|
||||||
|
- Next.js 16 (App Router /app)
|
||||||
|
- React 19, TypeScript
|
||||||
|
- Tailwind CSS v4, shadcn bileşenleri
|
||||||
|
- class-variance-authority, tailwind-merge
|
||||||
|
- lucide-react (ikonlar)
|
||||||
|
- sweetalert2 (bildirimler/konfirmasyonlar)
|
||||||
|
- zod (validasyon)
|
||||||
|
- next-auth (kimlik doğrulama)
|
||||||
|
- nextjs-turnstile (Cloudflare Turnstile entegrasyonu)
|
||||||
|
- tw-animate-css (isteğe bağlı animasyonlar)
|
||||||
|
|
||||||
|
Yeni büyük kütüphaneler eklemek gerekiyorsa önceden onay istenmelidir.
|
||||||
|
Küçük yardımcı util paketleri gerektiğinde kabul edilebilir ama öncelik mevcut paketlerle çözmek.
|
||||||
|
|
||||||
|
## Tasarım Sistemi ve UI
|
||||||
|
- shadcn + Tailwind üzerinde tutarlı bir design-system oluştur: tokenlar (renk, spacing, tipografi), light/dark tema.
|
||||||
|
- Temel component seti: Button, Input, Select, TextArea, Modal, Table, Pagination, Badge, Toast, Card, Form.
|
||||||
|
- class-variance-authority ile variant/size yönetimi, tailwind-merge ile conditional class birleştirme.
|
||||||
|
- İkonlar lucide-react ile sağlanacak.
|
||||||
|
- Erişilebilirlik: semantic HTML, aria attributeleri, klavye erişimi, WCAG AA hedefleri.
|
||||||
|
|
||||||
|
## Mimari ve Veri Akışı
|
||||||
|
- App Router (app/) kullan, sunucu bileşenleri (server components) ile veri yüklemesi/SSR; client components interaktivite için.
|
||||||
|
- Veri yüklemelerinde sunucu tarafı yükleme (server components) tercih edilir; client-side filtreleme/paginasyon için fetch + useState/useEffect kullanılabilir.
|
||||||
|
- Global state gerekiyorsa React Context ile minimal çözüm (yeni global state kütüphanesi eklenmeyecek).
|
||||||
|
|
||||||
|
## Kimlik Doğrulama & Yetkilendirme
|
||||||
|
- NextAuth ile güvenli oturum/JWT tabanlı kimlik doğrulama uygulanacak.
|
||||||
|
- Role-based access control: en az iki rol (superadmin, admin).
|
||||||
|
- Admin rotaları server-side yetki kontrolü ile korunacak (middleware veya server actions).
|
||||||
|
- /admin/login sayfasına Cloudflare Turnstile (nextjs-turnstile) entegre edilecek.
|
||||||
|
|
||||||
|
## Routing & Sayfalar (Zorunlu)
|
||||||
|
- /admin/login
|
||||||
|
- /admin → /admin yönlendirme (Dashboard)
|
||||||
|
- /admin (KPI kartları, son işlemler, hızlı aksiyonlar)
|
||||||
|
- /admin/users (liste, arama, filtre, pagination, CSV export)
|
||||||
|
- /admin/users/[id] (profil, roller, aktif/devre dışı)
|
||||||
|
- /admin/products (CRUD: liste, oluştur, düzenle, sil)
|
||||||
|
- /admin/orders (liste, detay, durum güncelleme)
|
||||||
|
- /admin/settings (genel, güvenlik, entegrasyonlar)
|
||||||
|
- /admin/profile
|
||||||
|
|
||||||
|
## Veri Modelleri (Örnek)
|
||||||
|
- Users: id, name, email, role, status, createdAt
|
||||||
|
- Products: id, title, sku, price, inventory, images[], status
|
||||||
|
- Orders: id, userId, items[], total, status, createdAt
|
||||||
|
|
||||||
|
(Not: Backend yoksa örnek/mock endpoint’ler veya mevcut API ile uyumlu yapı sağlanmalı.)
|
||||||
|
|
||||||
|
## Formlar & Validasyon
|
||||||
|
- Tüm formlarda Zod ile hem client-side hem server-side validasyon.
|
||||||
|
- Form submitleri server actions veya route handlers ile işlenmeli.
|
||||||
|
- Başarı/hata bildirimleri için sweetalert2 kullanılacak.
|
||||||
|
|
||||||
|
## Dosya/Resim Yükleme
|
||||||
|
- Gerçek bir backend/3rd-party (S3) yoksa: client-side önizleme sağlayan placeholder upload akışı oluştur; upload endpoint için gerekli iskelet/protokol hazır olsun.
|
||||||
|
|
||||||
|
## Güvenlik
|
||||||
|
- Tüm admin rotaları server-side yetkilendirmeyle korunacak.
|
||||||
|
- Hassas veriler .env ile saklanacak (README’de açıkça listelenecek).
|
||||||
|
- XSS/CSRF/SSRF risklerini azaltacak NextAuth & server actions en iyi uygulamalarına uyulacak.
|
||||||
|
|
||||||
|
## Performans & Optimizasyon
|
||||||
|
- Hedef: sayfa başlangıç süresi < 1.5s (kritik CSS minimal, resimler optimize).
|
||||||
|
- Lazy load, code-splitting, image optimization kullanımı önerilir.
|
||||||
|
|
||||||
|
## Test & Kalite
|
||||||
|
- TypeScript tipleri zorunlu, ESLint konfigürasyonuna uyulacak.
|
||||||
|
- Component-level testler opsiyonel; ek paket gerekiyorsa sonradan onay alınacak.
|
||||||
|
- README: kurulum, env değişkenleri, çalıştırma ve mimari kısa açıklama olacak.
|
||||||
|
|
||||||
|
## Hata Yönetimi & İzleme
|
||||||
|
- Merkezi error handling mekanizması.
|
||||||
|
- Kullanıcıya sweetalert2 ile başarılı/başarısız geri bildirimleri göster.
|
||||||
|
|
||||||
|
## Internationalization
|
||||||
|
- Proje i18n'ye hazır olmalı (tüm metinler merkezi çeviri kaynağından çekilecek).
|
||||||
|
|
||||||
|
## Kabul Kriterleri (Öncelikli)
|
||||||
|
1. Admin login çalışıyor; Turnstile doğrulaması entegre ve çalışır.
|
||||||
|
2. Rol tabanlı erişim ile korunan tüm /admin sayfalarına yetkisiz erişim engelleniyor.
|
||||||
|
3. Dashboard KPI kartları ve tablolar sunuyor; kullanıcı ve ürün CRUD fonksiyonları tamam.
|
||||||
|
4. Tüm formlar Zod ile client ve server validasyonu sağlıyor.
|
||||||
|
5. Component kütüphanesi shadcn + Tailwind ile tutarlı, responsive ve erişilebilir.
|
||||||
|
6. UX geri bildirimleri sweetalert2 ile gösteriliyor.
|
||||||
|
7. Kod TypeScript ile tam tiplenmiş ve ESLint uyarılarına duyarlı.
|
||||||
|
|
||||||
|
## Teslimat (Çıktı)
|
||||||
|
- Çalışır Next.js projesi (kaynak kod).
|
||||||
|
- README: kurulum, env değişkenleri (NEXTAUTH_URL, NEXTAUTH_SECRET, DATABASE_URL, TURNSTILE_SITEKEY, TURNSTILE_SECRET vb.), çalıştırma talimatları.
|
||||||
|
- Temel component listesi ve kısa kullanım notları.
|
||||||
|
- Kabul testi checklist'i (madde madde doğrulanabilir).
|
||||||
|
|
||||||
|
## Ek Kurallar & Notlar
|
||||||
|
- Yeni ana kütüphaneler eklemeden önce onay iste.
|
||||||
|
- Tasarım ve component kararları tutarlılık için belgelenmeli.
|
||||||
|
- Admin tamamlandıktan sonra müşteri-facing frontend için aynı design-system kullanılacak; bu aşama ayrı kabul kriterleriyle planlanacak.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Bu dosyayı doğrudan görev olarak kullan:
|
||||||
|
ve detayli bir kulanama kılavuzu hazırla.
|
||||||
306
frontend/belgeler/admin_user_crud.md
Normal file
306
frontend/belgeler/admin_user_crud.md
Normal file
@@ -0,0 +1,306 @@
|
|||||||
|
frontend
|
||||||
|
Proje `frontend` klasörü altında yapılandırılmıştır. Gerekli tüm paketler (`package.json`) önceden yüklenmiştir:
|
||||||
|
- **Framework:** Next.js 16 (App Router)
|
||||||
|
- **UI:** React 19, Tailwind CSS v4, shadcn/ui
|
||||||
|
- **İkonlar:** lucide-react
|
||||||
|
- **Validasyon:** Zod
|
||||||
|
- **Auth:** NextAuth.js
|
||||||
|
- **Bildirimler:** SweetAlert2
|
||||||
|
- **Güvenlik:** nextjs-turnstile (Cloudflare)
|
||||||
|
|
||||||
|
Hem softdelete edilmisler hermse aktif olan userleri Userler
|
||||||
|
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/users?soft=with' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTQ1NjksImlhdCI6MTc3MTM4Mzc2OSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.HCXkj1sYeR-1sXCvIQDgzgLuRVWo2NwI5M0WFTsbEtU'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/users?soft=with
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": 12,
|
||||||
|
"username": "aaaa bbb cccc ddddd",
|
||||||
|
"email": "arxxxxes2000@gmail.com",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 11,
|
||||||
|
"username": "update",
|
||||||
|
"email": "update@update.cem",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"username": "asasa fgfg",
|
||||||
|
"email": "aaaareaaas2ddd000@gmail.com",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false,
|
||||||
|
"deleted_at": "2026-02-18T06:20:56.99+03:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"username": "dfgdfg dfgdfg",
|
||||||
|
"email": "ares2ggddd000@gmail.com",
|
||||||
|
"email_verified": false,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"username": "vbcvbcvbb",
|
||||||
|
"email": "ares2000cvbcvb@gmail.com",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"username": "qweqweqwe",
|
||||||
|
"email": "areseeeeee2000@gmail.com",
|
||||||
|
"email_verified": false,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"username": "adminsss@demo.com",
|
||||||
|
"email": "ares2sss000@gmail.com",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"username": "aresds",
|
||||||
|
"email": "ares@asdf.com",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"username": "sss",
|
||||||
|
"email": "sss@ss.com",
|
||||||
|
"email_verified": false,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"username": "ddd",
|
||||||
|
"email": "ddd@dd.com",
|
||||||
|
"email_verified": false,
|
||||||
|
"is_admin": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"username": "beyhan",
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"username": "admin",
|
||||||
|
"email": "admin@gauth.local",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 12
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 1302
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 03:30:26 GMT
|
||||||
|
|
||||||
|
#################
|
||||||
|
sadece soft delete edilmis Userler
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/users?soft=only' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTE5NDgsImlhdCI6MTc3MTM4MTE0OCwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.MmYgMyLECZD1TcDOvDZCyWRKk9ogjFYhXnTXYUGzhMo'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/users?soft=only
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"items": null,
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 47
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 02:22:00 GMT
|
||||||
|
|
||||||
|
############
|
||||||
|
tek useri goster
|
||||||
|
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/admin/users/11' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTE5NDgsImlhdCI6MTc3MTM4MTE0OCwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.MmYgMyLECZD1TcDOvDZCyWRKk9ogjFYhXnTXYUGzhMo'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/users/11
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 11,
|
||||||
|
"username": "zxzx jkhjk",
|
||||||
|
"email": "addredds2dd000@gmail.com",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 128
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 02:23:44 GMT
|
||||||
|
|
||||||
|
#################
|
||||||
|
user iguncelle
|
||||||
|
curl -X 'PUT' \
|
||||||
|
'http://localhost:8080/api/v1/admin/users/11' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTE5NDgsImlhdCI6MTc3MTM4MTE0OCwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.MmYgMyLECZD1TcDOvDZCyWRKk9ogjFYhXnTXYUGzhMo' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"email": "update@update.cem",
|
||||||
|
"is_admin": false,
|
||||||
|
"username": "update"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/users/11
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 11,
|
||||||
|
"username": "update",
|
||||||
|
"email": "update@update.cem",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 105
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 02:25:24 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
Responses
|
||||||
|
|
||||||
|
#################
|
||||||
|
useri sil
|
||||||
|
curl -X 'DELETE' \
|
||||||
|
'http://localhost:8080/api/v1/admin/users/10' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTE5NDgsImlhdCI6MTc3MTM4MTE0OCwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.MmYgMyLECZD1TcDOvDZCyWRKk9ogjFYhXnTXYUGzhMo'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/users/10
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Undocumented
|
||||||
|
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"message": "user deleted successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 47
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 02:27:59 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
#################
|
||||||
|
User Restore
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/admin/users/10/restore' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzOTE5NDgsImlhdCI6MTc3MTM4MTE0OCwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.MmYgMyLECZD1TcDOvDZCyWRKk9ogjFYhXnTXYUGzhMo' \
|
||||||
|
-d ''
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/admin/users/10/restore
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"id": 10,
|
||||||
|
"username": "sfsdf. rtyrty",
|
||||||
|
"email": "aaaareaaas2ddd000@gmail.com",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 122
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Wed,18 Feb 2026 02:28:49 GMT
|
||||||
|
vary: Origin
|
||||||
194
frontend/belgeler/login_register.md
Normal file
194
frontend/belgeler/login_register.md
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
once login ve registeri yapalim
|
||||||
|
frontend
|
||||||
|
Proje `frontend` klasörü altında yapılandırılmıştır. Gerekli tüm paketler (`package.json`) önceden yüklenmiştir:
|
||||||
|
- **Framework:** Next.js 16 (App Router)
|
||||||
|
- **UI:** React 19, Tailwind CSS v4, shadcn/ui
|
||||||
|
- **İkonlar:** lucide-react
|
||||||
|
- **Validasyon:** Zod
|
||||||
|
- **Auth:** NextAuth.js
|
||||||
|
- **Bildirimler:** SweetAlert2
|
||||||
|
- **Güvenlik:** nextjs-turnstile (Cloudflare)
|
||||||
|
|
||||||
|
Login Backend
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/auth/login' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"password": "1923btO**"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/auth/login
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
Download
|
||||||
|
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzNzA1NzcsImlhdCI6MTc3MTM1OTc3NywiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.zBCWJlsJxOvB4EzGn5ReutjocF884kJjFsPojbMCWiY",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzY1NDM3NzcsImlhdCI6MTc3MTM1OTc3Nywic3ViIjoyLCJ0b2tlbl90eXBlIjoicmVmcmVzaCJ9.1ASz8UcbuWY7zKRipoFuHbpTBcBMWEbp4TuNKlFffmA",
|
||||||
|
"user": {
|
||||||
|
"id": 2,
|
||||||
|
"username": "beyhan",
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_admin": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 498
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Tue,17 Feb 2026 20:22:57 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
Responses
|
||||||
|
|
||||||
|
|
||||||
|
Register Backend
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/auth/register' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"email": "ares@asdf.com",
|
||||||
|
"password": "12345678",
|
||||||
|
"username": "aresds"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/auth/register
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
201
|
||||||
|
Response body
|
||||||
|
Download
|
||||||
|
|
||||||
|
{
|
||||||
|
"message": "Registration successful. Please check your email to verify your account.",
|
||||||
|
"user": {
|
||||||
|
"id": 5,
|
||||||
|
"username": "aresds",
|
||||||
|
"email": "ares@asdf.com",
|
||||||
|
"email_verified": false,
|
||||||
|
"is_admin": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 186
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Tue,17 Feb 2026 20:24:12 GMT
|
||||||
|
vary: Origin
|
||||||
|
|
||||||
|
Email Token Dogrulama
|
||||||
|
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/auth/verify-email?token=e77abe8a0843b480cb00174d1a234568dea7ff8965c307365617f15726b20b00' \
|
||||||
|
-H 'accept: application/json'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/auth/verify-email?token=e77abe8a0843b480cb00174d1a234568dea7ff8965c307365617f15726b20b00
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
Download
|
||||||
|
|
||||||
|
{
|
||||||
|
"message": "Email verified successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 41
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Tue,17 Feb 2026 20:26:14 GMT
|
||||||
|
|
||||||
|
Refresh Token Backend
|
||||||
|
|
||||||
|
curl -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/auth/refresh' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzY1NDM3NzcsImlhdCI6MTc3MTM1OTc3Nywic3ViIjoyLCJ0b2tlbl90eXBlIjoicmVmcmVzaCJ9.1ASz8UcbuWY7zKRipoFuHbpTBcBMWEbp4TuNKlFffmA"
|
||||||
|
}'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/auth/refresh
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
Download
|
||||||
|
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzNzExMjUsImlhdCI6MTc3MTM2MDMyNSwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.aW_xKEF2bWcC1xJdUTG4RB8T4ITH2ChnXNIqr8kAqXE",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzY1NDQzMjUsImlhdCI6MTc3MTM2MDMyNSwic3ViIjoyLCJ0b2tlbl90eXBlIjoicmVmcmVzaCJ9.ybzA7oG7RJFSA5azD5h3mpwEXNapb2NyO4sWV-m3Jd4"
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
access-control-allow-credentials: true
|
||||||
|
access-control-allow-headers: Authorization,Content-Type,Accept,Origin,X-Requested-With
|
||||||
|
access-control-allow-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
|
||||||
|
access-control-allow-origin: http://localhost:8080
|
||||||
|
access-control-max-age: 600
|
||||||
|
content-length: 396
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Tue,17 Feb 2026 20:32:05 GMT
|
||||||
|
vary: Origin
|
||||||
|
############################
|
||||||
|
Auth ME
|
||||||
|
curl -X 'GET' \
|
||||||
|
'http://localhost:8080/api/v1/auth/me' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzEzNzIyMzIsImlhdCI6MTc3MTM2MTQzMiwiaXNfYWRtaW4iOnRydWUsInN1YiI6MiwidG9rZW5fdHlwZSI6ImFjY2VzcyJ9.LfpH9ldKqR2h1zqwXYHPNsqrzh20pYhFAdgCCEbKtwc'
|
||||||
|
|
||||||
|
Request URL
|
||||||
|
|
||||||
|
http://localhost:8080/api/v1/auth/me
|
||||||
|
|
||||||
|
Server response
|
||||||
|
Code Details
|
||||||
|
200
|
||||||
|
Response body
|
||||||
|
Download
|
||||||
|
|
||||||
|
{
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"email_verified": true,
|
||||||
|
"id": 2,
|
||||||
|
"is_admin": true,
|
||||||
|
"username": "beyhan"
|
||||||
|
}
|
||||||
|
|
||||||
|
Response headers
|
||||||
|
|
||||||
|
content-length: 94
|
||||||
|
content-type: application/json; charset=utf-8
|
||||||
|
date: Tue,17 Feb 2026 20:51:52 GMT
|
||||||
23
frontend/components.json
Normal file
23
frontend/components.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://ui.shadcn.com/schema.json",
|
||||||
|
"style": "new-york",
|
||||||
|
"rsc": true,
|
||||||
|
"tsx": true,
|
||||||
|
"tailwind": {
|
||||||
|
"config": "",
|
||||||
|
"css": "app/globals.css",
|
||||||
|
"baseColor": "neutral",
|
||||||
|
"cssVariables": true,
|
||||||
|
"prefix": ""
|
||||||
|
},
|
||||||
|
"iconLibrary": "lucide",
|
||||||
|
"rtl": false,
|
||||||
|
"aliases": {
|
||||||
|
"components": "@/components",
|
||||||
|
"utils": "@/lib/utils",
|
||||||
|
"ui": "@/components/ui",
|
||||||
|
"lib": "@/lib",
|
||||||
|
"hooks": "@/hooks"
|
||||||
|
},
|
||||||
|
"registries": {}
|
||||||
|
}
|
||||||
53
frontend/components/admin/AdminHeader.tsx
Normal file
53
frontend/components/admin/AdminHeader.tsx
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useSession, signOut } from "next-auth/react"
|
||||||
|
import { ModeToggle } from "@/components/ui/mode-toggle"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||||
|
import { LogOut, User } from "lucide-react"
|
||||||
|
|
||||||
|
export function AdminHeader() {
|
||||||
|
const { data: session } = useSession()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header className="sticky top-0 z-30 flex h-16 items-center gap-4 border-b bg-background px-6 shadow-sm">
|
||||||
|
<div className="flex flex-1 items-center gap-4">
|
||||||
|
<h1 className="text-lg font-semibold md:text-xl">Yönetici Paneli</h1>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<ModeToggle />
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" size="icon" className="rounded-full">
|
||||||
|
<Avatar>
|
||||||
|
<AvatarImage src={session?.user?.image || ""} alt={session?.user?.name || "Admin"} />
|
||||||
|
<AvatarFallback>{session?.user?.name?.[0]?.toUpperCase() || "A"}</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuLabel>Hesabım</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuItem disabled>
|
||||||
|
<User className="mr-2 h-4 w-4" />
|
||||||
|
<span>Profil</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuItem onClick={() => signOut({ callbackUrl: "/auth/login" })}>
|
||||||
|
<LogOut className="mr-2 h-4 w-4" />
|
||||||
|
<span>Çıkış Yap</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
)
|
||||||
|
}
|
||||||
105
frontend/components/admin/AdminSidebar.tsx
Normal file
105
frontend/components/admin/AdminSidebar.tsx
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import Link from "next/link"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import {
|
||||||
|
LayoutDashboard,
|
||||||
|
Users,
|
||||||
|
ShoppingBag,
|
||||||
|
Settings,
|
||||||
|
Package,
|
||||||
|
FileText,
|
||||||
|
Tag,
|
||||||
|
List,
|
||||||
|
Image // Import Image icon
|
||||||
|
} from "lucide-react"
|
||||||
|
|
||||||
|
const sidebarItems = [
|
||||||
|
{
|
||||||
|
title: "Dashboard",
|
||||||
|
href: "/admin",
|
||||||
|
icon: LayoutDashboard,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Kullanıcılar",
|
||||||
|
href: "/admin/users",
|
||||||
|
icon: Users,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Ürünler",
|
||||||
|
href: "/admin/products",
|
||||||
|
icon: Package,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Siparişler",
|
||||||
|
href: "/admin/orders",
|
||||||
|
icon: ShoppingBag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Blog Yazıları",
|
||||||
|
href: "/admin/posts",
|
||||||
|
icon: FileText,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Kategoriler",
|
||||||
|
href: "/admin/categories",
|
||||||
|
icon: List, // Using List icon for categories, need to import it
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Tags",
|
||||||
|
href: "/admin/tags",
|
||||||
|
icon: Tag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Hero Banner",
|
||||||
|
href: "/admin/heroes",
|
||||||
|
icon: Image,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Ayarlar",
|
||||||
|
href: "/admin/settings",
|
||||||
|
icon: Settings,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export function AdminSidebar() {
|
||||||
|
const pathname = usePathname()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="hidden border-r bg-muted/40 md:block w-64 min-h-screen">
|
||||||
|
<div className="flex h-full max-h-screen flex-col gap-2">
|
||||||
|
<div className="flex h-16 items-center border-b px-6">
|
||||||
|
<Link href="/" className="flex items-center gap-2 font-semibold">
|
||||||
|
<Package className="h-6 w-6" />
|
||||||
|
<span className="">E-Ticaret Admin</span>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 overflow-auto py-2">
|
||||||
|
<nav className="grid items-start px-4 text-sm font-medium">
|
||||||
|
{sidebarItems.map((item) => {
|
||||||
|
const Icon = item.icon
|
||||||
|
const isActive = pathname === item.href
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={item.href}
|
||||||
|
href={item.href}
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-3 rounded-lg px-3 py-2 transition-all hover:text-primary",
|
||||||
|
isActive
|
||||||
|
? "bg-muted text-primary"
|
||||||
|
: "text-muted-foreground"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon className="h-4 w-4" />
|
||||||
|
{item.title}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
12
frontend/components/providers/NextAuthProvider.tsx
Normal file
12
frontend/components/providers/NextAuthProvider.tsx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { SessionProvider } from "next-auth/react";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface NextAuthProviderProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const NextAuthProvider = ({ children }: NextAuthProviderProps) => {
|
||||||
|
return <SessionProvider>{children}</SessionProvider>;
|
||||||
|
};
|
||||||
11
frontend/components/providers/ThemeProvider.tsx
Normal file
11
frontend/components/providers/ThemeProvider.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { ThemeProvider as NextThemesProvider } from "next-themes"
|
||||||
|
|
||||||
|
export function ThemeProvider({
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof NextThemesProvider>) {
|
||||||
|
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
|
||||||
|
}
|
||||||
50
frontend/components/ui/avatar.tsx
Normal file
50
frontend/components/ui/avatar.tsx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import * as AvatarPrimitive from "@radix-ui/react-avatar"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const Avatar = React.forwardRef<
|
||||||
|
React.ElementRef<typeof AvatarPrimitive.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<AvatarPrimitive.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
Avatar.displayName = AvatarPrimitive.Root.displayName
|
||||||
|
|
||||||
|
const AvatarImage = React.forwardRef<
|
||||||
|
React.ElementRef<typeof AvatarPrimitive.Image>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<AvatarPrimitive.Image
|
||||||
|
ref={ref}
|
||||||
|
className={cn("aspect-square h-full w-full", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
AvatarImage.displayName = AvatarPrimitive.Image.displayName
|
||||||
|
|
||||||
|
const AvatarFallback = React.forwardRef<
|
||||||
|
React.ElementRef<typeof AvatarPrimitive.Fallback>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<AvatarPrimitive.Fallback
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex h-full w-full items-center justify-center rounded-full bg-muted",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
|
||||||
|
|
||||||
|
export { Avatar, AvatarImage, AvatarFallback }
|
||||||
48
frontend/components/ui/badge.tsx
Normal file
48
frontend/components/ui/badge.tsx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
import { Slot } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const badgeVariants = cva(
|
||||||
|
"inline-flex items-center justify-center rounded-full border border-transparent px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
|
outline:
|
||||||
|
"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||||
|
ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||||
|
link: "text-primary underline-offset-4 [a&]:hover:underline",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function Badge({
|
||||||
|
className,
|
||||||
|
variant = "default",
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span"> &
|
||||||
|
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||||
|
const Comp = asChild ? Slot.Root : "span"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="badge"
|
||||||
|
data-variant={variant}
|
||||||
|
className={cn(badgeVariants({ variant }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Badge, badgeVariants }
|
||||||
64
frontend/components/ui/button.tsx
Normal file
64
frontend/components/ui/button.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
import { Slot } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const buttonVariants = cva(
|
||||||
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
|
outline:
|
||||||
|
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
|
ghost:
|
||||||
|
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||||
|
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||||
|
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||||
|
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||||
|
icon: "size-9",
|
||||||
|
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
|
||||||
|
"icon-sm": "size-8",
|
||||||
|
"icon-lg": "size-10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function Button({
|
||||||
|
className,
|
||||||
|
variant = "default",
|
||||||
|
size = "default",
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"button"> &
|
||||||
|
VariantProps<typeof buttonVariants> & {
|
||||||
|
asChild?: boolean
|
||||||
|
}) {
|
||||||
|
const Comp = asChild ? Slot.Root : "button"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="button"
|
||||||
|
data-variant={variant}
|
||||||
|
data-size={size}
|
||||||
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Button, buttonVariants }
|
||||||
92
frontend/components/ui/card.tsx
Normal file
92
frontend/components/ui/card.tsx
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card"
|
||||||
|
className={cn(
|
||||||
|
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-header"
|
||||||
|
className={cn(
|
||||||
|
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-title"
|
||||||
|
className={cn("leading-none font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-description"
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-action"
|
||||||
|
className={cn(
|
||||||
|
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-content"
|
||||||
|
className={cn("px-6", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-footer"
|
||||||
|
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Card,
|
||||||
|
CardHeader,
|
||||||
|
CardFooter,
|
||||||
|
CardTitle,
|
||||||
|
CardAction,
|
||||||
|
CardDescription,
|
||||||
|
CardContent,
|
||||||
|
}
|
||||||
134
frontend/components/ui/data-table.tsx
Normal file
134
frontend/components/ui/data-table.tsx
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { ChevronLeft, ChevronRight } from "lucide-react"
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[]
|
||||||
|
data: TData[]
|
||||||
|
searchKey?: string
|
||||||
|
onSearch?: (value: string) => void
|
||||||
|
pageCount?: number
|
||||||
|
page?: number
|
||||||
|
onPageChange?: (page: number) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
searchKey,
|
||||||
|
onSearch,
|
||||||
|
pageCount,
|
||||||
|
page,
|
||||||
|
onPageChange,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
// eslint-disable-next-line react-hooks/incompatible-library
|
||||||
|
const table = useReactTable({
|
||||||
|
data: data || [],
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
manualPagination: true,
|
||||||
|
pageCount: pageCount,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{searchKey && onSearch && (
|
||||||
|
<div className="flex items-center py-4">
|
||||||
|
<Input
|
||||||
|
placeholder="Ara..."
|
||||||
|
onChange={(event) => onSearch(event.target.value)}
|
||||||
|
className="max-w-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table.getRowModel().rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||||
|
Sonuç bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{(pageCount !== undefined && page !== undefined && onPageChange) && (
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onPageChange(Math.max(page - 1, 1))}
|
||||||
|
disabled={page === 1}
|
||||||
|
>
|
||||||
|
<ChevronLeft className="h-4 w-4" />
|
||||||
|
Önceki
|
||||||
|
</Button>
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
Sayfa {page} / {pageCount || 1}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onPageChange(Math.min(page + 1, pageCount || 1))}
|
||||||
|
disabled={page >= (pageCount || 1)}
|
||||||
|
>
|
||||||
|
Sonraki
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
158
frontend/components/ui/dialog.tsx
Normal file
158
frontend/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { XIcon } from "lucide-react"
|
||||||
|
import { Dialog as DialogPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
|
function Dialog({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||||
|
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||||
|
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||||
|
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogClose({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||||
|
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogOverlay({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Overlay
|
||||||
|
data-slot="dialog-overlay"
|
||||||
|
className={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
showCloseButton = true,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||||
|
showCloseButton?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DialogPortal data-slot="dialog-portal">
|
||||||
|
<DialogOverlay />
|
||||||
|
<DialogPrimitive.Content
|
||||||
|
data-slot="dialog-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{showCloseButton && (
|
||||||
|
<DialogPrimitive.Close
|
||||||
|
data-slot="dialog-close"
|
||||||
|
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||||
|
>
|
||||||
|
<XIcon />
|
||||||
|
<span className="sr-only">Close</span>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
)}
|
||||||
|
</DialogPrimitive.Content>
|
||||||
|
</DialogPortal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="dialog-header"
|
||||||
|
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogFooter({
|
||||||
|
className,
|
||||||
|
showCloseButton = false,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & {
|
||||||
|
showCloseButton?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="dialog-footer"
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{showCloseButton && (
|
||||||
|
<DialogPrimitive.Close asChild>
|
||||||
|
<Button variant="outline">Close</Button>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Title
|
||||||
|
data-slot="dialog-title"
|
||||||
|
className={cn("text-lg leading-none font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Description
|
||||||
|
data-slot="dialog-description"
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogOverlay,
|
||||||
|
DialogPortal,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
}
|
||||||
257
frontend/components/ui/dropdown-menu.tsx
Normal file
257
frontend/components/ui/dropdown-menu.tsx
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function DropdownMenu({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||||
|
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Trigger
|
||||||
|
data-slot="dropdown-menu-trigger"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuContent({
|
||||||
|
className,
|
||||||
|
sideOffset = 4,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal>
|
||||||
|
<DropdownMenuPrimitive.Content
|
||||||
|
data-slot="dropdown-menu-content"
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</DropdownMenuPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuItem({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
variant = "default",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||||
|
inset?: boolean
|
||||||
|
variant?: "default" | "destructive"
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Item
|
||||||
|
data-slot="dropdown-menu-item"
|
||||||
|
data-inset={inset}
|
||||||
|
data-variant={variant}
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuCheckboxItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
checked,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
|
data-slot="dropdown-menu-checkbox-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
checked={checked}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.CheckboxItem>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioGroup
|
||||||
|
data-slot="dropdown-menu-radio-group"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioItem
|
||||||
|
data-slot="dropdown-menu-radio-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CircleIcon className="size-2 fill-current" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.RadioItem>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuLabel({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||||
|
inset?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Label
|
||||||
|
data-slot="dropdown-menu-label"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Separator
|
||||||
|
data-slot="dropdown-menu-separator"
|
||||||
|
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuShortcut({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span">) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
data-slot="dropdown-menu-shortcut"
|
||||||
|
className={cn(
|
||||||
|
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSub({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||||
|
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubTrigger({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||||
|
inset?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
|
data-slot="dropdown-menu-sub-trigger"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronRightIcon className="ml-auto size-4" />
|
||||||
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubContent
|
||||||
|
data-slot="dropdown-menu-sub-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuPortal,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuGroup,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuRadioGroup,
|
||||||
|
DropdownMenuRadioItem,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuShortcut,
|
||||||
|
DropdownMenuSub,
|
||||||
|
DropdownMenuSubTrigger,
|
||||||
|
DropdownMenuSubContent,
|
||||||
|
}
|
||||||
167
frontend/components/ui/form.tsx
Normal file
167
frontend/components/ui/form.tsx
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import type { Label as LabelPrimitive } from "radix-ui"
|
||||||
|
import { Slot } from "radix-ui"
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
FormProvider,
|
||||||
|
useFormContext,
|
||||||
|
useFormState,
|
||||||
|
type ControllerProps,
|
||||||
|
type FieldPath,
|
||||||
|
type FieldValues,
|
||||||
|
} from "react-hook-form"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
|
||||||
|
const Form = FormProvider
|
||||||
|
|
||||||
|
type FormFieldContextValue<
|
||||||
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
|
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||||
|
> = {
|
||||||
|
name: TName
|
||||||
|
}
|
||||||
|
|
||||||
|
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
||||||
|
{} as FormFieldContextValue
|
||||||
|
)
|
||||||
|
|
||||||
|
const FormField = <
|
||||||
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
|
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||||
|
>({
|
||||||
|
...props
|
||||||
|
}: ControllerProps<TFieldValues, TName>) => {
|
||||||
|
return (
|
||||||
|
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||||
|
<Controller {...props} />
|
||||||
|
</FormFieldContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const useFormField = () => {
|
||||||
|
const fieldContext = React.useContext(FormFieldContext)
|
||||||
|
const itemContext = React.useContext(FormItemContext)
|
||||||
|
const { getFieldState } = useFormContext()
|
||||||
|
const formState = useFormState({ name: fieldContext.name })
|
||||||
|
const fieldState = getFieldState(fieldContext.name, formState)
|
||||||
|
|
||||||
|
if (!fieldContext) {
|
||||||
|
throw new Error("useFormField should be used within <FormField>")
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = itemContext
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name: fieldContext.name,
|
||||||
|
formItemId: `${id}-form-item`,
|
||||||
|
formDescriptionId: `${id}-form-item-description`,
|
||||||
|
formMessageId: `${id}-form-item-message`,
|
||||||
|
...fieldState,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type FormItemContextValue = {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const FormItemContext = React.createContext<FormItemContextValue>(
|
||||||
|
{} as FormItemContextValue
|
||||||
|
)
|
||||||
|
|
||||||
|
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
const id = React.useId()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormItemContext.Provider value={{ id }}>
|
||||||
|
<div
|
||||||
|
data-slot="form-item"
|
||||||
|
className={cn("grid gap-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</FormItemContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||||
|
const { error, formItemId } = useFormField()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Label
|
||||||
|
data-slot="form-label"
|
||||||
|
data-error={!!error}
|
||||||
|
className={cn("data-[error=true]:text-destructive", className)}
|
||||||
|
htmlFor={formItemId}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormControl({ ...props }: React.ComponentProps<typeof Slot.Root>) {
|
||||||
|
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Slot.Root
|
||||||
|
data-slot="form-control"
|
||||||
|
id={formItemId}
|
||||||
|
aria-describedby={
|
||||||
|
!error
|
||||||
|
? `${formDescriptionId}`
|
||||||
|
: `${formDescriptionId} ${formMessageId}`
|
||||||
|
}
|
||||||
|
aria-invalid={!!error}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||||
|
const { formDescriptionId } = useFormField()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<p
|
||||||
|
data-slot="form-description"
|
||||||
|
id={formDescriptionId}
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
||||||
|
const { error, formMessageId } = useFormField()
|
||||||
|
const body = error ? String(error?.message ?? "") : props.children
|
||||||
|
|
||||||
|
if (!body) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<p
|
||||||
|
data-slot="form-message"
|
||||||
|
id={formMessageId}
|
||||||
|
className={cn("text-destructive text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
useFormField,
|
||||||
|
Form,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormMessage,
|
||||||
|
FormField,
|
||||||
|
}
|
||||||
21
frontend/components/ui/input.tsx
Normal file
21
frontend/components/ui/input.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type={type}
|
||||||
|
data-slot="input"
|
||||||
|
className={cn(
|
||||||
|
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
|
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||||
|
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Input }
|
||||||
24
frontend/components/ui/label.tsx
Normal file
24
frontend/components/ui/label.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { Label as LabelPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Label({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<LabelPrimitive.Root
|
||||||
|
data-slot="label"
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Label }
|
||||||
40
frontend/components/ui/mode-toggle.tsx
Normal file
40
frontend/components/ui/mode-toggle.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { Moon, Sun } from "lucide-react"
|
||||||
|
import { useTheme } from "next-themes"
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
|
||||||
|
export function ModeToggle() {
|
||||||
|
const { setTheme } = useTheme()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="icon">
|
||||||
|
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||||
|
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||||
|
<span className="sr-only">Tema değiştir</span>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem onClick={() => setTheme("light")}>
|
||||||
|
Aydınlık
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
||||||
|
Koyu
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setTheme("system")}>
|
||||||
|
Sistem
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
)
|
||||||
|
}
|
||||||
190
frontend/components/ui/select.tsx
Normal file
190
frontend/components/ui/select.tsx
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||||
|
import { Select as SelectPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Select({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||||
|
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||||
|
return <SelectPrimitive.Group data-slot="select-group" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectValue({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||||
|
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectTrigger({
|
||||||
|
className,
|
||||||
|
size = "default",
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||||
|
size?: "sm" | "default"
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Trigger
|
||||||
|
data-slot="select-trigger"
|
||||||
|
data-size={size}
|
||||||
|
className={cn(
|
||||||
|
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<SelectPrimitive.Icon asChild>
|
||||||
|
<ChevronDownIcon className="size-4 opacity-50" />
|
||||||
|
</SelectPrimitive.Icon>
|
||||||
|
</SelectPrimitive.Trigger>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
position = "item-aligned",
|
||||||
|
align = "center",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Portal>
|
||||||
|
<SelectPrimitive.Content
|
||||||
|
data-slot="select-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||||
|
position === "popper" &&
|
||||||
|
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
position={position}
|
||||||
|
align={align}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SelectScrollUpButton />
|
||||||
|
<SelectPrimitive.Viewport
|
||||||
|
className={cn(
|
||||||
|
"p-1",
|
||||||
|
position === "popper" &&
|
||||||
|
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Viewport>
|
||||||
|
<SelectScrollDownButton />
|
||||||
|
</SelectPrimitive.Content>
|
||||||
|
</SelectPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Label
|
||||||
|
data-slot="select-label"
|
||||||
|
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Item
|
||||||
|
data-slot="select-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
data-slot="select-item-indicator"
|
||||||
|
className="absolute right-2 flex size-3.5 items-center justify-center"
|
||||||
|
>
|
||||||
|
<SelectPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||||
|
</SelectPrimitive.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Separator
|
||||||
|
data-slot="select-separator"
|
||||||
|
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollUpButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollUpButton
|
||||||
|
data-slot="select-scroll-up-button"
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronUpIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollUpButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollDownButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollDownButton
|
||||||
|
data-slot="select-scroll-down-button"
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronDownIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollDownButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
|
SelectScrollDownButton,
|
||||||
|
SelectScrollUpButton,
|
||||||
|
SelectSeparator,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
}
|
||||||
40
frontend/components/ui/sonner.tsx
Normal file
40
frontend/components/ui/sonner.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import {
|
||||||
|
CircleCheckIcon,
|
||||||
|
InfoIcon,
|
||||||
|
Loader2Icon,
|
||||||
|
OctagonXIcon,
|
||||||
|
TriangleAlertIcon,
|
||||||
|
} from "lucide-react"
|
||||||
|
import { useTheme } from "next-themes"
|
||||||
|
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||||
|
|
||||||
|
const Toaster = ({ ...props }: ToasterProps) => {
|
||||||
|
const { theme = "system" } = useTheme()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Sonner
|
||||||
|
theme={theme as ToasterProps["theme"]}
|
||||||
|
className="toaster group"
|
||||||
|
icons={{
|
||||||
|
success: <CircleCheckIcon className="size-4" />,
|
||||||
|
info: <InfoIcon className="size-4" />,
|
||||||
|
warning: <TriangleAlertIcon className="size-4" />,
|
||||||
|
error: <OctagonXIcon className="size-4" />,
|
||||||
|
loading: <Loader2Icon className="size-4 animate-spin" />,
|
||||||
|
}}
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--normal-bg": "var(--popover)",
|
||||||
|
"--normal-text": "var(--popover-foreground)",
|
||||||
|
"--normal-border": "var(--border)",
|
||||||
|
"--border-radius": "var(--radius)",
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Toaster }
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user