Skip to content
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 @@ -17,9 +17,12 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/job/posts")
Expand All @@ -35,32 +38,42 @@ public class JobPostController {
@PostMapping
@Operation(
summary = "구인 공고 등록",
description = "작성자 ID를 바탕으로 구인 공고를 생성합니다.",
description = "요청 사용자의 JWT uid를 작성자로 하여 공고를 생성합니다. (authorId는 바디로 받지 않습니다)",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
required = true,
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = JobPostRequest.class),
examples = @ExampleObject(value = """
{
"authorId": 19,
"title": "백엔드 개발자 구합니다",
"description": "Spring Boot 프로젝트 개발자 모집",
"payment": 1500000,
"requiredSkills": ["Java","Spring Boot","JPA"],
"description": "Spring Boot 기반 API 개발/운영, 코드리뷰 문화",
"payment": 3500000,
"requiredSkills": ["Java","Spring Boot","JPA","MySQL"],
"duration": "6m",
"deadline": "2025-09-30"
"deadline": "2025-12-31"
}
""")
)
)
)
public ResponseEntity<JobPostResponse> createJobPost(@RequestBody JobPostRequest request) {
public ResponseEntity<JobPostResponse> createJobPost(
@AuthenticationPrincipal Jwt jwt,
@RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true)
JobPostRequest request
) {
Long authorId = com.chaineeproject.chainee.security.SecurityUtils.uidOrNull(jwt);
if (authorId == null) {
return ResponseEntity.status(401).build();
}

try {
User author = userRepository.findById(request.authorId())
User author = userRepository.findById(authorId)
.orElseThrow(() -> new ApplicationException(ErrorCode.USER_NOT_FOUND));

String skillsJson = objectMapper.writeValueAsString(request.requiredSkills());
String skillsJson = objectMapper.writeValueAsString(
request.requiredSkills() == null ? List.of() : request.requiredSkills()
);

JobPost post = JobPost.builder()
.author(author)
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/chaineeproject/chainee/dto/JobPostRequest.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// src/main/java/com/chaineeproject/chainee/dto/JobPostRequest.java
package com.chaineeproject.chainee.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Schema(description = "구인 공고 등록 요청 DTO")
@Schema(description = "구인 공고 생성 요청")
public record JobPostRequest(
@Schema(description = "작성자 ID", example = "19")
Long authorId,
@Schema(description = "제목", example = "백엔드 개발자 구합니다")
@NotBlank String title,

@Schema(description = "공고 제목", example = "백엔드 개발자 구합니다")
String title,
@Schema(description = "설명", example = "Spring Boot 기반 API 개발/운영, 코드리뷰 문화")
@NotBlank String description,

@Schema(description = "공고 설명", example = "Spring Boot 프로젝트 개발자 모집")
String description,
@Schema(description = "급여/보상(숫자)", example = "3500000")
@NotNull BigDecimal payment,

@Schema(description = "지급 금액", example = "1500000")
BigDecimal payment,

@Schema(description = "요구 기술 목록", example = "[\"Java\", \"Spring Boot\", \"JPA\"]")
@Schema(description = "요구 기술", example = "[\"Java\",\"Spring Boot\",\"JPA\",\"MySQL\"]")
List<String> requiredSkills,

@Schema(description = "프로젝트 기간 (예: 6개월은 6m)", example = "6m")
@Schema(description = "기간(표기용)", example = "6m")
String duration,

@Schema(description = "마감일", example = "2025-09-30")
@Schema(description = "마감일", example = "2025-12-31")
LocalDate deadline
) {}