Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criação do metodo de registo e criação dos endpoints😑 #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/Activity/MailService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Kallun\Activity;

class MailService {

}
31 changes: 31 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Kallun\Http\Controllers;

use Illuminate\Http\Request;
use Kallun\Repository\UserRepository;

class UserController extends Controller
{
public function register(Request $request) {
$res = $request->validate([
"name" => "required",
"email" => "required|email|unique:users",
"password" => "required|min:6",
]);

if($res) {
$user = $request->only(["name", "password", "email"]);
$response = UserRepository::create($user);
return $response;
} else {
return response()->json([
"message" => "User already exists!"
], 400);
}
}

public function login (Request $request) {
return "Logando";
}
}
33 changes: 33 additions & 0 deletions app/Mail/UserEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Kallun\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class UserEmail extends Mailable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('view.name');
}
}
26 changes: 26 additions & 0 deletions app/Repository/UserRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace Kallun\Repository;

use Kallun\Models\User;

class UserRepository {
public static function create($user) {
$user["password"] = bcrypt($user["password"]);
try {
User::create($user)->save();

return response()->json([
"message" => "User was created with success!!",
], 201);

} catch(Exception $ex) {
return response()->json([
"message" => $ex,
], 400);
}
}

public static function findUser() {

}
}
23 changes: 23 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,26 @@
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});

Route::prefix('v1')->group(function () {

Route::prefix('auth')->group(function () {
Route::post('register', 'UserController@register');
Route::post('login', 'UserController@login');
});

/**
* Need to create the SlangController to
* replace the function hardcoded to controller function
*/

Route::prefix('slang')->group(function () {
Route::get('/{name?}', function ($name = "") {
return "retun slang! ".$name;
});
Route::post('/', function () {
return "add new slang";
});
});

});