Skip to content

Commit

Permalink
Merge pull request #84 from study-hub-inu/feat/terms-of-use
Browse files Browse the repository at this point in the history
Feat/terms of use
  • Loading branch information
wellbeing-dough authored Feb 11, 2024
2 parents 8786aad + 4701046 commit d0b3028
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package kr.co.studyhubinu.studyhubserver.notice.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QTermsOfUseEntity is a Querydsl query type for TermsOfUseEntity
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QTermsOfUseEntity extends EntityPathBase<TermsOfUseEntity> {

private static final long serialVersionUID = -1621487174L;

public static final QTermsOfUseEntity termsOfUseEntity = new QTermsOfUseEntity("termsOfUseEntity");

public final kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity _super = new kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity(this);

public final StringPath article = createString("article");

public final StringPath content = createString("content");

//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

public final NumberPath<Long> id = createNumber("id", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> modifiedDate = _super.modifiedDate;

public final StringPath title = createString("title");

public final StringPath version = createString("version");

public QTermsOfUseEntity(String variable) {
super(TermsOfUseEntity.class, forVariable(variable));
}

public QTermsOfUseEntity(Path<? extends TermsOfUseEntity> path) {
super(path.getType(), path.getMetadata());
}

public QTermsOfUseEntity(PathMetadata metadata) {
super(TermsOfUseEntity.class, metadata);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindNoticeResponse;
import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse;
import kr.co.studyhubinu.studyhubserver.notice.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Slice;
Expand All @@ -11,6 +12,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
Expand All @@ -24,4 +27,9 @@ public ResponseEntity<Slice<FindNoticeResponse>> getNotice(@RequestParam int pag
return ResponseEntity.ok().body(noticeService.getNotice(page, size));
}

@Operation(summary = "이용약관 조회")
@GetMapping("/v1/terms-of-use")
public ResponseEntity<List<FindTermsOfUsesResponse>> getTermsOfUse() {
return ResponseEntity.ok().body(noticeService.getTermsOfUse());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package kr.co.studyhubinu.studyhubserver.notice.domain;

import kr.co.studyhubinu.studyhubserver.common.domain.BaseTimeEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "terms_of_use")
public class TermsOfUseEntity extends BaseTimeEntity {

@Id
@Column(name = "terms_of_use_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;

private String article;

private String content;

private String version;

@Builder
public TermsOfUseEntity(String title, String article, String content, String version) {
this.title = title;
this.article = article;
this.content = content;
this.version = version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kr.co.studyhubinu.studyhubserver.notice.dto.response;

import lombok.Getter;

@Getter
public class FindTermsOfUsesResponse {

private final Long terms_of_use_id;
private final String title;
private final String article;
private final String content;

public FindTermsOfUsesResponse(Long terms_of_use_id, String title, String article, String content) {
this.terms_of_use_id = terms_of_use_id;
this.title = title;
this.article = article;
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.studyhubinu.studyhubserver.notice.repository;

import kr.co.studyhubinu.studyhubserver.notice.domain.TermsOfUseEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TermsOfUseRepository extends JpaRepository<TermsOfUseEntity, Long>, TermsOfUseRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kr.co.studyhubinu.studyhubserver.notice.repository;

import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse;

import java.util.List;

public interface TermsOfUseRepositoryCustom {
List<FindTermsOfUsesResponse> findAllTermsOfUse();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package kr.co.studyhubinu.studyhubserver.notice.repository;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import kr.co.studyhubinu.studyhubserver.notice.domain.QTermsOfUseEntity;
import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

import static kr.co.studyhubinu.studyhubserver.notice.domain.QTermsOfUseEntity.termsOfUseEntity;


@Repository
@RequiredArgsConstructor
public class TermsOfUseRepositoryCustomImpl implements TermsOfUseRepositoryCustom{

private final JPAQueryFactory jpaQueryFactory;

@Override
public List<FindTermsOfUsesResponse> findAllTermsOfUse() {
QTermsOfUseEntity termsOfUse = termsOfUseEntity;

JPAQuery<FindTermsOfUsesResponse> data = jpaQueryFactory
.select(Projections.constructor(
FindTermsOfUsesResponse.class,
termsOfUse.id.as("terms_of_use_id"), termsOfUse.title, termsOfUse.article, termsOfUse.content
)
)
.from(termsOfUse);

return data.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@

import kr.co.studyhubinu.studyhubserver.common.dto.Converter;
import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindNoticeResponse;
import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse;
import kr.co.studyhubinu.studyhubserver.notice.repository.NoticeRepository;
import kr.co.studyhubinu.studyhubserver.notice.repository.TermsOfUseRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class NoticeService {

private final NoticeRepository noticeRepository;
private final TermsOfUseRepository termsOfUseRepository;

public Slice<FindNoticeResponse> getNotice(int page, int size) {
final Pageable pageable = PageRequest.of(page, size);
return Converter.toSlice(pageable, noticeRepository.findNoticeAll(pageable));
}

public List<FindTermsOfUsesResponse> getTermsOfUse() {
return termsOfUseRepository.findAllTermsOfUse();
}
}
12 changes: 12 additions & 0 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DROP TABLE if EXISTS users;
DROP TABLE IF EXISTS fcm_token;
DROP TABLE IF EXISTS notice;
DROP TABLE IF EXISTS reject;
DROP TABLE IF EXISTS terms_of_use;

CREATE TABLE users
(
Expand Down Expand Up @@ -131,3 +132,14 @@ CREATE TABLE reject (
modified_date TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY (reject_id)
);

CREATE TABLE terms_of_use (
terms_of_use_id BIGINT NOT NULL AUTO_INCREMENT,
title VARCHAR(100),
article VARCHAR(100),
content TEXT,
version VARCHAR(50),
created_date TIMESTAMP(3) DEFAULT NULL,
modified_date TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY (terms_of_use_id)
);

0 comments on commit d0b3028

Please sign in to comment.