Skip to content

Commit

Permalink
KKUMI-113 [FEATURE] #66 mongoDB 설정 추가, PostView 추가
Browse files Browse the repository at this point in the history
mongoDB 설정, repository 추가
mongoDB의 document와 연결할 PostView 추가
  • Loading branch information
eekrwl committed Oct 2, 2024
1 parent aa32701 commit cda07df
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@EnableJpaAuditing
@SpringBootApplication
@EnableMongoRepositories(basePackages = "com.swmarastro.mykkumiserver")
public class MykkumiServerApplication {
public static void main(String[] args) {
SpringApplication.run(MykkumiServerApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.swmarastro.mykkumiserver.post;

import com.swmarastro.mykkumiserver.post.domain.PostView;
import org.springframework.data.mongodb.repository.MongoRepository;

public interface PostMongoRepository extends MongoRepository<PostView, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.swmarastro.mykkumiserver.post.domain;

import com.swmarastro.mykkumiserver.category.domain.Category;
import com.swmarastro.mykkumiserver.post.dto.PostImageDto;
import com.swmarastro.mykkumiserver.post.richtext.PostContentObject;
import com.swmarastro.mykkumiserver.user.User;
import com.swmarastro.mykkumiserver.post.dto.Writer;
import jakarta.persistence.Id;
import lombok.*;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@Getter
@Builder
@Document(collection="postview")
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class PostView {

@Id
private Long id;
private String category;
private String subCategory;
private Writer writer;
private List<PostContentObject> content;
private List<PostImageDto> images;

public static PostView of(Post post, Category category, User writer, List<PostImageDto> images) {
Writer postWriter = Writer.builder()
.uuid(writer.getUuid().toString())
.profileImage(writer.getProfileImage())
.nickname(writer.getNickname())
.build();

return PostView.builder()
.id(post.getId())
.category(category.getName())
.subCategory(post.getSubCategory().getName())
.writer(postWriter)
.content(post.getContent())
.images(images)
.build();
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/swmarastro/mykkumiserver/post/dto/Writer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.swmarastro.mykkumiserver.post.dto;

import com.swmarastro.mykkumiserver.user.User;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class Writer {
private String uuid;
private String profileImage;
private String nickname;

static public Writer of(User user) {
return Writer.builder()
.uuid(user.getUuid().toString())
.profileImage(user.getProfileImage())
.nickname(user.getNickname())
.build();
}
}
7 changes: 7 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring:
config:
import:
- 'aws-secretsmanager:local/mykkumi/mysql'
- 'aws-secretsmanager:dev/mykkumi/s3'
- 'aws-secretsmanager:dev/mykkumi/jwt'
- 'aws-secretsmanager:dev/mykkumi/oauth'
6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ spring:
username: ${db_username}
password: ${db_password}

data:
mongodb:
uri: ${mongodb_uri}

jpa:
hibernate:
ddl-auto: update
ddl-auto: validate
show-sql: true
properties:
hibernate:
Expand Down

0 comments on commit cda07df

Please sign in to comment.