Skip to content

Commit 889f11a

Browse files
authored
Merge pull request #486 from depromeet/develop
dev -> prd
2 parents 6270f29 + 1cce84b commit 889f11a

16 files changed

Lines changed: 516 additions & 22 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ out/
4646

4747
### VS Code ###
4848
.vscode/
49+
50+
### macOS ###
51+
.DS_Store
4952
#*.properties
5053

5154

layer-admin/src/main/java/org/layer/admin/notice/controller/dto/AdminNoticeRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
import org.layer.domain.notice.entity.NoticeCategory;
77

88
import jakarta.validation.constraints.NotNull;
9+
import jakarta.validation.constraints.Size;
910

1011
public class AdminNoticeRequest {
1112

1213
public record CreateNoticeRequest(
1314
@NotNull
15+
@Size(max = 100)
1416
String title,
1517
@NotNull
18+
@Size(max = 800)
1619
String content,
1720
@NotNull
1821
NoticeCategory category,
@@ -38,8 +41,10 @@ public Notice toEntity() {
3841

3942
public record UpdateNoticeRequest(
4043
@NotNull
44+
@Size(max = 100)
4145
String title,
4246
@NotNull
47+
@Size(max = 800)
4348
String content,
4449
@NotNull
4550
NoticeCategory category,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.layer.admin.popup.controller;
2+
3+
import org.layer.admin.popup.controller.dto.AdminPopupRequest.CreatePopupRequest;
4+
import org.layer.admin.popup.controller.dto.AdminPopupRequest.UpdatePopupActiveRequest;
5+
import org.layer.admin.popup.controller.dto.AdminPopupRequest.UpdatePopupRequest;
6+
import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupCreateResponse;
7+
import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupDetail;
8+
import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupPage;
9+
import org.layer.admin.popup.service.AdminPopupService;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.GetMapping;
12+
import org.springframework.web.bind.annotation.PatchMapping;
13+
import org.springframework.web.bind.annotation.PathVariable;
14+
import org.springframework.web.bind.annotation.PostMapping;
15+
import org.springframework.web.bind.annotation.PutMapping;
16+
import org.springframework.web.bind.annotation.RequestBody;
17+
import org.springframework.web.bind.annotation.RequestMapping;
18+
import org.springframework.web.bind.annotation.RequestParam;
19+
import org.springframework.web.bind.annotation.RestController;
20+
21+
import jakarta.validation.Valid;
22+
import lombok.RequiredArgsConstructor;
23+
24+
@RestController
25+
@RequiredArgsConstructor
26+
@RequestMapping("/admin/popup")
27+
public class AdminPopupController {
28+
29+
private final AdminPopupService adminPopupService;
30+
31+
@GetMapping("")
32+
public ResponseEntity<PopupPage> getPopups(
33+
@RequestParam(defaultValue = "0") int page,
34+
@RequestParam(defaultValue = "20") int size) {
35+
return ResponseEntity.ok(adminPopupService.getPopups(page, size));
36+
}
37+
38+
@GetMapping("/{popupId}")
39+
public ResponseEntity<PopupDetail> getPopup(@PathVariable Long popupId) {
40+
return ResponseEntity.ok(adminPopupService.getPopup(popupId));
41+
}
42+
43+
@PostMapping("")
44+
public ResponseEntity<PopupCreateResponse> createPopup(@RequestBody @Valid CreatePopupRequest request) {
45+
Long popupId = adminPopupService.createPopup(request);
46+
return ResponseEntity.ok(PopupCreateResponse.builder().popupId(popupId).build());
47+
}
48+
49+
@PutMapping("/{popupId}")
50+
public ResponseEntity<Void> updatePopup(@PathVariable Long popupId,
51+
@RequestBody @Valid UpdatePopupRequest request) {
52+
adminPopupService.updatePopup(popupId, request);
53+
return ResponseEntity.ok().build();
54+
}
55+
56+
@PatchMapping("/{popupId}/active")
57+
public ResponseEntity<Void> updatePopupActive(@PathVariable Long popupId,
58+
@RequestBody @Valid UpdatePopupActiveRequest request) {
59+
adminPopupService.updatePopupActive(popupId, request);
60+
return ResponseEntity.ok().build();
61+
}
62+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.layer.admin.popup.controller.dto;
2+
3+
import org.layer.domain.popup.entity.Popup;
4+
import org.layer.domain.popup.entity.PopupIconType;
5+
6+
import jakarta.validation.constraints.NotNull;
7+
import jakarta.validation.constraints.Size;
8+
9+
public class AdminPopupRequest {
10+
11+
public record CreatePopupRequest(
12+
@NotNull
13+
PopupIconType iconType,
14+
@NotNull
15+
@Size(max = 30)
16+
String title,
17+
@NotNull
18+
@Size(max = 800)
19+
String content,
20+
String moveButtonUrl,
21+
@NotNull
22+
Boolean isActive
23+
) {
24+
public Popup toEntity() {
25+
return Popup.builder()
26+
.iconType(iconType)
27+
.title(title)
28+
.content(content)
29+
.moveButtonUrl(moveButtonUrl)
30+
.isActive(isActive)
31+
.build();
32+
}
33+
}
34+
35+
public record UpdatePopupRequest(
36+
@NotNull
37+
PopupIconType iconType,
38+
@NotNull
39+
@Size(max = 30)
40+
String title,
41+
@NotNull
42+
@Size(max = 800)
43+
String content,
44+
String moveButtonUrl,
45+
@NotNull
46+
Boolean isActive
47+
) {
48+
}
49+
50+
public record UpdatePopupActiveRequest(
51+
@NotNull
52+
Boolean isActive
53+
) {
54+
}
55+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.layer.admin.popup.controller.dto;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.List;
5+
6+
import org.layer.domain.popup.entity.Popup;
7+
import org.layer.domain.popup.entity.PopupIconType;
8+
import org.springframework.data.domain.Page;
9+
10+
import lombok.Builder;
11+
12+
public class AdminPopupResponse {
13+
14+
@Builder
15+
public record PopupCreateResponse(
16+
Long popupId
17+
) {
18+
}
19+
20+
@Builder
21+
public record PopupSummary(
22+
Long id,
23+
PopupIconType iconType,
24+
String title,
25+
Boolean isActive,
26+
LocalDateTime createdAt
27+
) {
28+
public static PopupSummary of(Popup popup) {
29+
return PopupSummary.builder()
30+
.id(popup.getId())
31+
.iconType(popup.getIconType())
32+
.title(popup.getTitle())
33+
.isActive(popup.getIsActive())
34+
.createdAt(popup.getCreatedAt())
35+
.build();
36+
}
37+
}
38+
39+
@Builder
40+
public record PopupDetail(
41+
Long id,
42+
PopupIconType iconType,
43+
String title,
44+
String content,
45+
String moveButtonUrl,
46+
Boolean isActive,
47+
LocalDateTime createdAt,
48+
LocalDateTime updatedAt
49+
) {
50+
public static PopupDetail of(Popup popup) {
51+
return PopupDetail.builder()
52+
.id(popup.getId())
53+
.iconType(popup.getIconType())
54+
.title(popup.getTitle())
55+
.content(popup.getContent())
56+
.moveButtonUrl(popup.getMoveButtonUrl())
57+
.isActive(popup.getIsActive())
58+
.createdAt(popup.getCreatedAt())
59+
.updatedAt(popup.getUpdatedAt())
60+
.build();
61+
}
62+
}
63+
64+
@Builder
65+
public record PopupPage(
66+
List<PopupSummary> popups,
67+
long totalCount,
68+
int totalPages
69+
) {
70+
public static PopupPage of(Page<Popup> page) {
71+
return PopupPage.builder()
72+
.popups(page.getContent().stream().map(PopupSummary::of).toList())
73+
.totalCount(page.getTotalElements())
74+
.totalPages(page.getTotalPages())
75+
.build();
76+
}
77+
}
78+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.layer.admin.popup.service;
2+
3+
import org.layer.admin.popup.controller.dto.AdminPopupRequest.CreatePopupRequest;
4+
import org.layer.admin.popup.controller.dto.AdminPopupRequest.UpdatePopupActiveRequest;
5+
import org.layer.admin.popup.controller.dto.AdminPopupRequest.UpdatePopupRequest;
6+
import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupDetail;
7+
import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupPage;
8+
import org.layer.domain.popup.entity.Popup;
9+
import org.layer.domain.popup.repository.PopupRepository;
10+
import org.springframework.data.domain.Page;
11+
import org.springframework.data.domain.PageRequest;
12+
import org.springframework.data.domain.Sort;
13+
import org.springframework.stereotype.Service;
14+
import org.springframework.transaction.annotation.Transactional;
15+
16+
import lombok.RequiredArgsConstructor;
17+
18+
@Service
19+
@RequiredArgsConstructor
20+
@Transactional(readOnly = true)
21+
public class AdminPopupService {
22+
23+
private final PopupRepository popupRepository;
24+
25+
public PopupPage getPopups(int page, int size) {
26+
Page<Popup> popups = popupRepository.findAll(
27+
PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt")));
28+
return PopupPage.of(popups);
29+
}
30+
31+
public PopupDetail getPopup(Long popupId) {
32+
Popup popup = popupRepository.findByIdOrThrow(popupId);
33+
return PopupDetail.of(popup);
34+
}
35+
36+
@Transactional
37+
public Long createPopup(CreatePopupRequest request) {
38+
Popup popup = popupRepository.save(request.toEntity());
39+
return popup.getId();
40+
}
41+
42+
@Transactional
43+
public void updatePopup(Long popupId, UpdatePopupRequest request) {
44+
Popup popup = popupRepository.findByIdOrThrow(popupId);
45+
popup.update(request.iconType(), request.title(), request.content(), request.moveButtonUrl(),
46+
request.isActive());
47+
}
48+
49+
@Transactional
50+
public void updatePopupActive(Long popupId, UpdatePopupActiveRequest request) {
51+
Popup popup = popupRepository.findByIdOrThrow(popupId);
52+
popup.updateActive(request.isActive());
53+
}
54+
}

layer-api/src/main/java/org/layer/domain/notice/controller/dto/NoticeResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public record NoticeSummary(
1818
Long id,
1919
@Schema(description = "제목")
2020
String title,
21+
@Schema(description = "본문")
22+
String content,
2123
@Schema(description = "카테고리")
2224
NoticeCategory category,
2325
@Schema(description = "상단 고정 여부")
@@ -33,6 +35,7 @@ public static NoticeSummary of(Notice notice) {
3335
return NoticeSummary.builder()
3436
.id(notice.getId())
3537
.title(notice.getTitle())
38+
.content(notice.getContent())
3639
.category(notice.getCategory())
3740
.isPinned(notice.getIsPinned())
3841
.startAt(notice.getStartAt())
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.layer.domain.popup.controller;
2+
3+
import org.layer.domain.popup.controller.dto.PopupResponse.PopupListResponse;
4+
import org.layer.domain.popup.service.PopupService;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
import lombok.RequiredArgsConstructor;
11+
12+
@RestController
13+
@RequiredArgsConstructor
14+
@RequestMapping("/api/popup")
15+
public class PopupController {
16+
17+
private final PopupService popupService;
18+
19+
@GetMapping("/list")
20+
public ResponseEntity<PopupListResponse> getPopups() {
21+
return ResponseEntity.ok(popupService.getExposedPopups());
22+
}
23+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.layer.domain.popup.controller.dto;
2+
3+
import java.util.List;
4+
5+
import org.layer.domain.popup.entity.Popup;
6+
import org.layer.domain.popup.entity.PopupIconType;
7+
8+
import io.swagger.v3.oas.annotations.media.Schema;
9+
import lombok.Builder;
10+
11+
public class PopupResponse {
12+
13+
@Builder
14+
@Schema(description = "팝업 정보")
15+
public record PopupElement(
16+
@Schema(description = "팝업 아이디")
17+
Long id,
18+
@Schema(description = "아이콘 id", example = "default")
19+
PopupIconType iconType,
20+
@Schema(description = "제목")
21+
String title,
22+
@Schema(description = "내용")
23+
String content,
24+
@Schema(description = "이동 버튼 URL. null이면 이동 버튼 없이 확인 버튼만 노출")
25+
String moveButtonUrl
26+
) {
27+
public static PopupElement of(Popup popup) {
28+
return PopupElement.builder()
29+
.id(popup.getId())
30+
.iconType(popup.getIconType())
31+
.title(popup.getTitle())
32+
.content(popup.getContent())
33+
.moveButtonUrl(popup.getMoveButtonUrl())
34+
.build();
35+
}
36+
}
37+
38+
@Builder
39+
@Schema
40+
public record PopupListResponse(
41+
List<PopupElement> popups
42+
) {
43+
public static PopupListResponse of(List<Popup> popups) {
44+
return PopupListResponse.builder()
45+
.popups(popups.stream().map(PopupElement::of).toList())
46+
.build();
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)