-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GETP-168 refactor: 프로젝트 좋아요 / 좋아요 취소 서비스를 추상화에 대한 구현체로 변경
- Loading branch information
Showing
30 changed files
with
213 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/es/princip/getp/domain/like/command/domain/project/ProjectLike.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package es.princip.getp.domain.like.command.domain.project; | ||
|
||
import es.princip.getp.domain.like.command.domain.Like; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@DiscriminatorColumn | ||
@Table(name = "project_like") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) | ||
@AttributeOverrides( | ||
{ | ||
@AttributeOverride(name = "id", column = @Column(name = "project_like_id")), | ||
@AttributeOverride(name = "likerId", column = @Column(name = "people_id")), | ||
@AttributeOverride(name = "likedId", column = @Column(name = "project_id")) | ||
} | ||
) | ||
public class ProjectLike extends Like { | ||
|
||
private ProjectLike(final Long peopleId, final Long projectId) { | ||
super(peopleId, projectId); | ||
} | ||
|
||
public static ProjectLike of(final Long peopleId, final Long projectId) { | ||
return new ProjectLike(peopleId, projectId); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/es/princip/getp/domain/like/command/domain/project/ProjectLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package es.princip.getp.domain.like.command.domain.project; | ||
|
||
import es.princip.getp.domain.like.command.domain.LikeRepository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProjectLikeRepository extends JpaRepository<ProjectLike, Long>, LikeRepository { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/es/princip/getp/domain/like/command/domain/project/ProjectLiker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package es.princip.getp.domain.like.command.domain.project; | ||
|
||
import es.princip.getp.domain.like.command.domain.LikeReceivable; | ||
import es.princip.getp.domain.like.command.domain.Likeable; | ||
import es.princip.getp.domain.like.command.domain.Liker; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProjectLiker extends Liker<ProjectLike> { | ||
|
||
private final ProjectLikeRepository projectLikeRepository; | ||
|
||
@Autowired | ||
public ProjectLiker(ProjectLikeRepository projectLikeRepository) { | ||
super(projectLikeRepository); | ||
this.projectLikeRepository = projectLikeRepository; | ||
} | ||
|
||
@Override | ||
public ProjectLike like(final Likeable likeable, final LikeReceivable likeReceivable) { | ||
checkAlreadyLiked(likeable.getId(), likeReceivable.getId()); | ||
final ProjectLike like = ProjectLike.of(likeable.getId(), likeReceivable.getId()); | ||
projectLikeRepository.save(like); | ||
return like; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/es/princip/getp/domain/like/command/domain/project/ProjectUnliker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package es.princip.getp.domain.like.command.domain.project; | ||
|
||
import es.princip.getp.domain.like.command.domain.Unliker; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProjectUnliker extends Unliker { | ||
|
||
@Autowired | ||
public ProjectUnliker(ProjectLikeRepository projectLikeRepository) { | ||
super(projectLikeRepository); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...d/presentation/ProjectLikeController.java → ...d/presentation/ProjectLikeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/es/princip/getp/domain/like/query/dao/ProjectLikeDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package es.princip.getp.domain.like.query.dao; | ||
|
||
public interface ProjectLikeDao extends LikeDao { | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/es/princip/getp/domain/like/query/dao/ProjectLikeQueryDslDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package es.princip.getp.domain.like.query.dao; | ||
|
||
import es.princip.getp.infra.support.QueryDslSupport; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static es.princip.getp.domain.like.command.domain.project.QProjectLike.projectLike; | ||
import static java.util.stream.Collectors.toMap; | ||
|
||
@Repository | ||
public class ProjectLikeQueryDslDao extends QueryDslSupport implements ProjectLikeDao { | ||
|
||
@Override | ||
// TODO: 좋아요 수 조회 성능 개선 필요 | ||
public Long countByLikedId(final Long projectId) { | ||
return queryFactory.select(projectLike.count()) | ||
.from(projectLike) | ||
.where(projectLike.likedId.eq(projectId)) | ||
.fetchOne(); | ||
} | ||
|
||
@Override | ||
public Map<Long, Long> countByLikedIds(final Long... likedIds) { | ||
return queryFactory.select(projectLike.likedId, projectLike.count()) | ||
.from(projectLike) | ||
.where(projectLike.likedId.in(likedIds)) | ||
.groupBy(projectLike.likedId) | ||
.fetch() | ||
.stream() | ||
.collect( | ||
toMap( | ||
tuple -> tuple.get(projectLike.likedId), | ||
tuple -> Optional.ofNullable(tuple.get(projectLike.count())) | ||
.orElse(0L) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
src/main/java/es/princip/getp/domain/project/command/domain/ProjectLike.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/es/princip/getp/domain/project/command/domain/ProjectLikeRepository.java
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
src/main/java/es/princip/getp/domain/project/command/domain/ProjectLiker.java
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
src/main/java/es/princip/getp/domain/project/command/domain/ProjectUnliker.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.