Skip to content

Commit

Permalink
Merge pull request #1 from mijin0721/devepole
Browse files Browse the repository at this point in the history
notice 공지사항 작성하는 기능 추가
  • Loading branch information
mijin0721 authored Mar 24, 2023
2 parents 1f71111 + f6b3a16 commit bdfc301
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.hallym.festival.domain.notice.controller;

import com.hallym.festival.domain.notice.dto.NoticeRequestDto;
import com.hallym.festival.domain.notice.dto.NoticeResponseDto;
import com.hallym.festival.domain.notice.entity.Notice;
import com.hallym.festival.domain.notice.dto.NoticeDto;
import com.hallym.festival.domain.notice.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "api/notice")
@RequestMapping(value = "notice")
@RequiredArgsConstructor
public class NoticeController {
private final NoticeService noticeService;

@PostMapping
public void createNotice(@RequestBody NoticeRequestDto noticeRequestDto) {
System.out.println(noticeRequestDto);
public Map<String, String> create(@RequestBody NoticeDto noticeDto) {
noticeService.create(noticeDto);
return Map.of("result", "create success");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@
import com.hallym.festival.domain.notice.entity.Notice;
import lombok.*;

@Getter // get하는 메소드 만들어줌
@Builder
@AllArgsConstructor // 모든 필드 값을 파라미터로 받는 생성자를 만들어줌
@NoArgsConstructor // 파라미터가 없는 기본 생성자를 만들어줌
public class NoticeRequestDto {
import java.time.LocalDateTime;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class NoticeDto {
private Long id;

private String title;

private String content;
private boolean is_deleted;

private Boolean active;

private LocalDateTime regDate;

private LocalDateTime modDate;

public Notice toEntity() {
Notice build = Notice.builder()
.id(id)
.title(title)
.content(content)
.is_deleted(is_deleted)
.build();
return build;
return build;
}

}

This file was deleted.

17 changes: 11 additions & 6 deletions src/main/java/com/hallym/festival/domain/notice/entity/Notice.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.hallym.festival.domain.notice.entity;

import com.hallym.festival.domain.notice.dto.NoticeResponseDto;
import com.hallym.festival.domain.notice.dto.NoticeDto;
import com.hallym.festival.global.baseEntity.BaseTimeEntity;
import lombok.*;
import org.jetbrains.annotations.NotNull;

import javax.persistence.*;


@Builder

@Table(name = "notice")
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Notice extends BaseTimeEntity {
Expand All @@ -21,15 +22,19 @@ public class Notice extends BaseTimeEntity {
private String title;
@NotNull
private String content;
private boolean is_deleted;

public NoticeResponseDto toDto() {
NoticeResponseDto build = NoticeResponseDto.builder()
private boolean active;

public NoticeDto toDto() {
NoticeDto build = NoticeDto.builder()
.id(id)
.title(title)
.content(content)
.is_deleted(is_deleted)
.active(active)
.regDate(getRegDate())
.modDate(getModDate())
.build();
return build;
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.hallym.festival.domain.notice.service;

import com.hallym.festival.domain.notice.dto.NoticeRequestDto;
import com.hallym.festival.domain.notice.dto.NoticeResponseDto;
import com.hallym.festival.domain.notice.dto.NoticeDto;
import com.hallym.festival.domain.notice.entity.Notice;
import com.hallym.festival.domain.notice.repository.NoticeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Optional;

@RequiredArgsConstructor //의존성 주입 생성자 방법
@RequiredArgsConstructor
@Transactional
@Service
public class NoticeService {
private final NoticeRepository noticeRepository;

@Transactional
public Notice createNotice(NoticeRequestDto noticeRequestDto) {
Notice notice = noticeRequestDto.toEntity();
return noticeRepository.save(notice);
public NoticeDto create(NoticeDto noticeDto) {
Notice notice = noticeDto.toEntity();
noticeRepository.save(notice);
NoticeDto noticeDto1 = notice.toDto();
return noticeDto1;
}

}
5 changes: 1 addition & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ spring:
username: likelion
password: likelion11
jpa:
<<<<<<< HEAD
=======
open-in-view: true
>>>>>>> fdc3cd3fe3d7437bf43f4d7fc7ffbe166f830b2a
generate-ddl : true
hibernate:
ddl-auto: update # db 컬럼과 일치하는지 확인
ddl-auto: create # db 컬럼과 일치하는지 확인
properties:
hibernate:
format_sql: true # 로그 출력
Expand Down

This file was deleted.

32 changes: 32 additions & 0 deletions src/test/java/com/hallym/festival/service/NoticeServiceTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hallym.festival.service;

import com.hallym.festival.domain.notice.dto.NoticeDto;
import com.hallym.festival.domain.notice.service.NoticeService;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.stream.IntStream;

@SpringBootTest
@Log4j2
public class NoticeServiceTests {
@Autowired
NoticeService noticeService;

@Test
public void 게시물_작성() {
IntStream.rangeClosed(1,10).forEach(i -> {

NoticeDto noticeDto =
NoticeDto.builder()
.title("제목" + i)
.content("내용" + i)
.build();

noticeService.create(noticeDto);
});
System.out.println("----------작성완료!----------");
}
}

0 comments on commit bdfc301

Please sign in to comment.