Skip to content

Commit

Permalink
Merge pull request #56 from Crudzaso/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DiegoAndresRamirez authored Nov 11, 2024
2 parents 4bf6e9b + f12e1d0 commit f9d8408
Show file tree
Hide file tree
Showing 28 changed files with 1,148 additions and 415 deletions.
2 changes: 1 addition & 1 deletion Modules/Lotery/app/Models/Lotery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Lotery extends Model
*
* @var array
*/
protected $fillable = ['name', 'description', 'image_url']; // Agregar 'description' e 'image_url' para la asignación masiva
protected $fillable = ['name', 'description', 'url_imagen']; // Agregar 'description' e 'image_url' para la asignación masiva

/**
* Las relaciones de los sorteos con esta lotería (relación inversa).
Expand Down
32 changes: 32 additions & 0 deletions Modules/Raffle/app/Http/Controllers/RaffleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Modules\Raffle\Models\Raffle;
use Modules\Lotery\Models\Lotery;
use App\Models\User;
use Inertia\Inertia;

class RaffleController extends Controller
{
Expand Down Expand Up @@ -75,4 +76,35 @@ public function destroy($id)

return redirect()->route('raffles.index')->with('success', 'Rifa eliminada exitosamente.');
}

public function getRaffles(Request $request)
{
$query = Raffle::with('organizer', 'lottery');

if ($request->has('min_price')) {
$query->where('ticket_price', '>=', $request->input('min_price'));
}
if ($request->has('max_price')) {
$query->where('ticket_price', '<=', $request->input('max_price'));
}

if ($request->has('end_date')) {
$query->where('end_date', '<=', $request->input('end_date'));
}

$raffles = $query->paginate(6);
return response()->json($raffles);
}

public function getLastChanceRaffles()
{
$raffles = Raffle::where('end_date', '<', now()->addDays(10))
->whereColumn('tickets_sold', '<', 'total_tickets')
->with('organizer') // Incluir los datos del organizador
->orderBy('end_date', 'asc')
->limit(5)
->get();

return response()->json($raffles);
}
}
1 change: 1 addition & 0 deletions Modules/Raffle/app/Models/Raffle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Raffle extends Model
use HasFactory;

protected $fillable = [
'name',
'organizer_id',
'lottery_id',
'ticket_price',
Expand Down
1 change: 1 addition & 0 deletions Modules/Raffle/resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@endforeach
</tbody>
</table>
<active-raffles></active-raffles>
</div>
</div>
@endsection
2 changes: 1 addition & 1 deletion app/Filament/Resources/LoteryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function form(Form $form): Form
->nullable()
->maxLength(500),

TextInput::make('image_url') // Usamos TextInput para la URL
TextInput::make('url_imagen') // Usamos TextInput para la URL
->label('Image URL')
->nullable()
->url() // Esto asegura que solo se ingrese una URL válida
Expand Down
8 changes: 6 additions & 2 deletions app/Filament/Resources/RafflesResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static function form(Form $form): Form
{
return $form
->schema([

TextInput::make('name')
->label('Rifa')
->required(),

Select::make('organizer_id')
->label('Organizador')
->options(User::all()->pluck('name', 'id'))
Expand Down Expand Up @@ -77,11 +82,10 @@ public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->label('Nombre')->sortable(),
Tables\Columns\TextColumn::make('organizer.name')->label('Organizador')->sortable(),
Tables\Columns\TextColumn::make('lottery.name')->label('Lotería')->sortable(),
Tables\Columns\TextColumn::make('ticket_price')->label('Precio del Boleto')->sortable(),
Tables\Columns\TextColumn::make('total_tickets')->label('Total de Boletos')->sortable(),
Tables\Columns\TextColumn::make('tickets_sold')->label('Boletos Vendidos')->sortable(),
Tables\Columns\TextColumn::make('start_date')->label('Fecha de Inicio')->sortable()->dateTime(),
Tables\Columns\TextColumn::make('end_date')->label('Fecha de Finalización')->sortable()->dateTime(),
Tables\Columns\TextColumn::make('created_at')->label('Creado en')->sortable()->dateTime(),
Expand Down
102 changes: 102 additions & 0 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Laravel\Socialite\Facades\Socialite;
use App\Models\User;

class AuthController extends Controller
{
public function redirectToGitHub()
{
return Socialite::driver('github')->redirect();
}

public function handleGitHubCallback()
{
try {
$githubUser = Socialite::driver('github')->user();

// Verifica los datos recibidos
Log::info('Usuario de GitHub: ', [
'id' => $githubUser->id,
'nickname' => $githubUser->nickname,
'name' => $githubUser->name,
'email' => $githubUser->email,
'avatar' => $githubUser->avatar,
]);

// Encuentra o crea un usuario
$user = User::firstOrCreate([
'email' => $githubUser->email,
], [
'name' => $githubUser->name ?: 'Nombre por defecto',
'github_id' => $githubUser->id,
'lastname' => 'Apellidos por defecto',
'password' => bcrypt('random_password'),
'phone_number' => 'Número por defecto',
'document' => '00000000',
'document_type' => 'CC',
]);

// Inicia sesión al usuario
Auth::login($user);

return redirect('/dashboard');
} catch (\Exception $e) {
// Registra el error
Log::error('Error en la autenticación de GitHub: ' . $e->getMessage());
return redirect('/')->with('error', 'No se pudo iniciar sesión con GitHub.');
}
}

public function redirectToGoogle()
{
return Socialite::driver('google')->redirect();
}

public function handleGoogleCallback()
{
try {
Log::info('Entrando en el callback de Google.');

// Obtener el usuario de Google
$googleUser = Socialite::driver('google')->user();

Log::info('Usuario de Google obtenido', [
'email' => $googleUser->getEmail(),
'name' => $googleUser->getName(),
]);

// Buscar o crear un usuario en tu base de datos
$authUser = User::firstOrCreate(
['email' => $googleUser->getEmail()],
[
'name' => $googleUser->getName(),
'google_id' => $googleUser->getId(), // Guarda el google_id
'lastname' => 'Apellidos por defecto', // Asegúrate de que este campo exista
'password' => 'sadsadasd', // Generar una contraseña aleatoria
'phone_number' => 'Número por defecto', // Asegúrate de que este campo exista
'document' => uniqid(), // O una lógica para generar un documento único
'document_type' => 'CC', // Asegúrate de que este campo exista
]
);

Log::info('Usuario autenticado o creado', [
'authUser' => $authUser,
]);

// Iniciar sesión con el usuario autenticado
Auth::login($authUser, true);

// Redirigir a la página deseada
return redirect()->route('dashboard'); // Cambia a la ruta que desees
} catch (\Exception $e) {
// Registra el error
Log::error('Error en la autenticación de Google: ' . $e);
return redirect('/')->with('error', 'No se pudo iniciar sesión con Google.');
}
}
}
1 change: 0 additions & 1 deletion app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function panel(Panel $panel): Panel
DispatchServingFilamentEvent::class,
])
->authMiddleware([
'role:admin',
]);
}
}
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"vue": "^3.3.13"
},
"dependencies": {
"@splidejs/vue-splide": "^0.6.12",
"chart.js": "^4.4.6",
"lucide-vue-next": "^0.454.0",
"vue-router": "^4.4.5"
Expand Down
1 change: 1 addition & 0 deletions public/assets/media/gananza/filter-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/assets/media/gananza/filter-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions resources/js/Components/Dashboard/ActiveRaffles.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<template>
<section :class="['active-raffles my-8', theme.backgroundClass]">
<h2 :class="['text-2xl font-bold mb-6 text-center', theme.textPrimary]">Rifas Activas</h2>

<!-- Mensaje si no hay rifas -->
<div v-if="raffles.data.length === 0" :class="theme.textSecondary">
No hay rifas activas en este momento.
</div>

<!-- Grid de Rifas (1 fila con 3 cartas) -->
<div v-else class="container mx-auto w-full grid grid-cols-1 md:grid-cols-3 gap-6">
<RaffleCard
v-for="raffle in raffles.data.slice(0, 3)"
:key="raffle.id"
:raffle="raffle"
/>
</div>

<!-- Botón para ver todas las rifas -->
<div class="flex justify-center mt-8">
<button
@click="redirectToRaffles"
:class="[theme.buttonPrimary]"
class="py-2 px-6 rounded-lg hover:scale-105 transition"
>
¡Ver todas las rifas!
</button>
</div>
</section>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue';
import { useDarkMode } from '@/composables/useDarkMode';
import RaffleCard from './RaffleCard.vue';
const raffles = ref({ data: [] });
const { isDarkMode } = useDarkMode();
const theme = computed(() => ({
backgroundClass: isDarkMode.value
? 'bg-[#1a1a1c] shadow-lg' // Fondo oscuro para Dark Mode
: 'bg-[#F5F5F7] shadow-sm ', // Fondo blanco suave para Light Mode
textPrimary: isDarkMode.value ? 'text-white' : 'text-gray-900',
textSecondary: isDarkMode.value ? 'text-gray-400' : 'text-gray-600',
buttonPrimary: isDarkMode.value
? 'bg-blue-700 text-white hover:bg-blue-800'
: 'bg-blue-600 text-white hover:bg-blue-700',
}));
const redirectToRaffles = () => {
window.location.href = '/rifas-activas';
};
const fetchRaffles = async () => {
try {
const response = await fetch('/raffles-actives');
if (!response.ok) {
throw new Error('Error al obtener las rifas activas');
}
raffles.value = await response.json();
} catch (error) {
console.error('Error fetching raffles:', error);
}
};
onMounted(() => fetchRaffles());
</script>

<style scoped>
.active-raffles {
border-radius: 12px;
padding: 1rem;
}
button {
transition: transform 0.2s;
}
button:hover {
transform: scale(1.05);
}
</style>
Loading

0 comments on commit f9d8408

Please sign in to comment.