Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [FEATURE] 공고 작성 기능 개발 #43

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sponus.sponusbe.auth.annotation.AuthOrganization;
import com.sponus.sponusbe.domain.announcement.dto.AnnouncementBriefResponse;
import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateRequest;
import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateResponse;
import com.sponus.sponusbe.domain.announcement.dto.AnnouncementResponse;
import com.sponus.sponusbe.domain.announcement.service.AnnouncementQueryService;
import com.sponus.sponusbe.domain.announcement.service.AnnouncementService;
import com.sponus.sponusbe.domain.organization.entity.Organization;
import com.sponus.sponusbe.global.common.ApiResponse;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -48,9 +51,10 @@ public ApiResponse<AnnouncementResponse> searchAnnouncement(@RequestParam String
return ApiResponse.onSuccess(announcementQueryService.searchAnnouncement(search));
}

@PostMapping
public ApiResponse<AnnouncementBriefResponse> createAnnouncement(AnnouncementCreateRequest request) {
return ApiResponse.onSuccess(announcementQueryService.createAnnouncement(request));
@PostMapping("/")
public ApiResponse<AnnouncementCreateResponse> createAnnouncement(@AuthOrganization Organization authOrganization,
AnnouncementCreateRequest request) {
return ApiResponse.onSuccess(announcementService.createAnnouncement(authOrganization, request));
}

@DeleteMapping("/{announcementId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.sponus.sponusbe.domain.announcement.dto;

import com.sponus.sponusbe.domain.announcement.entity.Announcement;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementStatus;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementType;
import com.sponus.sponusbe.domain.organization.entity.Organization;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -14,6 +17,19 @@ public record AnnouncementCreateRequest(
@NotNull(message = "[ERROR] 카테코리 입력은 필수 입니다.")
AnnouncementCategory category,
@NotBlank(message = "[ERROR] 내용 입력은 필수 입니다.")
String content
String content,

AnnouncementStatus status
) {

public Announcement toEntity(Organization writer) {
return Announcement.builder()
.writer(writer)
.title(title)
.type(type)
.category(category)
.content(content)
.status(status)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.sponus.sponusbe.domain.announcement.dto;

import com.sponus.sponusbe.domain.announcement.entity.Announcement;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementStatus;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementType;

import lombok.Builder;

@Builder
public record AnnouncementCreateResponse(
Long id,
Long writerId,
String title,
AnnouncementType type,
AnnouncementCategory category,
String content,
AnnouncementStatus status,
Long viewCount
) {
public static AnnouncementCreateResponse from(Announcement announcement) {
return AnnouncementCreateResponse.builder()
.id(announcement.getId())
.writerId(announcement.getWriter().getId())
.title(announcement.getTitle())
.type(announcement.getType())
.category(announcement.getCategory())
.content(announcement.getContent())
.status(AnnouncementStatus.POSTED)
.viewCount(announcement.getViewCount())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateRequest;
import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateResponse;
import com.sponus.sponusbe.domain.announcement.entity.Announcement;
import com.sponus.sponusbe.domain.announcement.repository.AnnouncementRepository;
import com.sponus.sponusbe.domain.organization.entity.Organization;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Transactional
@Service
public class AnnouncementService {

private final AnnouncementRepository announcementRepository;

public AnnouncementCreateResponse createAnnouncement(Organization authOrganization,
AnnouncementCreateRequest request) {
final Announcement announcement = announcementRepository.save(request.toEntity(authOrganization));
return AnnouncementCreateResponse.from(announcement);
}
}
Loading