-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from CSID-DGU/backend/feature/crew
BE: [feat] 갤러리 좋아요 #83
- Loading branch information
Showing
7 changed files
with
144 additions
and
1 deletion.
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
17 changes: 17 additions & 0 deletions
17
...main/java/RunningMachines/R2R/domain/crew/post/gallery/dto/GalleryPreviewResponseDto.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,17 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class GalleryPreviewResponseDto { | ||
private String crewTitle; | ||
private int postCount; | ||
private int memberCount; | ||
private List<GallerySimpleResponseDto> posts; | ||
} |
14 changes: 14 additions & 0 deletions
14
.../main/java/RunningMachines/R2R/domain/crew/post/gallery/dto/GallerySimpleResponseDto.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 RunningMachines.R2R.domain.crew.post.gallery.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class GallerySimpleResponseDto { | ||
private Long postId; | ||
private String imageUrl; | ||
} |
51 changes: 51 additions & 0 deletions
51
...ain/java/RunningMachines/R2R/domain/crew/post/gallery/service/GalleryPostLikeService.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,51 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.service; | ||
|
||
import RunningMachines.R2R.domain.community.post.entity.Post; | ||
import RunningMachines.R2R.domain.community.post.repository.PostRepository; | ||
import RunningMachines.R2R.domain.crew.common.repository.CrewRepository; | ||
import RunningMachines.R2R.domain.crew.post.entity.CrewPost; | ||
import RunningMachines.R2R.domain.crew.post.entity.CrewPostLike; | ||
import RunningMachines.R2R.domain.crew.post.repository.CrewPostLikeRepository; | ||
import RunningMachines.R2R.domain.crew.post.repository.CrewPostRepository; | ||
import RunningMachines.R2R.domain.user.service.AuthCommandService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import RunningMachines.R2R.domain.user.entity.User; | ||
import RunningMachines.R2R.domain.crew.common.entity.Crew; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GalleryPostLikeService { | ||
private final CrewPostRepository crewPostRepository; | ||
private final CrewPostLikeRepository crewPostLikeRepository; | ||
private final CrewRepository crewRepository; | ||
private final AuthCommandService authCommandService; | ||
|
||
@Transactional | ||
public void likeGalleryPost(Long crewId, Long crewPostId) { | ||
User currentUser = authCommandService.getCurrentUser(); | ||
|
||
CrewPost crewPost = crewPostRepository.findById(crewPostId) | ||
.orElseThrow(() -> new IllegalArgumentException("게시글을 찾을 수 없습니다.")); | ||
Crew crew = crewRepository.findById(crewId) | ||
.orElseThrow(() -> new IllegalArgumentException("크루를 찾을 수 없습니다.")); | ||
|
||
boolean isMemberOrLeader = crew.getCrewUsers().stream() | ||
.anyMatch(crewUser -> crewUser.getUser().equals(currentUser)); | ||
if (!isMemberOrLeader) { | ||
throw new IllegalArgumentException("좋아요는 크루 멤버만 누를 수 있습니다."); | ||
} | ||
|
||
boolean alreadyLiked = crewPostLikeRepository.existsByCrewPostAndUser(crewPost, currentUser); | ||
if (alreadyLiked) { | ||
throw new IllegalArgumentException("이미 좋아요를 눌렀습니다."); | ||
} | ||
|
||
CrewPostLike like = CrewPostLike.builder() | ||
.crewPost(crewPost) | ||
.user(currentUser) | ||
.build(); | ||
crewPostLikeRepository.save(like); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...src/main/java/RunningMachines/R2R/domain/crew/post/repository/CrewPostLikeRepository.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 RunningMachines.R2R.domain.crew.post.repository; | ||
|
||
import RunningMachines.R2R.domain.crew.post.entity.CrewPost; | ||
import RunningMachines.R2R.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import RunningMachines.R2R.domain.crew.post.entity.CrewPostLike; | ||
|
||
import java.util.Optional; | ||
|
||
public interface CrewPostLikeRepository extends JpaRepository<CrewPostLike, Integer> { | ||
boolean existsByCrewPostAndUser(CrewPost crewPost, User user); | ||
|
||
Optional<CrewPostLike> findByCrewPostAndUser(CrewPost crewPost, User user); | ||
} |
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