Contents API 추가 수정
This commit is contained in:
parent
77c0a7d43f
commit
a697185451
|
|
@ -1,8 +1,11 @@
|
|||
package com.leejk0523.javavue.admin.contents.controller;
|
||||
|
||||
import com.leejk0523.javavue.admin.contents.service.AdminContentsService;
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsListResult;
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsPagingQuery;
|
||||
import com.leejk0523.javavue.model.AsaContent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
@ -15,8 +18,8 @@ public class AdminContentsController {
|
|||
private final AdminContentsService adminContentsService;
|
||||
|
||||
@GetMapping("/api/admin/contents/contentsList")
|
||||
public ResponseEntity<List<AsaContent>> siteAllList() {
|
||||
final var results = adminContentsService.SiteAllList();
|
||||
public ResponseEntity<Page<ContentsListResult>> findContentsList(ContentsPagingQuery query) {
|
||||
final var results = adminContentsService.findContentsList(query);
|
||||
return ResponseEntity.ok(results);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,16 @@
|
|||
package com.leejk0523.javavue.admin.contents.dao;
|
||||
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsListResult;
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsPagingQuery;
|
||||
import com.leejk0523.javavue.model.AsaContent;
|
||||
import com.leejk0523.javavue.model.QAsaContent;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
|
@ -13,11 +22,50 @@ public class AdminContentsDao extends QuerydslRepositorySupport {
|
|||
super(AsaContent.class);
|
||||
}
|
||||
|
||||
public List<AsaContent> SiteAllList() {
|
||||
public Page<ContentsListResult> findContentsList(ContentsPagingQuery query) {
|
||||
QAsaContent asaContent = QAsaContent.asaContent;
|
||||
|
||||
return from(asaContent)
|
||||
final var offset = getOffset(query);
|
||||
final var limit = getLimit(query);
|
||||
final var pageable = getPageable(query);
|
||||
|
||||
BooleanExpression expression = asaContent.delYn.eq("N");
|
||||
|
||||
final var list = from(asaContent)
|
||||
.select(
|
||||
Projections.bean(
|
||||
ContentsListResult.class,
|
||||
asaContent.contentId,
|
||||
asaContent.contentTitle,
|
||||
asaContent.orgId,
|
||||
asaContent.useYn,
|
||||
asaContent.frstRgtrId,
|
||||
asaContent.frstRegDt,
|
||||
asaContent.lastMdfrId,
|
||||
asaContent.lastMdfcnDt
|
||||
)
|
||||
)
|
||||
.where(expression)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.orderBy(asaContent.contentId.desc())
|
||||
.fetch();
|
||||
|
||||
final var total = from(asaContent).where(expression).fetchCount();
|
||||
|
||||
return new PageImpl<>(list, pageable, total);
|
||||
}
|
||||
|
||||
private Pageable getPageable(ContentsPagingQuery query) {
|
||||
return PageRequest.of(query.getPage() - 1, query.getSize());
|
||||
}
|
||||
|
||||
private long getOffset(ContentsPagingQuery query) {
|
||||
return (long) (query.getPage() - 1) * query.getSize();
|
||||
}
|
||||
|
||||
private long getLimit(ContentsPagingQuery query) {
|
||||
return query.getSize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
package com.leejk0523.javavue.admin.contents.service;
|
||||
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsListResult;
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsPagingQuery;
|
||||
import com.leejk0523.javavue.model.AsaContent;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AdminContentsService {
|
||||
List<AsaContent> SiteAllList();
|
||||
Page<ContentsListResult> findContentsList(ContentsPagingQuery query);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package com.leejk0523.javavue.admin.contents.service;
|
||||
|
||||
import com.leejk0523.javavue.admin.contents.dao.AdminContentsDao;
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsListResult;
|
||||
import com.leejk0523.javavue.admin.contents.vo.ContentsPagingQuery;
|
||||
import com.leejk0523.javavue.model.AsaContent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -13,7 +16,7 @@ public class AdminContentsServiceImpl implements AdminContentsService {
|
|||
private final AdminContentsDao adminContentsDao;
|
||||
|
||||
@Override
|
||||
public List<AsaContent> SiteAllList() {
|
||||
return adminContentsDao.SiteAllList();
|
||||
public Page<ContentsListResult> findContentsList(ContentsPagingQuery query) {
|
||||
return adminContentsDao.findContentsList(query);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.leejk0523.javavue.admin.contents.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class ContentsListResult {
|
||||
private Integer contentId;
|
||||
private String contentTitle;
|
||||
private String orgId;
|
||||
private Boolean useYn;
|
||||
private String frstRgtrId;
|
||||
private LocalDateTime frstRegDt;
|
||||
private String lastMdfrId;
|
||||
private LocalDateTime lastMdfcnDt;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.leejk0523.javavue.admin.contents.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class ContentsPagingQuery {
|
||||
|
||||
@NotNull
|
||||
private int page;
|
||||
|
||||
@NotNull
|
||||
private int size;
|
||||
|
||||
private String orgId;
|
||||
private String siteId;
|
||||
private String keyword;
|
||||
private Type type;
|
||||
|
||||
public enum Type {
|
||||
TITLE,
|
||||
CONTENT
|
||||
}
|
||||
}
|
||||
|
|
@ -10,18 +10,15 @@ import java.time.LocalDateTime;
|
|||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "asa_content")
|
||||
@Table(name = "ASA_CONTENT")
|
||||
public class AsaContent {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@SequenceGenerator(name = "SQ_ASA_CONTENT", sequenceName = "SQ_ASA_CONTENT", allocationSize = 1)
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SQ_ASA_CONTENT")
|
||||
@Column(name = "CONTENT_ID", nullable = false)
|
||||
private Integer contentId;
|
||||
|
||||
@Size(max = 20)
|
||||
@Column(name = "SITE_ID", length = 20)
|
||||
private String siteId;
|
||||
|
||||
@Column(name = "ORG_ID", length = 36)
|
||||
private String orgId;
|
||||
|
||||
|
|
@ -38,10 +35,10 @@ public class AsaContent {
|
|||
private String contentPlain;
|
||||
|
||||
@Column(name = "USE_YN", length = 1, nullable = false)
|
||||
private Boolean useYn;
|
||||
private String useYn;
|
||||
|
||||
@Column(name = "DEL_YN", length = 1, nullable = false)
|
||||
private Boolean delYn;
|
||||
private String delYn;
|
||||
|
||||
@Column(name = "FRST_RGTR_ID", length = 50, nullable = false)
|
||||
private String frstRgtrId;
|
||||
|
|
|
|||
Loading…
Reference in New Issue