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

feat: 제안 생성 기능 개발 #300

Merged
merged 6 commits into from
Jun 30, 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 @@ -3,7 +3,10 @@
import com.sponus.coredomain.domain.bookmark.Bookmark;
import com.sponus.coredomain.domain.organization.Organization;

import jakarta.validation.constraints.NotNull;

public record BookmarkToggleRequest(
@NotNull
Long target
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ public BookmarkToggleResponse bookmarkToggle(Organization organization, Bookmark
return BookmarkToggleResponse.from(bookmark, true);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coreinfrasecurity.annotation.AuthOrganization;
import com.sponus.sponusbe.domain.propose.dto.request.ProposeCreateRequest;
import com.sponus.sponusbe.domain.propose.dto.request.ProposeStatusUpdateRequest;
import com.sponus.sponusbe.domain.propose.dto.request.ProposeUpdateRequest;
import com.sponus.sponusbe.domain.propose.dto.response.DateGroupedProposeResponse;
import com.sponus.sponusbe.domain.propose.dto.response.ProposeCreateResponse;
import com.sponus.sponusbe.domain.propose.dto.response.ProposeDetailGetResponse;
import com.sponus.sponusbe.domain.propose.service.ProposeQueryService;
import com.sponus.sponusbe.domain.propose.service.ProposeService;

Expand All @@ -40,81 +36,12 @@
public class ProposeController {

private final ProposeService proposeService;
private final ProposeQueryService proposeQueryService;

@PostMapping(consumes = "multipart/form-data")
@PostMapping()
public ApiResponse<ProposeCreateResponse> createPropose(
@AuthOrganization Organization authOrganization,
@RequestPart("request") @Valid ProposeCreateRequest request,
@RequestPart(value = "attachments", required = false) List<MultipartFile> attachments
) throws IOException {
return ApiResponse.onSuccess(
proposeService.createPropose(
authOrganization,
request,
attachments == null ? List.of() : attachments
)
);
@RequestBody @Valid ProposeCreateRequest request
){
return ApiResponse.onSuccess(proposeService.createPropose(authOrganization, request));
}

@GetMapping("/sent")
public ApiResponse<List<DateGroupedProposeResponse>> getSentProposes(
@AuthOrganization Organization authOrganization
) {
return ApiResponse.onSuccess(proposeQueryService.getSentProposes(authOrganization));
}

@GetMapping("/received")
public ApiResponse<List<DateGroupedProposeResponse>> getReceivedProposes(
@AuthOrganization Organization authOrganization,
@RequestParam(required = false) Long announcementId
) {
return ApiResponse.onSuccess(proposeQueryService.getReceivedProposes(authOrganization, announcementId));
}

@GetMapping("/{proposeId}")
public ApiResponse<ProposeDetailGetResponse> getProposeDetail(
@AuthOrganization Organization authOrganization,
@PathVariable Long proposeId
) {
return ApiResponse.onSuccess(proposeService.getProposeDetail(authOrganization, proposeId));
}

@PatchMapping(value = "/{proposeId}", consumes = "multipart/form-data")
public ApiResponse<Void> updatePropose(
@AuthOrganization Organization authOrganization,
@PathVariable Long proposeId,
@RequestPart @Valid ProposeUpdateRequest request,
@RequestPart(value = "attachments", required = false) List<MultipartFile> attachments
) {
proposeService.updatePropose(
authOrganization,
proposeId,
request,
attachments == null ? List.of() : attachments);
return ApiResponse.onSuccess(null);
}

@PatchMapping(value = "/{proposeId}/status")
public ApiResponse<Void> acceptPropose(
@AuthOrganization Organization authOrganization,
@PathVariable Long proposeId,
@RequestBody @Valid ProposeStatusUpdateRequest request
) {
proposeService.updateProposeStatus(
authOrganization,
proposeId,
request);
return ApiResponse.onSuccess(null);
}

@DeleteMapping("/{proposeId}")
public ApiResponse<Void> deletePropose(
@AuthOrganization Organization authOrganization,
@PathVariable Long proposeId
) {
proposeService.deletePropose(authOrganization, proposeId);
return ApiResponse.onSuccess(null);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sponus.sponusbe.domain.propose.dto.request;

import com.sponus.coredomain.domain.bookmark.Bookmark;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.propose.Propose;
import com.sponus.coredomain.domain.propose.ProposeStatus;
Expand All @@ -8,26 +9,13 @@
import jakarta.validation.constraints.NotNull;

public record ProposeCreateRequest(

@NotBlank(message = "[ERROR] 제안 제목 입력은 필수 입니다.")
String title,

@NotBlank(message = "[ERROR] 제안 내용 입력은 필수 입니다.")
String content,

@NotNull(message = "[ERROR] 제안 대상 공고 입력은 필수 입니다.")
Long announcementId
@NotNull
Long target
) {
public Propose toEntity(
Organization proposedOrganization,
Organization proposingOrganization
) {
public Propose toEntity(Organization organization, Organization target) {
return Propose.builder()
.title(title)
.content(content)
.status(ProposeStatus.PENDING)
.proposedOrganization(proposedOrganization)
.proposingOrganization(proposingOrganization)
.organization(organization)
.target(target)
.build();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
package com.sponus.sponusbe.domain.propose.dto.response;

import com.sponus.coredomain.domain.propose.Propose;

import lombok.Builder;

@Builder
public record ProposeCreateResponse(
Long proposeId
Long id,
Long organizationId,
Long target
) {

public static ProposeCreateResponse from(Propose propose) {
return ProposeCreateResponse.builder()
.id(propose.getId())
.organizationId(propose.getOrganization().getId())
.target(propose.getTarget().getId())
.build();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
@AllArgsConstructor
public enum ProposeErrorCode implements BaseErrorCode {
PROPOSE_ERROR(HttpStatus.BAD_REQUEST, "PROP4000", "제안 관련 에러"),
ANNOUNCEMENT_ID_IS_REQUIRED(HttpStatus.BAD_REQUEST, "PROP4001", "공고 ID가 필요합니다."),
INVALID_PROPOSING_ORGANIZATION(HttpStatus.BAD_REQUEST, "PROP4002", "해당 단체가 작성한 제안이 아닙니다."),
INVALID_PROPOSED_ORGANIZATION(HttpStatus.BAD_REQUEST, "PROP4003", "제안을 받은 단체만 접근이 가능합니다."),
PROPOSE_STATUS_NOT_PENDING(HttpStatus.BAD_REQUEST, "PROP4004", "수락 대기 중인 제안만 수정이 가능합니다."),
INVALID_PROPOSE_STATUS(HttpStatus.BAD_REQUEST, "PROP4005", "유효하지 않은 제안 상태입니다."),
PROPOSE_LIMIT_ERROR(HttpStatus.CONFLICT, "PROP4009", "하루 제안 5회 초과하였습니다."),
PROFILE_NOT_COMPLETED(HttpStatus.BAD_REQUEST, "PROP4010", "프로필이 작성되지 않았습니다."),
PROPOSE_NOT_FOUND(HttpStatus.NOT_FOUND, "PROP4040", "해당 제안이 존재하지 않습니다.");

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
package com.sponus.sponusbe.domain.propose.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coreinfradb.propose.ProposeCustomRepository;
import com.sponus.sponusbe.domain.propose.dto.response.DateGroupedProposeResponse;
import com.sponus.sponusbe.domain.propose.dto.response.ProposeSummaryGetResponse;

import lombok.RequiredArgsConstructor;

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

private final ProposeCustomRepository proposeCustomRepository;

public List<DateGroupedProposeResponse> getSentProposes(Organization organization) {
return DateGroupedProposeResponse.from(
proposeCustomRepository.findSentPropose(organization.getId()).stream()
.map(ProposeSummaryGetResponse::from)
.toList());
}

public List<DateGroupedProposeResponse> getReceivedProposes(Organization organization, Long announcementId) {
return DateGroupedProposeResponse.from(
proposeCustomRepository.findReceivedProposeWithAnnouncementId(organization.getId(), announcementId).stream()
.map(ProposeSummaryGetResponse::from)
.toList());
}
}
Loading
Loading