Skip to content

Commit

Permalink
[feat] 공지사항 작성 API 구현
Browse files Browse the repository at this point in the history
[feat] 공지사항 작성 API 구현
  • Loading branch information
bo-ram-bo-ram authored Jul 12, 2024
2 parents 5df51a8 + 62ef30b commit b8ca8c7
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 15 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.pickple.server.api.notice.controller;

import com.pickple.server.api.notice.dto.request.NoticeCreateRequest;
import com.pickple.server.api.notice.service.NoticeCommandService;
import com.pickple.server.global.response.ApiResponseDto;
import com.pickple.server.global.response.enums.SuccessCode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class NoticeController {

private final NoticeCommandService noticeCommandService;

@PostMapping("/v1/moim/{moimId}/notice")
public ApiResponseDto createNotice(@PathVariable Long moimId,
@RequestBody NoticeCreateRequest noticeCreateRequest) {
noticeCommandService.createNotice(moimId, noticeCreateRequest);
return ApiResponseDto.success(SuccessCode.HOST_POST_SUCCESS);
}
}
28 changes: 13 additions & 15 deletions src/main/java/com/pickple/server/api/notice/domain/Notice.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.pickple.server.api.notice.domain;

import com.pickple.server.api.moim.domain.Moim;
import jakarta.persistence.*;
import lombok.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
Expand All @@ -25,17 +36,4 @@ public class Notice {
private String content;

private String imageUrl;


@Builder
public Notice(final Moim moim,
final String title,
final String content,
final String imageUrl
){
this.moim = moim;
this.title = title;
this.content = content;
this.imageUrl = imageUrl;
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.pickple.server.api.notice.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public record NoticeCreateRequest(
@Size(max = 25, message = "제목은 최대 25자 이내로 작성해주세요.")
@NotBlank(message = "제목 비어 있습니다.")
String noticeTitle,//공지사항 제목

@Size(max = 500, message = "내용은 최대 500자 이내로 작성해주세요.")
@NotBlank(message = "내용이 비어 있습니다.")
String noticeContent, //공지사항 내용

String imageUrl //공지사항 이미지
) {

}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pickple.server.api.notice.repository;

import com.pickple.server.api.notice.domain.Notice;
import org.springframework.data.jpa.repository.JpaRepository;

public interface NoticeRepository extends JpaRepository<Notice, Long> {
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.pickple.server.api.notice.service;

import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.api.moim.repository.MoimRepository;
import com.pickple.server.api.notice.domain.Notice;
import com.pickple.server.api.notice.dto.request.NoticeCreateRequest;
import com.pickple.server.api.notice.repository.NoticeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
public class NoticeCommandService {

private final MoimRepository moimRepository;
private final NoticeRepository noticeRepository;

public void createNotice(Long moimId, NoticeCreateRequest request) {
Moim moim = moimRepository.findMoimByIdOrThrow(moimId);

Notice notice = Notice.builder()
.title(request.noticeTitle())
.content(request.noticeContent())
.imageUrl(request.imageUrl())
.moim(moim)
.build();

noticeRepository.save(notice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum SuccessCode {
MOIM_SUBMISSION_POST_SUCCESS(20007, HttpStatus.OK, "모임 참여 신청 성공"),
PRESIGNED_URL_GET_SUCCESS(20008, HttpStatus.OK, "presigned url 발급 성공"),
SUBMITTED_MOIM_DETAIL_GET_SUCCESS(20008, HttpStatus.OK, "신청한 모임 상세 정보 조회 성공"),
HOST_POST_SUCCESS(20009, HttpStatus.OK, "공지사항 작성 성공"),

//201 Created
MOIM_CREATE_SUCCESS(20100, HttpStatus.CREATED, "모임 개설 성공");
Expand Down

0 comments on commit b8ca8c7

Please sign in to comment.