Skip to content

Commit e880a7f

Browse files
committed
Merge branch 'feature/62-1'
2 parents 1ff4193 + 7405c27 commit e880a7f

32 files changed

+1128
-3
lines changed

โ€Ž.gitignoreโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
HELP.md
22
.gradle
33
build/
4+
.kotlin
45
!gradle/wrapper/gradle-wrapper.jar
56
!**/src/main/**/build/
67
!**/src/test/**/build/

โ€Žsrc/main/generated/com/daramg/server/post/domain/QCurationPost.javaโ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class QCurationPost extends EntityPathBase<CurationPost> {
3535
//inherited
3636
public final DateTimePath<java.time.LocalDateTime> createdAt;
3737

38+
//inherited
39+
public final DateTimePath<java.time.LocalDateTime> deletedAt;
40+
3841
//inherited
3942
public final ListPath<String, StringPath> hashtags;
4043

@@ -47,6 +50,9 @@ public class QCurationPost extends EntityPathBase<CurationPost> {
4750
//inherited
4851
public final BooleanPath isBlocked;
4952

53+
//inherited
54+
public final BooleanPath isDeleted;
55+
5056
//inherited
5157
public final NumberPath<Integer> likeCount;
5258

@@ -89,10 +95,12 @@ public QCurationPost(Class<? extends CurationPost> type, PathMetadata metadata,
8995
this.commentCount = _super.commentCount;
9096
this.content = _super.content;
9197
this.createdAt = _super.createdAt;
98+
this.deletedAt = _super.deletedAt;
9299
this.hashtags = _super.hashtags;
93100
this.id = _super.id;
94101
this.images = _super.images;
95102
this.isBlocked = _super.isBlocked;
103+
this.isDeleted = _super.isDeleted;
96104
this.likeCount = _super.likeCount;
97105
this.postStatus = _super.postStatus;
98106
this.primaryComposer = inits.isInitialized("primaryComposer") ? new com.daramg.server.composer.domain.QComposer(forProperty("primaryComposer")) : null;

โ€Žsrc/main/generated/com/daramg/server/post/domain/QFreePost.javaโ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class QFreePost extends EntityPathBase<FreePost> {
3333
//inherited
3434
public final DateTimePath<java.time.LocalDateTime> createdAt;
3535

36+
//inherited
37+
public final DateTimePath<java.time.LocalDateTime> deletedAt;
38+
3639
//inherited
3740
public final ListPath<String, StringPath> hashtags;
3841

@@ -45,6 +48,9 @@ public class QFreePost extends EntityPathBase<FreePost> {
4548
//inherited
4649
public final BooleanPath isBlocked;
4750

51+
//inherited
52+
public final BooleanPath isDeleted;
53+
4854
//inherited
4955
public final NumberPath<Integer> likeCount;
5056

@@ -85,10 +91,12 @@ public QFreePost(Class<? extends FreePost> type, PathMetadata metadata, PathInit
8591
this.commentCount = _super.commentCount;
8692
this.content = _super.content;
8793
this.createdAt = _super.createdAt;
94+
this.deletedAt = _super.deletedAt;
8895
this.hashtags = _super.hashtags;
8996
this.id = _super.id;
9097
this.images = _super.images;
9198
this.isBlocked = _super.isBlocked;
99+
this.isDeleted = _super.isDeleted;
92100
this.likeCount = _super.likeCount;
93101
this.postStatus = _super.postStatus;
94102
this.title = _super.title;

โ€Žsrc/main/generated/com/daramg/server/post/domain/QPost.javaโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class QPost extends EntityPathBase<Post> {
3131
//inherited
3232
public final DateTimePath<java.time.LocalDateTime> createdAt = _super.createdAt;
3333

34+
public final DateTimePath<java.time.LocalDateTime> deletedAt = createDateTime("deletedAt", java.time.LocalDateTime.class);
35+
3436
public final ListPath<String, StringPath> hashtags = this.<String, StringPath>createList("hashtags", String.class, StringPath.class, PathInits.DIRECT2);
3537

3638
//inherited
@@ -40,6 +42,8 @@ public class QPost extends EntityPathBase<Post> {
4042

4143
public final BooleanPath isBlocked = createBoolean("isBlocked");
4244

45+
public final BooleanPath isDeleted = createBoolean("isDeleted");
46+
4347
public final NumberPath<Integer> likeCount = createNumber("likeCount", Integer.class);
4448

4549
public final EnumPath<PostStatus> postStatus = createEnum("postStatus", PostStatus.class);

โ€Žsrc/main/generated/com/daramg/server/post/domain/QStoryPost.javaโ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class QStoryPost extends EntityPathBase<StoryPost> {
3333
//inherited
3434
public final DateTimePath<java.time.LocalDateTime> createdAt;
3535

36+
//inherited
37+
public final DateTimePath<java.time.LocalDateTime> deletedAt;
38+
3639
//inherited
3740
public final ListPath<String, StringPath> hashtags;
3841

@@ -45,6 +48,9 @@ public class QStoryPost extends EntityPathBase<StoryPost> {
4548
//inherited
4649
public final BooleanPath isBlocked;
4750

51+
//inherited
52+
public final BooleanPath isDeleted;
53+
4854
//inherited
4955
public final NumberPath<Integer> likeCount;
5056

@@ -87,10 +93,12 @@ public QStoryPost(Class<? extends StoryPost> type, PathMetadata metadata, PathIn
8793
this.commentCount = _super.commentCount;
8894
this.content = _super.content;
8995
this.createdAt = _super.createdAt;
96+
this.deletedAt = _super.deletedAt;
9097
this.hashtags = _super.hashtags;
9198
this.id = _super.id;
9299
this.images = _super.images;
93100
this.isBlocked = _super.isBlocked;
101+
this.isDeleted = _super.isDeleted;
94102
this.likeCount = _super.likeCount;
95103
this.postStatus = _super.postStatus;
96104
this.primaryComposer = inits.isInitialized("primaryComposer") ? new com.daramg.server.composer.domain.QComposer(forProperty("primaryComposer")) : null;

โ€Žsrc/main/java/com/daramg/server/auth/config/SecurityConfig.javaโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3232
http
3333
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
3434
.csrf(AbstractHttpConfigurer::disable)
35+
.headers(headers -> headers.frameOptions(frame -> frame.sameOrigin())) // ์ถ”๊ฐ€: h2 db ์ ‘๊ทผ
3536
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
3637
.authorizeHttpRequests(auth -> auth
3738
/**
@@ -47,6 +48,7 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
4748

4849
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll()
4950
.requestMatchers("/docs/**").permitAll()
51+
.requestMatchers("/h2-console/**").permitAll() // ์ถ”๊ฐ€: h2 db ์ ‘๊ทผ
5052

5153
/**
5254
* ์œ„์—์„œ ๋“ฑ๋ก๋˜์ง€ ์•Š์€ ๋ชจ๋“  ๊ฒฝ๋กœ๋Š” ์ธ์ฆ ํ•„์š”
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.daramg.server.notice.application;
2+
3+
import com.daramg.server.common.application.EntityUtils;
4+
import com.daramg.server.common.dto.PageRequestDto;
5+
import com.daramg.server.common.dto.PageResponseDto;
6+
import com.daramg.server.common.util.PagingUtils;
7+
import com.daramg.server.notice.domain.Notice;
8+
import com.daramg.server.notice.dto.NoticeResponseDto;
9+
import com.daramg.server.notice.repository.NoticeQueryRepository;
10+
import com.daramg.server.user.domain.User;
11+
import lombok.RequiredArgsConstructor;
12+
import org.springframework.stereotype.Service;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
import java.util.List;
16+
17+
@RequiredArgsConstructor
18+
@Transactional(readOnly = true)
19+
@Service
20+
public class NoticeQueryService {
21+
22+
private final NoticeQueryRepository noticeQueryRepository;
23+
private final PagingUtils pagingUtils;
24+
25+
public PageResponseDto<NoticeResponseDto> getAllPublishedNotices(PageRequestDto pageRequest, User user) {
26+
List<Notice> notices = noticeQueryRepository.getPublished(pageRequest);
27+
28+
return pagingUtils.createPageResponse(
29+
notices,
30+
pageRequest.getValidatedSize(),
31+
notice -> toNoticeResponseDto(notice, user),
32+
Notice::getCreatedAt,
33+
Notice::getId
34+
);
35+
}
36+
37+
private NoticeResponseDto toNoticeResponseDto(Notice notice, User user) {
38+
return NoticeResponseDto.from(notice);
39+
}
40+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.daramg.server.notice.application;
2+
3+
import com.daramg.server.common.application.EntityUtils;
4+
import com.daramg.server.notice.domain.Notice;
5+
import com.daramg.server.notice.domain.vo.NoticeCreateVo;
6+
import com.daramg.server.notice.domain.vo.NoticeUpdateVo;
7+
import com.daramg.server.notice.dto.NoticeCreateDto;
8+
import com.daramg.server.notice.dto.NoticeUpdateDto;
9+
import com.daramg.server.notice.repository.NoticeRepository;
10+
import com.daramg.server.notice.utils.NoticeUserValidator;
11+
import com.daramg.server.user.domain.User;
12+
import lombok.RequiredArgsConstructor;
13+
import lombok.extern.slf4j.Slf4j;
14+
import org.springframework.stereotype.Service;
15+
import org.springframework.transaction.annotation.Transactional;
16+
17+
@RequiredArgsConstructor
18+
@Slf4j
19+
@Service
20+
public class NoticeService {
21+
22+
private final NoticeRepository noticeRepository;
23+
private final EntityUtils entityUtils;
24+
25+
@Transactional
26+
public void create(NoticeCreateDto dto, User user) {
27+
28+
NoticeCreateVo vo = new NoticeCreateVo(
29+
user,
30+
dto.getTitle(),
31+
dto.getContent(),
32+
dto.getImages()
33+
);
34+
35+
Notice notice = Notice.from(vo);
36+
noticeRepository.save(notice);
37+
}
38+
39+
@Transactional
40+
public void updateNotice(Long noticeId, NoticeUpdateDto dto, User user) {
41+
Notice notice = entityUtils.getEntity(noticeId, Notice.class);
42+
NoticeUserValidator.check(notice, user);
43+
44+
NoticeUpdateVo vo = toUpdateVo(dto);
45+
notice.update(vo);
46+
}
47+
48+
@Transactional
49+
public void delete(Long noticeId, User user) {
50+
Notice notice = entityUtils.getEntity(noticeId, Notice.class);
51+
NoticeUserValidator.check(notice, user);
52+
notice.softDelete();
53+
}
54+
55+
private NoticeUpdateVo toUpdateVo(NoticeUpdateDto dto) {
56+
return new NoticeUpdateVo(
57+
dto.getTitle(),
58+
dto.getContent(),
59+
dto.getImages()
60+
);
61+
}
62+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.daramg.server.notice.domain;
2+
3+
import com.daramg.server.common.converter.JsonArrayConverter;
4+
import com.daramg.server.common.domain.BaseEntity;
5+
import com.daramg.server.common.exception.BusinessException;
6+
import com.daramg.server.notice.domain.vo.NoticeCreateVo;
7+
import com.daramg.server.notice.domain.vo.NoticeUpdateVo;
8+
import com.daramg.server.user.domain.User;
9+
import jakarta.persistence.*;
10+
import lombok.*;
11+
import org.hibernate.annotations.SQLRestriction;
12+
13+
import java.time.LocalDateTime;
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
@Entity
18+
@Getter
19+
@Table(name = "notices")
20+
@SQLRestriction("is_deleted = false")
21+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
22+
public class Notice extends BaseEntity<Notice> {
23+
24+
private static final String EMPTY_UPDATE_REQUEST = "์ˆ˜์ • ์‚ฌํ•ญ์ด ์—†์Šต๋‹ˆ๋‹ค.";
25+
26+
@ManyToOne(fetch = FetchType.LAZY)
27+
@JoinColumn(name = "user_id")
28+
private User user;
29+
30+
@Column(name = "title", nullable = false, columnDefinition = "TEXT")
31+
private String title;
32+
33+
@Column(name = "content", nullable = false, columnDefinition = "TEXT")
34+
private String content;
35+
36+
@Convert(converter = JsonArrayConverter.class)
37+
@Column(name = "images", columnDefinition = "JSON")
38+
private List<String> images = new ArrayList<>();
39+
40+
@Column(name = "is_deleted", nullable = false)
41+
private boolean isDeleted = false;
42+
43+
@Column(name = "deleted_at")
44+
private LocalDateTime deletedAt;
45+
46+
public void update(NoticeUpdateVo vo) {
47+
if (vo.getTitle() == null && vo.getContent() == null
48+
&& vo.getImages() == null) {
49+
throw new BusinessException(EMPTY_UPDATE_REQUEST);
50+
}
51+
52+
if (vo.getTitle() != null) {
53+
updateTitle(vo.getTitle());
54+
}
55+
56+
if (vo.getContent() != null) {
57+
updateContent(vo.getContent());
58+
}
59+
60+
if (vo.getImages() != null) {
61+
updateImages(vo.getImages());
62+
}
63+
}
64+
65+
@Builder(access = AccessLevel.PRIVATE)
66+
private Notice(String title, String content, List<String> images, User user) {
67+
this.title = title;
68+
this.content = content;
69+
this.images = (images != null) ? images : new ArrayList<>();
70+
this.user = user;
71+
}
72+
73+
public static Notice from(NoticeCreateVo vo) {
74+
return Notice.builder()
75+
.title(vo.getTitle())
76+
.content(vo.getContent())
77+
.images(vo.getImages())
78+
.user(vo.getUser())
79+
.build();
80+
}
81+
82+
protected void updateTitle(String title) {
83+
this.title = title;
84+
}
85+
86+
protected void updateContent(String content) {
87+
this.content = content;
88+
}
89+
90+
protected void updateImages(List<String> images) {
91+
this.images = (images != null) ? images : new ArrayList<>();
92+
}
93+
94+
public void softDelete() {
95+
if (this.isDeleted) return;
96+
97+
this.isDeleted = true;
98+
this.deletedAt = LocalDateTime.now();
99+
}
100+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.daramg.server.notice.domain.vo
2+
3+
import com.daramg.server.user.domain.User
4+
5+
class NoticeCreateVo (
6+
7+
val user: User,
8+
val title: String,
9+
val content: String,
10+
val images: List<String> = emptyList(),
11+
)

0 commit comments

Comments
ย (0)