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

Release v5 #6

Merged
merged 6 commits into from
Jan 16, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Liker DocBlocks and upgrade instructions
antonkomarev committed Jan 11, 2018
commit 176d2da43489eed1067e7625eca51a12f3ad3806
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,23 @@

All notable changes to `laravel-love` will be documented in this file.

## [5.0.0] - 2018-01-11

### Added

- Added `Cog\Contracts\Love\Liker\Models\Liker` contract with methods `like`, `dislike`, `unlike`, `undislike`, `toggleLike`, `toggleDislike`, `hasLiked`, `hasDisliked`

### Changed

- Method `like` renamed to `likeBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract
- Method `dislike` renamed to `dislikeBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract
- Method `unlike` renamed to `unlikeBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract
- Method `undislike` renamed to `undislikeBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract
- Method `liked` renamed to `likedBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract
- Method `disliked` renamed to `dislikedBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract
- Method `likeToggle` renamed to `toggleLikeBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract
- Method `dislikeToggle` renamed to `toggleDislikeBy` in `Cog\Contracts\Love\Likeable\Models\Likeable` contract

## [4.0.0] - 2018-01-04

### Changed
@@ -149,6 +166,7 @@ All notable changes to `laravel-love` will be documented in this file.

- Initial release

[5.0.0]: https://github.com/cybercog/laravel-love/compare/4.0.0...5.0.0
[4.0.0]: https://github.com/cybercog/laravel-love/compare/3.1.0...4.0.0
[3.1.0]: https://github.com/cybercog/laravel-love/compare/3.0.0...3.1.0
[3.0.0]: https://github.com/cybercog/laravel-love/compare/2.2.5...3.0.0
14 changes: 14 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Upgrade Guide

- [From v4 to v5](#from-v4-to-v5)
- [From v3 to v4](#from-v3-to-v4)

## From v4 to v5

### Likeable model methods

- Find all `like` method and replace it with `likeBy`
- Find all `dislike` method and replace it with `dislikeBy`
- Find all `unlike` method and replace it with `unlikeBy`
- Find all `undislike` method and replace it with `undislikeBy`
- Find all `likeToggle` method and replace it with `toggleLikeBy`
- Find all `dislikeToggle` method and replace it with `toggleDislikeBy`
- Find all `liked` method and replace it with `isLikedBy`
- Find all `disliked` method and replace it with `isDislikedBy`

## From v3 to v4

Because there are many breaking changes an upgrade is not that easy. There are many edge cases this guide does not cover.
20 changes: 18 additions & 2 deletions contracts/Liker/Models/Liker.php
Original file line number Diff line number Diff line change
@@ -23,48 +23,64 @@
interface Liker
{
/**
* Add a like for the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*/
public function like(Likeable $likeable);

/**
* Add a dislike for the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*/
public function unlike(Likeable $likeable);
public function dislike(Likeable $likeable);

/**
* Remove a like from the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*/
public function dislike(Likeable $likeable);
public function unlike(Likeable $likeable);

/**
* Remove a dislike from the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*/
public function undislike(Likeable $likeable);

/**
* Toggle like of the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*/
public function toggleLike(Likeable $likeable);

/**
* Toggle dislike of the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*/
public function toggleDislike(Likeable $likeable);

/**
* Determine if Liker has liked Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return bool
*/
public function hasLiked(Likeable $likeable): bool;

/**
* Determine if Liker has disliked Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return bool
*/
49 changes: 22 additions & 27 deletions src/Liker/Models/Traits/Liker.php
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
trait Liker
{
/**
* Add a like for model by the given user.
* Add a like for the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
@@ -36,78 +36,73 @@ public function like(LikeableContract $likeable)
}

/**
* Remove a like from this record for the given user.
* Add a dislike for the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*
*/
public function unlike(LikeableContract $likeable)
public function dislike(LikeableContract $likeable)
{
app(LikeableServiceContract::class)->removeLikeFrom($likeable, LikeType::LIKE, $this);
app(LikeableServiceContract::class)->addLikeTo($likeable, LikeType::DISLIKE, $this);
}

/**
* Toggle like for model by the given user.
* Remove a like from the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*
*/
public function toggleLike(LikeableContract $likeable)
public function unlike(LikeableContract $likeable)
{
app(LikeableServiceContract::class)->toggleLikeOf($likeable, LikeType::LIKE, $this);
app(LikeableServiceContract::class)->removeLikeFrom($likeable, LikeType::LIKE, $this);
}

/**
* Has the user already liked likeable model.
* Remove a dislike from the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return bool
* @return void
*/
public function hasLiked(LikeableContract $likeable): bool
public function undislike(LikeableContract $likeable)
{
return app(LikeableServiceContract::class)->isLiked($likeable, LikeType::LIKE, $this);
app(LikeableServiceContract::class)->removeLikeFrom($likeable, LikeType::DISLIKE, $this);
}

/**
* Add a dislike for model by the given user.
* Toggle like of the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*
*/
public function dislike(LikeableContract $likeable)
public function toggleLike(LikeableContract $likeable)
{
app(LikeableServiceContract::class)->addLikeTo($likeable, LikeType::DISLIKE, $this);
app(LikeableServiceContract::class)->toggleLikeOf($likeable, LikeType::LIKE, $this);
}

/**
* Remove a dislike from this record for the given user.
* Toggle dislike of the Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*
*/
public function undislike(LikeableContract $likeable)
public function toggleDislike(LikeableContract $likeable)
{
app(LikeableServiceContract::class)->removeLikeFrom($likeable, LikeType::DISLIKE, $this);
app(LikeableServiceContract::class)->toggleLikeOf($likeable, LikeType::DISLIKE, $this);
}

/**
* Toggle dislike for model by the given user.
* Determine if Liker has liked Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return void
*
* @return bool
*/
public function toggleDislike(LikeableContract $likeable)
public function hasLiked(LikeableContract $likeable): bool
{
app(LikeableServiceContract::class)->toggleLikeOf($likeable, LikeType::DISLIKE, $this);
return app(LikeableServiceContract::class)->isLiked($likeable, LikeType::LIKE, $this);
}

/**
* Has the user already disliked likeable model.
* Determine if Liker has disliked Likeable model.
*
* @param \Cog\Contracts\Love\Likeable\Models\Likeable $likeable
* @return bool