forked from kookmin-sw/cap-template
-
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.
- Loading branch information
Showing
39 changed files
with
472 additions
and
74 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
43 changes: 43 additions & 0 deletions
43
back/src/main/generated/com/example/capstone/domain/like/entity/QLike.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,43 @@ | ||
package com.example.capstone.domain.like.entity; | ||
|
||
import static com.querydsl.core.types.PathMetadataFactory.*; | ||
|
||
import com.querydsl.core.types.dsl.*; | ||
|
||
import com.querydsl.core.types.PathMetadata; | ||
import javax.annotation.processing.Generated; | ||
import com.querydsl.core.types.Path; | ||
|
||
|
||
/** | ||
* QLike is a Querydsl query type for Like | ||
*/ | ||
@Generated("com.querydsl.codegen.DefaultEntitySerializer") | ||
public class QLike extends EntityPathBase<Like> { | ||
|
||
private static final long serialVersionUID = -1705593941L; | ||
|
||
public static final QLike like = new QLike("like1"); | ||
|
||
public final NumberPath<Long> answerId = createNumber("answerId", Long.class); | ||
|
||
public final NumberPath<Long> id = createNumber("id", Long.class); | ||
|
||
public final BooleanPath isClick = createBoolean("isClick"); | ||
|
||
public final StringPath uuid = createString("uuid"); | ||
|
||
public QLike(String variable) { | ||
super(Like.class, forVariable(variable)); | ||
} | ||
|
||
public QLike(Path<? extends Like> path) { | ||
super(path.getType(), path.getMetadata()); | ||
} | ||
|
||
public QLike(PathMetadata metadata) { | ||
super(Like.class, metadata); | ||
} | ||
|
||
} | ||
|
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
9 changes: 9 additions & 0 deletions
9
back/src/main/java/com/example/capstone/domain/help/exception/HelpNotFoundException.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 com.example.capstone.domain.help.exception; | ||
|
||
import com.example.capstone.global.error.exception.EntityNotFoundException; | ||
|
||
public class HelpNotFoundException extends EntityNotFoundException { | ||
public HelpNotFoundException(Long id) { | ||
super(id + " is not found help"); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
back/src/main/java/com/example/capstone/domain/like/entity/Like.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,32 @@ | ||
package com.example.capstone.domain.like.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Table(name = "likes") | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Like { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@Column(name = "uuid", nullable = false) | ||
private String uuid; | ||
|
||
@Column(name = "answer_id", nullable = false) | ||
private Long answerId; | ||
|
||
@Column(name = "is_click", nullable = false) | ||
private Boolean isClick; | ||
|
||
public void updateClick(Boolean isClick) { | ||
this.isClick = isClick; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
back/src/main/java/com/example/capstone/domain/like/repository/LikeCustomRepository.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,12 @@ | ||
package com.example.capstone.domain.like.repository; | ||
|
||
import com.example.capstone.domain.like.entity.Like; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface LikeCustomRepository { | ||
Optional<Like> findByAnswerIdAndUuid(Long answerId, String uuid); | ||
|
||
void deleteByAnswerIdAndUuid(Long answerId, String uuid); | ||
} |
10 changes: 10 additions & 0 deletions
10
back/src/main/java/com/example/capstone/domain/like/repository/LikeRepository.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,10 @@ | ||
package com.example.capstone.domain.like.repository; | ||
|
||
import com.example.capstone.domain.like.entity.Like; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface LikeRepository extends JpaRepository<Like, Long>, LikeCustomRepository { | ||
Like save(Like like); | ||
} |
33 changes: 33 additions & 0 deletions
33
back/src/main/java/com/example/capstone/domain/like/repository/LikeRepositoryImpl.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,33 @@ | ||
package com.example.capstone.domain.like.repository; | ||
|
||
import com.example.capstone.domain.like.entity.QLike; | ||
import com.example.capstone.domain.like.entity.Like; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
public class LikeRepositoryImpl implements LikeCustomRepository { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
private final QLike like = QLike.like; | ||
|
||
@Override | ||
public Optional<Like> findByAnswerIdAndUuid(Long answerId, String uuid) { | ||
return Optional.ofNullable(jpaQueryFactory | ||
.selectFrom(like) | ||
.where(like.answerId.eq(answerId), | ||
like.uuid.eq(uuid)) | ||
.fetchOne()); | ||
} | ||
|
||
@Override | ||
public void deleteByAnswerIdAndUuid(Long answerId, String uuid) { | ||
jpaQueryFactory | ||
.delete(like) | ||
.where(like.answerId.eq(answerId), | ||
like.uuid.eq(uuid)) | ||
.execute(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
back/src/main/java/com/example/capstone/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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.capstone.domain.like.service; | ||
|
||
import com.example.capstone.domain.like.entity.Like; | ||
import com.example.capstone.domain.like.repository.LikeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LikeService { | ||
private final LikeRepository likeRepository; | ||
|
||
@Transactional | ||
public void likeAnswer(String userId, Long answerId) { | ||
likeRepository.findByAnswerIdAndUuid(answerId, userId).ifPresentOrElse( | ||
l -> { | ||
l.updateClick(true); | ||
}, () -> { | ||
likeRepository.save(Like.builder().uuid(userId).answerId(answerId).isClick(true).build()); | ||
}); | ||
} | ||
|
||
@Transactional | ||
public void unlikeAnswer(String userId, Long answerId) { | ||
likeRepository.findByAnswerIdAndUuid(answerId, userId).ifPresent( | ||
l -> { | ||
l.updateClick(false); | ||
}); | ||
} | ||
|
||
} |
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.