-
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.
- Loading branch information
1 parent
07ae285
commit d890a8b
Showing
30 changed files
with
920 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.odiga.fiesta.badge.domain; | ||
|
||
import static jakarta.persistence.GenerationType.*; | ||
import static lombok.AccessLevel.*; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Index; | ||
import jakarta.persistence.Table; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Entity | ||
@AllArgsConstructor | ||
@Getter | ||
@SuperBuilder | ||
@NoArgsConstructor(access = PROTECTED) | ||
@ToString | ||
@Table(name = "badge", indexes = { | ||
@Index(name = "idx_badge_type", columnList = "type") | ||
}) | ||
public class Badge { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "badge_id") | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@Column(nullable = false) | ||
private String description; | ||
|
||
@Column(name = "image_url", nullable = false) | ||
private String imageUrl; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "type", nullable = false) | ||
private BadgeType type; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/odiga/fiesta/badge/domain/BadgeConstants.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,29 @@ | ||
package com.odiga.fiesta.badge.domain; | ||
|
||
import static lombok.AccessLevel.*; | ||
|
||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = PRIVATE) | ||
public class BadgeConstants { | ||
|
||
public static final Long USER_JOIN_BADGE_ID = 1L; | ||
|
||
// 리뷰 작성 관련 뱃지 | ||
public static final Long FIRST_REVIEW_BADGE_ID = 2L; | ||
public static final Long PASSIONATE_REVIEWER_BADGE_ID = 4L; | ||
public static final Long HISTORY_LOVER_BADGE_ID = 5L; | ||
public static final Long MUSIC_LOVER_BADGE_ID = 6L; | ||
public static final Long ACTIVITY_BADGE_ID = 7L; | ||
public static final Long FOODIE_LOVER_BADGE_ID = 8L; | ||
public static final Long MOVIE_LOVER_BADGE_ID = 9L; | ||
public static final Long FIREWORKS_LOVER_BADGE_ID = 10L; | ||
public static final Long NATURE_LOVER_BADGE_ID = 11L; | ||
public static final Long NIGHT_LOVER_BADGE_ID = 12L; | ||
public static final Long ART_LOVER_BADGE_ID = 13L; | ||
public static final Long CULTURE_LOVER_BADGE_ID = 14L; | ||
public static final Long UNIQUE_LOVER_BADGE_ID = 15L; | ||
|
||
// 페스티벌 등록 관련 뱃지 | ||
public static final Long FIRST_FESTIVAL_BADGE_ID = 3L; | ||
} |
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,6 @@ | ||
package com.odiga.fiesta.badge.domain; | ||
|
||
public enum BadgeType { | ||
|
||
USER, REVIEW, FESTIVAL | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/odiga/fiesta/badge/domain/UserBadge.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 com.odiga.fiesta.badge.domain; | ||
|
||
import static jakarta.persistence.GenerationType.*; | ||
import static lombok.AccessLevel.*; | ||
|
||
import com.odiga.fiesta.common.domain.BaseEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Index; | ||
import jakarta.persistence.Table; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Entity | ||
@Getter | ||
@AllArgsConstructor | ||
@SuperBuilder | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Table(name = "user_badge", indexes = { | ||
@Index(name = "idx_user_badge_user_id", columnList = "user_id"), | ||
@Index(name = "idx_user_badge_badge_id", columnList = "badge_id") | ||
}) | ||
public class UserBadge extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "user_badge_id") | ||
private Long id; | ||
|
||
@Column(name = "badge_id") | ||
private Long badgeId; | ||
|
||
@Column(name = "user_id") | ||
private Long userId; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/odiga/fiesta/badge/repository/BadgeCustomRepository.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.odiga.fiesta.badge.repository; | ||
|
||
import java.util.List; | ||
|
||
import com.odiga.fiesta.user.dto.response.UserBadgeResponse; | ||
|
||
public interface BadgeCustomRepository { | ||
|
||
List<UserBadgeResponse> findUserBadges(Long userId); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/odiga/fiesta/badge/repository/BadgeCustomRepositoryImpl.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,45 @@ | ||
package com.odiga.fiesta.badge.repository; | ||
|
||
import static com.odiga.fiesta.badge.domain.QBadge.*; | ||
import static com.odiga.fiesta.badge.domain.QUserBadge.*; | ||
|
||
import java.util.List; | ||
|
||
import com.odiga.fiesta.user.dto.response.UserBadgeResponse; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.core.types.dsl.CaseBuilder; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class BadgeCustomRepositoryImpl implements BadgeCustomRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<UserBadgeResponse> findUserBadges(Long userId) { | ||
|
||
return queryFactory.select( | ||
Projections.fields( | ||
UserBadgeResponse.class, | ||
badge.id.as("badgeId"), | ||
badge.name.as("badgeName"), | ||
badge.description, | ||
badge.imageUrl, | ||
new CaseBuilder() | ||
.when(userBadge.isNull()) // userBadge가 null이면 false | ||
.then(false) | ||
.when(userBadge.userId.isNull()) | ||
.then(false) | ||
.when(userBadge.userId.eq(userId)) | ||
.then(true) | ||
.otherwise(false).as("isAcquired") | ||
) | ||
) | ||
.from(badge) | ||
.leftJoin(userBadge) | ||
.on(badge.id.eq(userBadge.badgeId)) // 단순 조인 | ||
.fetch(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/odiga/fiesta/badge/repository/BadgeRepository.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,16 @@ | ||
package com.odiga.fiesta.badge.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import com.odiga.fiesta.badge.domain.Badge; | ||
import com.odiga.fiesta.badge.domain.BadgeType; | ||
|
||
public interface BadgeRepository extends JpaRepository<Badge, Long>, BadgeCustomRepository { | ||
|
||
@Query("SELECT b.id FROM Badge b WHERE b.type = :type") | ||
List<Long> findIdsByType(@Param("type") BadgeType type); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/odiga/fiesta/badge/repository/UserBadgeRepository.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,15 @@ | ||
package com.odiga.fiesta.badge.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import com.odiga.fiesta.badge.domain.UserBadge; | ||
|
||
public interface UserBadgeRepository extends JpaRepository<UserBadge, Long> { | ||
|
||
@Query("SELECT ub.badgeId FROM UserBadge ub WHERE ub.userId= :userId AND ub.badgeId IN :badgeIds") | ||
List<Long> findBadgeIdByUserIdAndBadgeIdIn(@Param("userId") Long userId, @Param("badgeIds") List<Long> badgeIds); | ||
} |
Oops, something went wrong.