-
Notifications
You must be signed in to change notification settings - Fork 0
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 #91 from tukcomCD2024/feat#90/get-member
- Loading branch information
Showing
51 changed files
with
877 additions
and
690 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
50 changes: 0 additions & 50 deletions
50
backend/memetory/src/main/java/com/example/memetory/domain/like/controller/LikeApi.java
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
...nd/memetory/src/main/java/com/example/memetory/domain/like/controller/LikeController.java
This file was deleted.
Oops, something went wrong.
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
11 changes: 11 additions & 0 deletions
11
...tory/src/main/java/com/example/memetory/domain/like/exception/NotCreateLikeException.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,11 @@ | ||
package com.example.memetory.domain.like.exception; | ||
|
||
import com.example.memetory.global.exception.BusinessException; | ||
import com.example.memetory.global.response.ErrorCode; | ||
|
||
public class NotCreateLikeException extends BusinessException { | ||
|
||
public NotCreateLikeException() { | ||
super(ErrorCode.LIKE_NOT_CREATE); | ||
} | ||
} |
64 changes: 37 additions & 27 deletions
64
backend/memetory/src/main/java/com/example/memetory/domain/like/service/LikeService.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 |
---|---|---|
@@ -1,43 +1,53 @@ | ||
package com.example.memetory.domain.like.service; | ||
|
||
import org.springframework.dao.DataIntegrityViolationException; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.example.memetory.domain.like.dto.LikeServiceDto; | ||
import com.example.memetory.domain.like.entity.Like; | ||
import com.example.memetory.domain.like.exception.NotCreateLikeException; | ||
import com.example.memetory.domain.like.exception.NotFoundLikeException; | ||
import com.example.memetory.domain.like.repository.LikeRepository; | ||
import com.example.memetory.domain.member.entity.Member; | ||
import com.example.memetory.domain.member.service.MemberService; | ||
import com.example.memetory.domain.memes.entity.Memes; | ||
import com.example.memetory.domain.memes.service.MemesService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LikeService { | ||
|
||
private final MemberService memberService; | ||
private final MemesService memesService; | ||
private final LikeRepository likeRepository; | ||
|
||
@Transactional | ||
public void register(LikeServiceDto likeServiceDto) { | ||
Member member = memberService.findByEmail(likeServiceDto.getEmail()); | ||
Memes memes = memesService.getMemesBetweenService(likeServiceDto.getMemesId()); | ||
memes.addLikeCount(); | ||
|
||
Like newLike = likeServiceDto.toEntity(member, memes); | ||
likeRepository.save(newLike); | ||
} | ||
|
||
@Transactional | ||
public void cancel(LikeServiceDto likeServiceDto) { | ||
Member member = memberService.findByEmail(likeServiceDto.getEmail()); | ||
Memes memes = memesService.getMemesBetweenService(likeServiceDto.getMemesId()); | ||
memes.cancelLikeCount(); | ||
|
||
Like like = likeRepository.findLikeByMemberAndMemes(member, memes).orElseThrow(NotFoundLikeException::new); | ||
|
||
likeRepository.delete(like); | ||
} | ||
private final MemberService memberService; | ||
private final MemesService memesService; | ||
private final LikeRepository likeRepository; | ||
|
||
@Transactional | ||
public void registerLike(LikeServiceDto likeServiceDto) { | ||
Member member = memberService.findMemberFromEmail(likeServiceDto.getEmail()); | ||
Memes memes = memesService.findMemesFromMemesId(likeServiceDto.getMemesId()); | ||
|
||
Like newLike = likeServiceDto.toEntityFromMemberAndMemes(member, memes); | ||
saveLike(newLike); | ||
memes.addLikeCount(); | ||
} | ||
|
||
private void saveLike(Like like) { | ||
try { | ||
likeRepository.save(like); | ||
} catch (DataIntegrityViolationException e) { | ||
throw new NotCreateLikeException(); | ||
} | ||
} | ||
|
||
@Transactional | ||
public void cancelLike(LikeServiceDto likeServiceDto) { | ||
Member member = memberService.findMemberFromEmail(likeServiceDto.getEmail()); | ||
Memes memes = memesService.findMemesFromMemesId(likeServiceDto.getMemesId()); | ||
Like like = likeRepository.findLikeByMemberAndMemes(member, memes).orElseThrow(NotFoundLikeException::new); | ||
|
||
likeRepository.delete(like); | ||
memes.cancelLikeCount(); | ||
} | ||
} |
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
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
Oops, something went wrong.