Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
added initial migration, model and controller for group feature. see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas83 committed Mar 5, 2020
1 parent e465a67 commit cebb0d6
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 12 deletions.
24 changes: 24 additions & 0 deletions app/Group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Group extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'description', 'avatar',
'background', 'visibility',
];


public function content()
{
return $this->belongsToMany('App\Content');
}
}
26 changes: 26 additions & 0 deletions app/GroupMembers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class GroupMembers extends Model
{

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'group_id', 'user_id', 'status', 'is_moderator',
];

/**
* Get the user
*/
public function user()
{
return $this->belongsTo('App\User');
}
}
45 changes: 45 additions & 0 deletions app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class GroupController extends Controller
{


/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}


/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
52 changes: 52 additions & 0 deletions database/migrations/2020_03_05_203451_add_groups_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddGroupsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{

Schema::table('contents', function (Blueprint $table) {
$table->unsignedInteger('group_id')->after('user_id');
});

Schema::create('groups', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('avatar');
$table->string('background');
$table->text('description');
$table->enum('visibility', ['public', 'private']);
$table->timestamps();

});

Schema::create('group_members', function (Blueprint $table) {
$table->unsignedBigInteger('group_id');
$table->unsignedBigInteger('user_id');
$table->enum('status', ['confirmed', 'awaiting', 'blocking']);
$table->tinyInteger('is_moderator');
$table->foreign('group_id')->references('id')->on('contents')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
30 changes: 18 additions & 12 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
Route::resource('content/likes', 'ContentLikeController')->only([
'index',
]);

Route::get('/user/public', function (Request $request) {
if ($request->has('id')) {
return User::where('id', '=', $request->id)->select('id', 'name', 'bio', 'avatar', 'background', 'created_at')->first();
}
if ($request->has('name')) {
return User::where('name', '=', $request->name)->select('id', 'name', 'bio', 'avatar', 'background', 'created_at')->first();
}
});

});

Route::post(
Expand All @@ -41,24 +51,20 @@
Route::resource('content', 'ContentController')->only([
'store', 'update', 'destroy',
]);

Route::resource('group', 'GroupController')->only([
'store', 'update', 'destroy',
]);

Route::resource('user', 'UserController')->only([
'update',
]);

Route::post('content/upload', 'ContentController@upload');
Route::post('content/ogparser', 'ContentController@parseog');

Route::get('/user', function (Request $request) {
return $request->user();
});
});

Route::get('/user/public', function (Request $request) {
if ($request->has('id')) {
return User::where('id', '=', $request->id)->select('id', 'name', 'bio', 'avatar', 'background', 'created_at')->first();
}
if ($request->has('name')) {
return User::where('name', '=', $request->name)->select('id', 'name', 'bio', 'avatar', 'background', 'created_at')->first();
}
});

Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});

0 comments on commit cebb0d6

Please sign in to comment.