Skip to content

Commit

Permalink
Merge pull request #45 from KNU-HAEDAL/issue/17
Browse files Browse the repository at this point in the history
Issue/17 DB DDL 수정
  • Loading branch information
bayy1216 authored Jul 17, 2024
2 parents 8e74657 + 6dfa83a commit 42bdc15
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ public class ChallengeGroup extends BaseTimeEntity {
private Long id;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private ChallengeCategory category;

@Column(nullable = false)
private String title;

@Column(nullable = false)
private String content;

@Column(nullable = false)
private String guide;

@Column(nullable = false)
private Integer cumulativeCount;

@OneToMany(mappedBy = "challengeGroup", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package org.haedal.zzansuni.domain.challengegroup.challenge;

import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;

import java.time.LocalDate;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -31,23 +24,30 @@ public class Challenge extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "challenge_group_id")
private ChallengeGroup challengeGroup;

@Column(nullable = false)
private Integer requiredCount;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private DayType dayType;

@Column(nullable = false)
private Integer onceExp;

@Column(nullable = false)
private Integer successExp;

@Column(nullable = false)
private Integer difficulty;

@Column(nullable = false)
private LocalDate startDate;

@Column(nullable = false)
private LocalDate endDate;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package org.haedal.zzansuni.domain.challengegroup.image;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -26,10 +20,11 @@ public class ChallengeGroupImage extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String imageUrl;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "challenge_group_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "challenge_group_id", nullable = false)
private ChallengeGroup challengeGroup;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package org.haedal.zzansuni.domain.challengegroup.review;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -27,15 +21,18 @@ public class ChallengeReview extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_challenge_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_challenge_id", nullable = false)
private UserChallenge userChallenge;

@Column(nullable = false)
private String content;

@Column(nullable = false)
private Integer rating;

// 쿼리 성능을 위해 비정규화
@Column(nullable = false)
private Long challengeGroupId;

public static ChallengeReview create(UserChallenge userChallenge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,30 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
@Table(
uniqueConstraints = {
@UniqueConstraint(
name = "user_challenge_unique",
columnNames = {"challenge_id", "user_id"}
)
}
)
public class UserChallenge extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "challenge_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "challenge_id", nullable = false)
private Challenge challenge;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private ChallengeStatus status;

@OneToMany(mappedBy = "userChallenge", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Table(
uniqueConstraints = {
@UniqueConstraint(
name = "challenge_group_user_exp_unique",
columnNames = {"challenge_group_id", "user_id"}
)
}
)
public class ChallengeGroupUserExp {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "challenge_group_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "challenge_group_id", nullable = false)
private ChallengeGroup challengeGroup;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Column(nullable = false)
private Integer totalExp;

public static ChallengeGroupUserExp create(ChallengeGroup challengeGroup, User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ public class ChallengeVerification extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_challenge_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_challenge_id", nullable = false)
private UserChallenge userChallenge;

private String imageUrl;

@Column(nullable = false)
private String content;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private ChallengeVerificationStatus status;

public static ChallengeVerification create(ChallengeCommand.VerificationCreate command, UserChallenge userChallenge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class User extends BaseTimeEntity {
@Column(nullable = false)
private Role role;

@Column(unique = true)
private String email;

private String password;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.haedal.zzansuni.global.api;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand All @@ -10,12 +8,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@OpenAPIDefinition(
servers = {
@Server(url = "https://api.reditus.site",description = "Prod Server"),
@Server(url = "http://localhost:8080", description = "localhost"),
}
)
@Configuration
public class SwaggerConfig {
private static final String BEARER_KEY = "bearer-key";
Expand Down
4 changes: 2 additions & 2 deletions zzansuni-api-server/app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spring:
h2.console.enabled: false
flyway:
enabled: true
baseline-on-migrate: true # Flyway가 초기화되지 않은 데이터베이스에 마이그레이션을 적용할 때 초기 버전으로 마이그레이션 파일을 적용할지 여부
baseline-on-migrate: false # Flyway가 초기화되지 않은 데이터베이스에 마이그레이션을 적용할 때 초기 버전으로 마이그레이션 파일을 적용할지 여부
fail-on-missing-locations: true # 스크립트 파일을 저장하는 위치를 못 찾을때 실패할지 여부
baseline-version: 1 # Flyway가 초기화되지 않은 데이터베이스에 마이그레이션을 적용할 때 버전을 설정
kakao:
Expand All @@ -70,7 +70,7 @@ spring: # dev profile
activate:
on-profile: dev
datasource:
url: jdbc:mysql://localhost:3306/zzansuni
url: jdbc:mysql://localhost:3306/zzansuni?createDatabaseIfNotExist=true
username: "root"
password: "root"
jpa:
Expand Down
Loading

0 comments on commit 42bdc15

Please sign in to comment.