Skip to content

Commit

Permalink
[ADD] 프로젝트 폴더링 및 엔티티 코드 추가 #4
Browse files Browse the repository at this point in the history
[ADD] 프로젝트 폴더링 및 엔티티 코드 추가 #4
  • Loading branch information
kimchaeeun3447 authored Oct 23, 2023
2 parents fd2583b + ceb9667 commit b321848
Show file tree
Hide file tree
Showing 23 changed files with 389 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mument/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

### Q Class ###
/src/main/generated/
32 changes: 32 additions & 0 deletions mument/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.querydsl:querydsl-jpa'
implementation 'com.querydsl:querydsl-apt'

compileOnly 'org.projectlombok:lombok'

developmentOnly 'org.springframework.boot:spring-boot-devtools'

runtimeOnly 'com.mysql:mysql-connector-j'

annotationProcessor 'org.projectlombok:lombok'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa"
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation("org.junit.vintage:junit-vintage-engine") {
Expand All @@ -38,4 +48,26 @@ tasks.named('test') {
useJUnitPlatform()
}

// Querydsl
def querydslSrcDir = 'src/main/generated'
sourceSets {
main {
java {
srcDirs += [ querydslSrcDir ]
}
}
}

compileJava {
options.compilerArgs << '-Aquerydsl.generatedAnnotationClass=javax.annotation.Generated'
}

tasks.withType(JavaCompile) {
options.generatedSourceOutputDirectory = file(querydslSrcDir)
}

clean {
delete file(querydslSrcDir)
}


19 changes: 19 additions & 0 deletions mument/src/main/java/com/mument/mument/config/QuerydslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mument.mument.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Configuration
public class QuerydslConfig {
@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mument.mument.core.common.domain;

import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;

@EntityListeners(value = {AuditingEntityListener.class})
@MappedSuperclass
@Getter
public abstract class BaseDate {

@CreatedDate
@Column(updatable = false)
private LocalDateTime createdAt;

// @LastModifiedDate
// private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mument.mument.core.mument.controller;

import com.mument.mument.core.mument.service.MumentService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mument")
@AllArgsConstructor
public class MumentController {

private final MumentService mumentService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mument.mument.core.mument.domain;

import com.mument.mument.core.common.domain.BaseDate;
import com.mument.mument.core.mument.domain.Mument;
import com.mument.mument.core.user.domain.User;
import lombok.Getter;

import javax.persistence.*;

@Entity
@Getter
public class Like extends BaseDate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mument_id", nullable = false)
private Mument mument;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mument.mument.core.mument.domain;

import com.mument.mument.core.common.domain.BaseDate;
import com.mument.mument.core.user.domain.User;
import com.mument.mument.core.music.domain.Music;
import lombok.Getter;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Getter
public class Mument extends BaseDate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "music_id", nullable = false)
private Music music;

@Column(length = 1000)
private String content;

@Column(nullable = false, name = "is_first")
private boolean is_first;

@Column(nullable = false)
private int likeCount;

@Column(nullable = false, name = "is_deleted")
private boolean is_deleted;

@Column(nullable = false, name = "is_private")
private boolean is_private;

private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mument.mument.core.mument.domain;

import com.mument.mument.core.common.domain.BaseDate;
import lombok.Getter;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Getter
public class MumentTag extends BaseDate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mument_id", nullable = false)
private Mument mument;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tag_id", nullable = false)
private Tag tag;

@Column(nullable = false, name = "is_deleted")
private boolean is_deleted;

private LocalDateTime updatedAt;
}
19 changes: 19 additions & 0 deletions mument/src/main/java/com/mument/mument/core/mument/domain/Tag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mument.mument.core.mument.domain;

import lombok.Getter;

import javax.persistence.*;

@Entity
@Getter
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private int tagSort;

@Column(length = 20)
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mument.mument.core.mument.repository;

import com.mument.mument.core.mument.domain.Mument;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MumentRepository extends JpaRepository<Mument, Long>, MumentRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mument.mument.core.mument.repository;

public interface MumentRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mument.mument.core.mument.repository;

import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class MumentRepositoryImpl implements MumentRepositoryCustom {

private final JPAQueryFactory queryFactory;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mument.mument.core.mument.service;

public interface MumentService {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mument.mument.core.mument.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@RequiredArgsConstructor
@Slf4j
@Service
public class MumentServiceImpl implements MumentService {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mument.mument.core.music.domain;

import lombok.Getter;

import javax.persistence.*;

@Entity
@Getter
public class Music {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String artist;

@Column(nullable = false)
private String image;

@Column(nullable = false)
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mument.mument.core.user.controller;

import com.mument.mument.core.user.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class UserController {

private final UserService userService;
}
23 changes: 23 additions & 0 deletions mument/src/main/java/com/mument/mument/core/user/domain/Block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mument.mument.core.user.domain;

import com.mument.mument.core.common.domain.BaseDate;
import com.mument.mument.core.user.domain.User;
import lombok.Getter;

import javax.persistence.*;

@Entity
@Getter
public class Block extends BaseDate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "blocked_user_id", nullable = false)
private User blockedUser;
}
44 changes: 44 additions & 0 deletions mument/src/main/java/com/mument/mument/core/user/domain/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.mument.mument.core.user.domain;

import com.mument.mument.core.common.domain.BaseDate;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class User extends BaseDate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(length = 10)
private String provider;

@Column(length = 50)
private String profileId;

private String refreshToken;

private String image;

private LocalDateTime updatedAt;

private String authenticationCode;

private String gender;

private String ageRange;

private String email;

@Column(nullable = false, name = "is_deleted")
private boolean is_deleted;

private String fcmToken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mument.mument.core.user.repository;

import com.mument.mument.core.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Long>, UserRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.mument.mument.core.user.repository;

// QueryDSL 로 custom 해서 사용할 메소드 선언
public interface UserRepositoryCustom {
}
Loading

0 comments on commit b321848

Please sign in to comment.