Skip to content

Commit

Permalink
20240405
Browse files Browse the repository at this point in the history
  • Loading branch information
laigasus committed Apr 5, 2024
1 parent 81dbfba commit d3c0f3b
Show file tree
Hide file tree
Showing 56 changed files with 1,709 additions and 495 deletions.
382 changes: 195 additions & 187 deletions app/src/main/resources/data.sql

Large diffs are not rendered by default.

953 changes: 953 additions & 0 deletions app/src/main/resources/data_bak.sql

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/src/main/resources/db/migration/V5__insert_account.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO member (member_id, email, name, picture)
VALUES (UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), '[email protected]', '옥재욱', 'https://lh3.googleusercontent.com/a/ACg8ocJPZpvBzDi_TG3kMCt_eESIh1-GoXIJW9TyktH0e3NkPwg=s96-c');
67 changes: 67 additions & 0 deletions app/src/main/resources/db/migration/V8__insert_dogam.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
SET @time := NOW();

INSERT INTO dogam (member_id, waste_id, created_date)
VALUES (UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1001, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1002, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1003, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1004, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1005, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1006, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1007, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1008, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1009, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1010, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1011, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1012, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1013, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1014, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1015, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1016, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1017, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1018, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1019, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1020, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1021, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1022, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1023, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1024, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1025, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1026, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1027, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1028, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1029, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1030, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1031, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1032, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1033, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1034, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1035, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1036, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1037, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1038, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1039, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1040, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1041, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1042, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1043, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1044, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1045, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1046, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1047, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1048, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1049, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1050, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1051, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1052, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1053, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1054, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1055, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1056, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1057, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1058, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1059, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1060, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1061, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1062, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1063, @time := DATE_ADD(@time, INTERVAL 1 SECOND)),
(UNHEX(REPLACE('4c29cb26-d2f3-38d8-9d02-a9da30c7ad99', '-', '')), 1064, @time := DATE_ADD(@time, INTERVAL 1 SECOND));
2 changes: 1 addition & 1 deletion domain/src/main/java/blisgo/domain/community/Reply.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
public class Reply {
private ReplyId replyId;
private PostId postId;
private Author author;
private String content;
private Author author;
private LocalDateTime createdDate;
private LocalDateTime modifiedDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public enum Category {
CAUTION("주의"),
PRO_FACILITY("전문시설");

final String tag;
private final String tag;
}
6 changes: 4 additions & 2 deletions domain/src/main/java/blisgo/domain/dictionary/vo/DogamId.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package blisgo.domain.dictionary.vo;

import blisgo.domain.member.vo.MemberId;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor(staticName = "of")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder(toBuilder = true)
public class DogamId {
private MemberId memberId;
private WasteId wasteId;
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ plugins {
id 'io.swagger.swaggerhub' version '+'
}

ext {
springCloudVersion = "2023.0.1"
}

bootJar.enabled = false
jar.enabled = true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package blisgo.infrastructure.internal.persistence.base;

import blisgo.infrastructure.internal.InternalRoot;
import blisgo.infrastructure.internal.persistence.common.JpaAuthor;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
Expand All @@ -13,6 +12,8 @@
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.util.UUID;

@Configuration
@EnableJpaAuditing
@EnableJpaRepositories(basePackageClasses = InternalRoot.class)
Expand All @@ -29,7 +30,7 @@ public JPAQueryFactory init() {

@Bean
@Description("도메인 중 회원 정보 데이터가 필요한 경우 OIDC 에서 받아온 회원 정보를 사용하도록 함")
public AuditorAware<JpaAuthor> auditorProvider() {
public AuditorAware<UUID> auditorProvider() {
return new OidcAuditorAware();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ModelMapper modelMapper() {
modelMapper.getConfiguration()
.setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE)
.setFieldMatchingEnabled(true)
.setMatchingStrategy(MatchingStrategies.LOOSE);
.setMatchingStrategy(MatchingStrategies.STANDARD);

return modelMapper;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package blisgo.infrastructure.internal.persistence.base;


import blisgo.infrastructure.internal.persistence.common.JpaAuthor;
import blisgo.infrastructure.internal.persistence.common.JpaPicture;
import blisgo.domain.member.vo.MemberId;
import lombok.NonNull;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
Expand All @@ -11,29 +10,22 @@
import org.springframework.security.oauth2.core.oidc.user.OidcUser;

import java.util.Optional;
import java.util.UUID;

public class OidcAuditorAware implements AuditorAware<JpaAuthor> {
public class OidcAuditorAware implements AuditorAware<UUID> {

@NonNull
@Override
public Optional<JpaAuthor> getCurrentAuditor() {
public Optional<UUID> getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

if (authentication == null || !authentication.isAuthenticated()) {
return Optional.of(JpaAuthor.of(
"[email protected]",
"관리자",
JpaPicture.of("https://res.cloudinary.com/blisgo/image/upload/f_auto,q_auto/v1/manifest/admin")
));
return Optional.of(UUID.randomUUID());
}

OidcUser oidcUser = (OidcUser) authentication.getPrincipal();
OidcUserInfo oidcUserInfo = oidcUser.getUserInfo();

return Optional.of(JpaAuthor.of(
oidcUserInfo.getEmail(),
oidcUserInfo.getFullName(),
JpaPicture.of(oidcUserInfo.getPicture())
));
return Optional.ofNullable(MemberId.of(oidcUserInfo.getEmail()).id());
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package blisgo.infrastructure.internal.persistence.common;

import jakarta.persistence.Embedded;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Transient;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.UUID;

@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -19,7 +22,10 @@
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity extends BaseTimeEntity {

@Embedded
@LastModifiedBy
@Transient
protected JpaAuthor author;

@LastModifiedBy
@Comment("회원 Id")
protected UUID memberId;
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
package blisgo.infrastructure.internal.persistence.common;

import jakarta.persistence.AttributeOverride;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;

@Getter
@Embeddable
@AllArgsConstructor(staticName = "of")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PUBLIC)
public class JpaAuthor {

@Column(name = "author_email")
@Comment("회원 이메일(FK)")
private String email;

@Column(name = "author_name")
@Comment("작성자")
private String name;

@Embedded
@AttributeOverride(name = "url", column = @Column(name = "author_picture"))
private JpaPicture picture;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package blisgo.infrastructure.internal.persistence.common;

import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -11,7 +10,7 @@
@Getter
@Embeddable
@AllArgsConstructor(staticName = "of")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor
public class JpaPicture {
@URL(protocol = "https")
@Comment("이미지")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package blisgo.infrastructure.internal.persistence.community;

import blisgo.domain.community.Post;
import blisgo.infrastructure.internal.persistence.community.model.JpaPost;
import blisgo.infrastructure.internal.persistence.community.mapper.PostMapper;
import blisgo.infrastructure.internal.persistence.community.model.JpaPost;
import blisgo.infrastructure.internal.persistence.community.repository.PostCustomRepository;
import blisgo.infrastructure.internal.persistence.community.repository.PostJpaRepository;
import blisgo.usecase.port.PostOutputPort;
Expand Down Expand Up @@ -34,7 +34,7 @@ public boolean create(Post domain) {

@Override
public Post read(Long postId) {
return jpaRepository.findById(postId)
return customRepository.findByIdWithReplies(postId)
.map(mapper::toDomain)
.orElse(null);
}
Expand All @@ -50,14 +50,8 @@ public Slice<Post> read(Map<String, ?> columns, Pageable pageable) {
@Override
@Transactional
public boolean update(Post domain) {
if (domain.postId().id() == null) {
jpaRepository.save(mapper.toEntity(domain));
return true;
}

jpaRepository.findById(domain.postId().id()).ifPresentOrElse(
existingPost -> existingPost.updateInfo(mapper.toEntity(domain)),
() -> jpaRepository.save(mapper.toEntity(domain))
jpaRepository.findById(domain.postId().id()).ifPresent(
existingPost -> existingPost.updateInfo(mapper.toEntity(domain))
);

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package blisgo.infrastructure.internal.persistence.community.model;

import blisgo.infrastructure.internal.persistence.base.ContentConverter;
import blisgo.infrastructure.internal.persistence.common.BaseEntity;
import blisgo.infrastructure.internal.persistence.common.JpaContent;
import blisgo.infrastructure.internal.persistence.base.ContentConverter;
import jakarta.persistence.Table;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@DynamicInsert
@DynamicUpdate
Expand Down Expand Up @@ -40,7 +42,7 @@ public class JpaPost extends BaseEntity {
@Comment("좋아요")
private long likes;

@Formula("(SELECT count(*) FROM reply r WHERE r.post_id = post_id)")
@Transient
private long replies;

@Version
Expand Down
Loading

0 comments on commit d3c0f3b

Please sign in to comment.