Skip to content

Commit

Permalink
Merge pull request #5 from JECT-Study/J01-39-be-공지사항-기능
Browse files Browse the repository at this point in the history
J01 39 be 공지사항 기능
  • Loading branch information
kmw2378 authored Jan 3, 2025
2 parents 097ff7e + ac3e349 commit cdacc40
Show file tree
Hide file tree
Showing 32 changed files with 361 additions and 120 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/ject/componote/domain/announcement/model/Title.java

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 30 additions & 0 deletions src/main/java/ject/componote/domain/faq/api/FAQController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ject.componote.domain.faq.api;

import jakarta.validation.Valid;
import ject.componote.domain.common.dto.response.PageResponse;
import ject.componote.domain.faq.application.FAQService;
import ject.componote.domain.faq.dto.request.FAQRequest;
import ject.componote.domain.faq.dto.response.FAQResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/faqs")
@RestController
@RequiredArgsConstructor
public class FAQController {
private final FAQService faqService;

@GetMapping
public ResponseEntity<PageResponse<FAQResponse>> getFAQs(@ModelAttribute @Valid final FAQRequest faqRequest,
@PageableDefault final Pageable pageable) {
return ResponseEntity.ok(
faqService.getFAQs(faqRequest, pageable)
);
}
}
23 changes: 23 additions & 0 deletions src/main/java/ject/componote/domain/faq/api/FAQTypeConstant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ject.componote.domain.faq.api;

import ject.componote.domain.faq.domain.FAQType;
import lombok.Getter;

@Getter
public enum FAQTypeConstant {
ALL(null),
COMPONENT(FAQType.COMPONENT),
DESIGN(FAQType.DESIGN),
SERVICE(FAQType.SERVICE),
ETC(FAQType.ETC);

private final FAQType type;

FAQTypeConstant(final FAQType type) {
this.type = type;
}

public boolean isAll() {
return this == ALL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ject.componote.domain.faq.application;

import ject.componote.domain.common.dto.response.PageResponse;
import ject.componote.domain.faq.api.FAQTypeConstant;
import ject.componote.domain.faq.dao.FAQRepository;
import ject.componote.domain.faq.domain.FAQ;
import ject.componote.domain.faq.domain.FAQType;
import ject.componote.domain.faq.dto.request.FAQRequest;
import ject.componote.domain.faq.dto.response.FAQResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class FAQService {
private final FAQRepository faqRepository;

public PageResponse<FAQResponse> getFAQs(final FAQRequest request, final Pageable pageable) {
final FAQTypeConstant typeConstant = request.type();
final Page<FAQResponse> page = findAllFAQsWithConditions(typeConstant, pageable)
.map(FAQResponse::from);
return PageResponse.from(page);
}

private Page<FAQ> findAllFAQsWithConditions(final FAQTypeConstant typeConstant, final Pageable pageable) {
if (typeConstant.isAll()) {
return faqRepository.findAll(pageable);
}

final FAQType type = typeConstant.getType();
return faqRepository.findAllByType(type, pageable);
}
}
11 changes: 11 additions & 0 deletions src/main/java/ject/componote/domain/faq/dao/FAQRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ject.componote.domain.faq.dao;

import ject.componote.domain.faq.domain.FAQ;
import ject.componote.domain.faq.domain.FAQType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FAQRepository extends JpaRepository<FAQ, Long> {
Page<FAQ> findAllByType(final FAQType type, final Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ject.componote.domain.announcement.domain;
package ject.componote.domain.faq.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
Expand All @@ -8,11 +8,11 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import ject.componote.domain.announcement.model.Description;
import ject.componote.domain.announcement.model.Title;
import ject.componote.domain.announcement.model.converter.DescriptionConverter;
import ject.componote.domain.announcement.model.converter.TitleConverter;
import ject.componote.domain.faq.model.FAQContent;
import ject.componote.domain.faq.model.FAQTitle;
import ject.componote.domain.faq.model.converter.FAQContentConverter;
import ject.componote.domain.common.domain.BaseEntity;
import ject.componote.domain.faq.model.converter.FAQTitleConverter;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -31,11 +31,11 @@ public class FAQ extends BaseEntity {
@Enumerated(EnumType.STRING)
private FAQType type;

@Convert(converter = TitleConverter.class)
@Convert(converter = FAQTitleConverter.class)
@Column(name = "title", nullable = false)
private Title title;
private FAQTitle title;

@Convert(converter = DescriptionConverter.class)
@Column(name = "description", nullable = false)
private Description description;
@Convert(converter = FAQContentConverter.class)
@Column(name = "content", nullable = false)
private FAQContent content;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ject.componote.domain.announcement.domain;
package ject.componote.domain.faq.domain;

public enum FAQType {
COMPONENT, DESIGN, SERVICE, ETC;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ject.componote.domain.faq.dto.request;

import jakarta.validation.constraints.NotNull;
import ject.componote.domain.faq.api.FAQTypeConstant;

public record FAQRequest(@NotNull FAQTypeConstant type) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ject.componote.domain.faq.dto.response;

import ject.componote.domain.faq.domain.FAQ;

public record FAQResponse(String title, String content) {
public static FAQResponse from(final FAQ faq) {
return new FAQResponse(faq.getTitle().getValue(), faq.getContent().getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ject.componote.domain.faq.error;

public class FAQException {
}
20 changes: 20 additions & 0 deletions src/main/java/ject/componote/domain/faq/model/FAQContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ject.componote.domain.faq.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@EqualsAndHashCode
@Getter
@ToString
public class FAQContent {
private final String value;

private FAQContent(final String value) {
this.value = value;
}

public static FAQContent from(final String value) {
return new FAQContent(value);
}
}
20 changes: 20 additions & 0 deletions src/main/java/ject/componote/domain/faq/model/FAQTitle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ject.componote.domain.faq.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@Getter
@EqualsAndHashCode
@ToString
public class FAQTitle {
private final String value;

private FAQTitle(final String value) {
this.value = value;
}

public static FAQTitle from(final String value) {
return new FAQTitle(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ject.componote.domain.faq.model.converter;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import ject.componote.domain.faq.model.FAQContent;

@Converter
public class FAQContentConverter implements AttributeConverter<FAQContent, String> {
@Override
public String convertToDatabaseColumn(final FAQContent attribute) {
return attribute.getValue();
}

@Override
public FAQContent convertToEntityAttribute(final String dbData) {
return FAQContent.from(dbData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ject.componote.domain.faq.model.converter;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import ject.componote.domain.faq.model.FAQTitle;

@Converter
public class FAQTitleConverter implements AttributeConverter<FAQTitle, String> {
@Override
public String convertToDatabaseColumn(final FAQTitle attribute) {
return attribute.getValue();
}

@Override
public FAQTitle convertToEntityAttribute(final String dbData) {
return FAQTitle.from(dbData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ject.componote.domain.notice.api;

import ject.componote.domain.common.dto.response.PageResponse;
import ject.componote.domain.notice.application.NoticeService;
import ject.componote.domain.notice.dto.response.NoticeResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/notices")
public class NoticeController {
private final NoticeService noticeService;

@GetMapping
public ResponseEntity<PageResponse<NoticeResponse>> getNotices(@PageableDefault final Pageable pageable) {
return ResponseEntity.ok(
noticeService.getNotices(pageable)
);
}
}
Loading

0 comments on commit cdacc40

Please sign in to comment.