Skip to content

Commit 0ec00c1

Browse files
committed
feat(review): 리뷰 엔티티 레포지토리 생성
1 parent 34fd953 commit 0ec00c1

File tree

6 files changed

+118
-27
lines changed

6 files changed

+118
-27
lines changed

src/main/java/com/somemore/domains/Review.java

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.somemore.review.domain;
2+
3+
import static jakarta.persistence.GenerationType.IDENTITY;
4+
import static lombok.AccessLevel.PROTECTED;
5+
6+
import com.somemore.global.common.BaseEntity;
7+
import jakarta.persistence.Column;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
import jakarta.persistence.Lob;
12+
import jakarta.persistence.Table;
13+
import java.util.UUID;
14+
import lombok.Builder;
15+
import lombok.Getter;
16+
import lombok.NoArgsConstructor;
17+
18+
@Getter
19+
@NoArgsConstructor(access = PROTECTED)
20+
@Entity
21+
@Table(name = "review")
22+
public class Review extends BaseEntity {
23+
24+
@Id
25+
@GeneratedValue(strategy = IDENTITY)
26+
private Long id;
27+
28+
@Column(name = "volunteer_apply_id", nullable = false)
29+
private Long volunteerApplyId;
30+
31+
@Column(name = "volunteer_id", nullable = false, length = 16)
32+
private UUID volunteerId;
33+
34+
@Column(name = "title", nullable = false)
35+
private String title;
36+
37+
@Lob
38+
@Column(name = "content", nullable = false)
39+
private String content;
40+
41+
@Column(name = "img_url", nullable = false)
42+
private String imgUrl;
43+
44+
@Builder
45+
public Review(Long volunteerApplyId, UUID volunteerId, String title,
46+
String content, String imgUrl) {
47+
this.volunteerApplyId = volunteerApplyId;
48+
this.volunteerId = volunteerId;
49+
this.title = title;
50+
this.content = content;
51+
this.imgUrl = imgUrl;
52+
}
53+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.somemore.review.repository;
2+
3+
import com.somemore.review.domain.Review;
4+
import java.util.Optional;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.data.jpa.repository.Query;
7+
8+
public interface ReviewJpaRepository extends JpaRepository<Review, Long> {
9+
10+
Optional<Review> findByIdAndDeletedFalse(Long id);
11+
12+
@Query("SELECT COUNT(r) > 0 FROM Review r WHERE r.volunteerApplyId = :volunteerId AND r.deleted = false")
13+
boolean existsByVolunteerApplyId(Long volunteerId);
14+
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.somemore.review.repository;
2+
3+
import com.somemore.review.domain.Review;
4+
import java.util.Optional;
5+
6+
public interface ReviewRepository {
7+
8+
Review save(Review review);
9+
10+
Optional<Review> findById(Long id);
11+
12+
boolean existsByVolunteerApplyId(Long volunteerApplyId);
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.somemore.review.repository;
2+
3+
import com.querydsl.jpa.impl.JPAQueryFactory;
4+
import com.somemore.review.domain.Review;
5+
import java.util.Optional;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.stereotype.Repository;
8+
9+
@RequiredArgsConstructor
10+
@Repository
11+
public class ReviewRepositoryImpl implements ReviewRepository {
12+
13+
private final ReviewJpaRepository reviewJpaRepository;
14+
private final JPAQueryFactory queryFactory;
15+
16+
@Override
17+
public Review save(Review review) {
18+
return reviewJpaRepository.save(review);
19+
}
20+
21+
@Override
22+
public Optional<Review> findById(Long id) {
23+
return reviewJpaRepository.findByIdAndDeletedFalse(id);
24+
}
25+
26+
@Override
27+
public boolean existsByVolunteerApplyId(Long volunteerApplyId) {
28+
return reviewJpaRepository.existsByVolunteerApplyId(volunteerApplyId);
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.somemore.volunteerapply.domain;
2+
3+
public enum ApplyStatus {
4+
WAITING,
5+
APPROVED,
6+
REJECTED,
7+
}

0 commit comments

Comments
 (0)