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] B-03 #37 #60

Merged
merged 62 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
a21c5e3
feat: create post
zelly-log Feb 5, 2025
f523b16
feat: Add jobPosting GlobalErrorCode
zelly-log Feb 5, 2025
ab5b08f
Merge branch 'main' of https://github.com/prgrms-be-devcourse/NBE3-4-โ€ฆ
zelly-log Feb 5, 2025
3fdfb02
fix: Fix for not getting post ID values
zelly-log Feb 5, 2025
83a43e0
refactor: ์ธ์ฆ์ธ๊ฐ€ ๋กœ์ง ๋ณ€๊ฒฝ
sungyeong98 Feb 5, 2025
5c54223
feat: ํ”„๋ก ํŠธ ๊ธฐ์ดˆ ์ž‘์—…
sungyeong98 Feb 5, 2025
60fca72
feat: redis mock์ฒ˜๋ฆฌ
sungyeong98 Feb 5, 2025
3cede89
feat: Category Service ์นดํ…Œ๊ณ ๋ฆฌ ์ˆ˜์ • ๋กœ์ง ์ž‘์„ฑ
Gonhub9 Feb 3, 2025
6deee56
fix: merge ์˜ค๋ฅ˜
zelly-log Feb 5, 2025
bdc8330
feat: Category Controller ์นดํ…Œ๊ณ ๋ฆฌ ์ˆ˜์ • ์ถ”๊ฐ€
Gonhub9 Feb 4, 2025
a60b90b
feat: Category Service ๋”ํ‹ฐ ์ฒดํ‚น ์ถ”๊ฐ€
Gonhub9 Feb 4, 2025
5c1f2ed
refactor: Category Controller ์ˆ˜์ •
Gonhub9 Feb 4, 2025
dc5f6a9
test: Category Service Test ์ฝ”๋“œ ์ž‘์„ฑ
Gonhub9 Feb 4, 2025
3ad5025
chore: Category ์—๋Ÿฌ ์ฝ”๋“œ ์ˆ˜์ •
Gonhub9 Feb 4, 2025
b0beb72
test: Category Controller Test ์ฝ”๋“œ ์ž‘์„ฑ
Gonhub9 Feb 4, 2025
65fdfaf
test: Category Controller Test ์ˆ˜์ •
Gonhub9 Feb 4, 2025
e093db1
chore: package ๋ช… ์ˆ˜์ • ๋ฐ ErrorCode ์ถ”๊ฐ€
Gonhub9 Feb 4, 2025
24f7794
chore: querydsl ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
dd7581c
feat: ์ง€์›์ž ์ˆ˜ ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
3d48dbe
chore: querydsl ๊ด€๋ จ ์˜์กด์„ฑ ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
ee4d5e8
feat: ๋™์  ์กฐํšŒ์šฉ ๊ฒ€์ƒ‰ ์กฐ๊ฑด ๊ฐ์ฒด ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
da2bd70
refactor: RequireEducate.code ๋ณ€์ˆ˜ ํƒ€์ž… ๋ณ€๊ฒฝ
kdo1999 Feb 4, 2025
3b280b4
feat: QuerydslConfig ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
2cf42cc
feat: JobSkillResponse ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
8e52bbb
feat: JobPostingDetailResponse ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
95f5c8c
feat: JobPostingPageResponse ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
34d1ff5
feat: ํŽ˜์ด์ง• ๋™์  ์กฐํšŒ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
4843c11
feat: ํŽ˜์ด์ง• ๋™์  ์กฐํšŒ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
2c1ab49
feat: ์ฑ„์šฉ ๊ณต๊ณ  ์ปจํŠธ๋กค๋Ÿฌ ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
12725a1
refactor: ์กฐํšŒ ๋ฉ”์„œ๋“œ ํŠธ๋žœ์žญ์…˜ ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
a4a53f7
test: ApiV1JobPostingControllerTest.findAll_success ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
0b932dc
test: ApiV1JobPostingControllerTest.findAll_experience_level_success ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
60be88d
test: ApiV1JobPostingControllerTest.findAll_experience_level2_success ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
dea8f8c
test: ApiV1JobPostingControllerTest.findAll_salary_code_99_success ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
e1b7a04
test: ApiV1JobPostingControllerTest.findAll_page_size_negative_fail ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
e0e2e15
test: ApiV1JobPostingControllerTest.findAll_page_num_negative_fail ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
7f4427f
refactor: JobSkillResponse code ํƒ€์ž… ๋ณ€๊ฒฝ
kdo1999 Feb 4, 2025
58eed2e
test: TestInstance ์–ด๋…ธํ…Œ์ด์…˜ ์ถ”๊ฐ€
kdo1999 Feb 4, 2025
ce1c540
remove: JobKillResponse ์ค‘๋ณต์œผ๋กœ ์ธํ•œ ์ œ๊ฑฐ
kdo1999 Feb 4, 2025
7cff705
refactor: JobSkillResponse ๋ณ€ํ™˜ ๋ถ€๋ถ„ ์ˆ˜์ •
kdo1999 Feb 4, 2025
476bbf7
test: ๋ฏธ์‚ฌ์šฉ ์˜์กด ์ œ๊ฑฐ
kdo1999 Feb 4, 2025
b6b3095
Revert "[FEAT] CG-03 #35"
kdo1999 Feb 5, 2025
e134bed
Revert "Revert "[FEAT] CG-03 #35""
kdo1999 Feb 5, 2025
400c79c
feat: redis mock์ฒ˜๋ฆฌ
sungyeong98 Feb 5, 2025
1c06e71
refactor: ํ•„ํ„ฐ๋ง ์ฝ”๋“œ ์ˆ˜์ •
sungyeong98 Feb 5, 2025
4b99273
test: ํ…Œ์ŠคํŠธ์šฉ sql ์ถ”๊ฐ€
kdo1999 Feb 5, 2025
0637130
test: ํ…Œ์ŠคํŠธ ๋ถ€๋ถ„ ์ฃผ์„ ์ฒ˜๋ฆฌ
kdo1999 Feb 5, 2025
2a957eb
refactor: @PathVariable name ์„ค์ •
kdo1999 Feb 5, 2025
fb3d9a9
feat: ํ”„๋กœํ•„ ๊ตฌํ˜„
sungyeong98 Feb 5, 2025
93067f5
feat: Add jobPosting GlobalErrorCode
zelly-log Feb 5, 2025
d47bb2b
Merge branch 'main' of https://github.com/prgrms-be-devcourse/NBE3-4-โ€ฆ
zelly-log Feb 5, 2025
dbb3676
refactor: recruitmentClosingDate ์˜คํƒ€ ์ˆ˜์ •
zelly-log Feb 6, 2025
a30c4cf
test: ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ, ์ƒ์„ฑ ๋ฆฌํฌ์ง€ํ„ฐ๋ฆฌ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
zelly-log Feb 6, 2025
dd062d9
test: ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ, ์กฐํšŒ controller ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
zelly-log Feb 6, 2025
e6cb3b5
fix: category ๊ฐ€์ ธ์˜ค๋Š” ๋ถ€๋ถ„ null๊ฐ’ ์ฒ˜๋ฆฌ
zelly-log Feb 6, 2025
2668067
rename: Post entity์—์„œ board_id -> postid๋กœ ๋ณ€๊ฒฝ
zelly-log Feb 6, 2025
95676b6
refactor: ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ์‹œ ๋กœ๊ทธ์ธ ์ •๋ณด ํ™•์ธํ•˜๋Š” ๋กœ์ง ์ค‘๋ณต์œผ๋กœ ์ œ๊ฑฐ
zelly-log Feb 6, 2025
f678b1d
refactor: PostCreateRequestDto ๋‚ด์— Entity ๋ณ€ํ™˜ ๋กœ์ง post ์—”ํ‹ฐํ‹ฐ๋กœ ์ด์ „
zelly-log Feb 6, 2025
0324099
refactor: ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ์‹œ ๊ณต๋ฐฑ ๋ฐฉ์ง€ ์œ ํšจ์„ฑ ๊ฒ€์ฆ ๋กœ์ง ์ถ”๊ฐ€
zelly-log Feb 6, 2025
f78ce11
refactor: repository ํ…Œ์ŠคํŠธ Springboottest -> DataJpaTest ๋ณ€๊ฒฝ
zelly-log Feb 6, 2025
a54203a
style: formatting, ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” import๋ฌธ ์ œ๊ฑฐ
zelly-log Feb 6, 2025
9cbd134
Merge branch 'main' into feature/B-03
kdo1999 Feb 6, 2025
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
@@ -1,13 +1,19 @@
package com.backend.domain.post.controller;

import com.backend.domain.post.dto.PostCreateRequestDto;
import com.backend.domain.post.dto.PostResponseDto;
import com.backend.domain.post.service.PostService;
import com.backend.global.response.GenericResponse;
import com.backend.global.security.custom.CustomUserDetails;
import jakarta.validation.Valid;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -20,16 +26,17 @@ public class ApiV1PostController {
// PostService ์ฃผ์ž…
private final PostService postService;

// ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ (DTO ์ ์šฉ)
// TODO: category, jobposting ๋ฏธ๊ตฌํ˜„, ๊ตฌํ˜„ ์ดํ›„ ๋‹ค์‹œ ์ž‘์—…
// @PostMapping("/posts")
// public GenericResponse<PostResponseDto> createPost
// (@RequestBody PostCreateRequestDto responseDto){
// PostResponseDto createdPost = postService.createPost(responseDto);
// return GenericResponse.of();
// }
// ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ
@PostMapping
public GenericResponse<PostResponseDto> createPost
(@Valid @RequestBody PostCreateRequestDto responseDto,
@AuthenticationPrincipal CustomUserDetails user) {

PostResponseDto createdPost = postService.createPost(responseDto, user.getSiteUser());
return GenericResponse.of(true, HttpStatus.CREATED.value(), createdPost);
}

// ์ „์ฒด ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ (DTO ์ ์šฉ) + ์กฐ๊ฑด ์—†์ด ์ „์ฒด ๊ธ€ ์กฐํšŒ, ์นดํ…Œ๊ณ ๋ฆฌ, ์ •๋ ฌ, ๊ฒ€์ƒ‰, ํŽ˜์ด์ง•
// ์ „์ฒด ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ (DTO ์ ์šฉ) + ์กฐ๊ฑด ์—†์ด ์ „์ฒด ๊ธ€ ์กฐํšŒ, ์นดํ…Œ๊ณ ๋ฆฌ, ์ •๋ ฌ, ๊ฒ€์ƒ‰, ํŽ˜์ด์ง•
@GetMapping
public GenericResponse<Page<PostResponseDto>> getAllPosts(
@RequestParam(required = false) Long categoryId,
Expand All @@ -54,15 +61,15 @@ public GenericResponse<PostResponseDto> getPostById(@PathVariable Long id) {
}

// ๊ฒŒ์‚ฌ๊ธ€ ์ˆ˜์ • (DTO ์ ์šฉ)
// @PutMapping("/posts/{id}")
// @PutMapping("/{id}")
// public GenericResponse<PostResponseDto> updatePost(@PathVariable Long id,
// @RequestBody PostCreateRequestDto requestDto){
// PostResponseDto updatedPost = postService.updatePost(id, requestDto);
// return GenericResponse.of();
// }

// ๊ฒŒ์‹œ๊ธ€ ์‚ญ์ œ
// @DeleteMapping("/posts/{id}")
// @DeleteMapping("/{id}")
// public GenericResponse<Void> deletePost(@PathVariable Long id){
// postService.deletePost(id);
// return GenericResponse.noContent().build();
Expand Down
kdo1999 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.backend.domain.post.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -12,24 +14,14 @@
@AllArgsConstructor
public class PostCreateRequestDto {

@NotBlank(message = "์ œ๋ชฉ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.")
private String subject;
@NotBlank(message = "๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.")
private String content;
@NotNull(message = "์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ์„ ํƒํ•ด ์ฃผ์„ธ์š”.")
private Long categoryId;
@Builder.Default // ๊ธฐ๋ณธ๊ฐ’
private Long jobPostingId = null; // ๋ชจ์ง‘ ๊ฒŒ์‹œํŒ ์•„๋‹ ๊ฒฝ์šฐ null

public Long getCategoryId() {
return categoryId;
}

// DTO -> Entity
// TODO: jobposting ๋ฏธ๊ตฌํ˜„, ๊ตฌํ˜„ ์ดํ›„ ๋‹ค์‹œ ์ž‘์—…
// public Post toEntity(Category categoryEntity, JobPosting jobPostingEntity){
// return Post.builder()
// .subject(this.subject)
// .content(this.content)
// .category(this.category)
// .categoryId(this.categoryEntity)
// .jobPosting(this.jobPostingEntity)
// .build();
// }
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ public class PostResponseDto {
private String subject;
private String content;
private Long categoryId;
private Long jobPostingId;
private Long authorId;
private String authorName;
private ZonedDateTime createdAt;

// Entity -> DTO ๋ณ€ํ™˜(Builder ํ™œ์šฉ)
public static PostResponseDto fromEntity(Post post) {
return PostResponseDto.builder()
.id(post.getId())
.id(post.getPostId())
.subject(post.getSubject())
.content(post.getContent())
// TODO: category, jobposting ๋ฏธ๊ตฌํ˜„, ๊ตฌํ˜„ ์ดํ›„ ๋‹ค์‹œ ์ž‘์—…
.categoryId(post.getCategoryId().getId())
// .jobId(post.getJobId().getId())
.jobPostingId(post.getJobId() != null ? post.getJobId().getId() : null)
.createdAt(post.getCreatedAt())
.build();

Expand Down
71 changes: 45 additions & 26 deletions backend/src/main/java/com/backend/domain/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.backend.domain.category.entity.Category;
import com.backend.domain.jobposting.entity.JobPosting;
import com.backend.domain.post.dto.PostCreateRequestDto;
import com.backend.domain.user.entity.SiteUser;
import com.backend.global.baseentity.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -23,16 +25,16 @@
// ๊ฒŒ์‹œํŒ ์—”ํ‹ฐํ‹ฐ
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "post")
@AllArgsConstructor
@Builder
public class Post extends BaseEntity {

// board_id: ๊ฒŒ์‹œ๊ธ€์˜ ๊ณ ์œ  ์‹๋ณ„์ž(PK, Auto Increment)
// postId: ๊ฒŒ์‹œ๊ธ€์˜ ๊ณ ์œ  ์‹๋ณ„์ž(PK, Auto Increment)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long postId;

// subject: ๊ฒŒ์‹œ๊ธ€ ์ œ๋ชฉ
@Column(nullable = false)
Expand All @@ -42,13 +44,13 @@ public class Post extends BaseEntity {
@Column(nullable = false, columnDefinition = "TEXT")
private String content;

// ์นดํ…Œ๊ณ ๋ฆฌ ID -> ์นดํ…Œ๊ณ ๋ฆฌ ํ…Œ์ด๋ธ”๊ณผ์˜ ๊ด€๊ณ„ ์„ค์ • | ๋‹ค๋Œ€์ผ ๊ด€๊ณ„, board์˜ ์—ฌ๋Ÿฌ ๊ฒŒ์‹œ๊ธ€์ด ํ•˜๋‚˜์˜ ์นดํ…Œ๊ณ ๋ฆฌ ์ฐธ์กฐ
// ์นดํ…Œ๊ณ ๋ฆฌ ID -> ์นดํ…Œ๊ณ ๋ฆฌ ํ…Œ์ด๋ธ”๊ณผ์˜ ๊ด€๊ณ„ ์„ค์ •
@ManyToOne
@JoinColumn(name = "category_id")
@JoinColumn(name = "category_id", nullable = false)
private Category categoryId;

// ๋ชจ์ง‘ ๊ฒŒ์‹œํŒ์—๋งŒ ํ•„์š”ํ•œ ๋ถ€๋ถ„
private ZonedDateTime recruimentClosingDate; // ๋ชจ์ง‘ ๊ธฐ๊ฐ„
private ZonedDateTime recruitmentClosingDate; // ๋ชจ์ง‘ ๊ธฐ๊ฐ„
private Long numOfApplicants; // ๋ชจ์ง‘ ์ธ์›

@Enumerated(EnumType.STRING)
Expand All @@ -57,33 +59,50 @@ public class Post extends BaseEntity {

// ์ฑ„์šฉ ID -> JopPosting table์— ์ฑ„์šฉID๋ž‘ ์ด์–ด์ง
@ManyToOne
@JoinColumn(name = "job_id")
@JoinColumn(name = "job_id", nullable = true)
private JobPosting jobId;

// UserId ํ•œ ๊ฐœ์˜ ๊ฒŒ์‹œ๊ธ€์€ ์˜ค์ง ํ•œ ์œ ์ €์—๊ฒŒ๋งŒ ์†ํ•จ
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private SiteUser author;

// createDate: ์ƒ์„ฑ์ผ์ž, BaseEntity ์ƒ์†
// modifyDate: ์ˆ˜์ •์ผ์ž, BaseEntity ์ƒ์†

// ๊ฐ์ฒด ์ƒ์„ฑ ํ†ต์ผ
public static Post createPost(String subject, String content, Category category,
SiteUser author, JobPosting jobposting) {
boolean isRecruitment = "๋ชจ์ง‘ ๊ฒŒ์‹œํŒ".equals(category.getName());

return Post.builder()
.subject(subject)
.content(content)
.categoryId(category)
.jobId(jobposting)
.author(author)
.recruitmentStatus(isRecruitment ? RecruitmentStatus.OPEN : null) // ๋ชจ์ง‘ ๊ฒŒ์‹œํŒ์ด๋ฉด OPEN
.build();
}

public static Post createPost(PostCreateRequestDto dto, Category category,
SiteUser author, JobPosting jobPosting) {
return Post.builder()
.subject(dto.getSubject())
.content(dto.getContent())
.categoryId(category)
.author(author)
.jobId(jobPosting)
.recruitmentStatus(
jobPosting != null ? RecruitmentStatus.OPEN : null) // ๋ชจ์ง‘ ๊ฒŒ์‹œํŒ์ด๋ฉด OPEN
.build();
}

// ๊ฒŒ์‹œ๊ธ€ ์ˆ˜์ •
public void updatePost(String subject, String content) {
// ๊ธฐ์กด ์ œ๋ชฉ๊ณผ ๋‹ค๋ฅผ ๋•Œ
this.subject = subject;
// ๊ธฐ์กด ๊ฒŒ์‹œ๊ธ€ ๋‚ด์šฉ๊ณผ ๋‹ค๋ฅผ ๋•Œ
this.content = content;
}

// ํ…Œ์ŠคํŠธ์šฉ ์ƒ์„ฑ์ž ์ถ”๊ฐ€
public Post(String subject, String content, Category categoryId) {
this.subject = subject;
this.content = content;
this.categoryId = categoryId;

// ๋ชจ์ง‘ ๊ฒŒ์‹œํŒ์ผ ๊ฒฝ์šฐ recruitmentStatus ์„ค์ •
if (isRecruitmentCategory()) {
this.recruitmentStatus = RecruitmentStatus.OPEN;
} else {
this.recruitmentStatus = null;
}
}

// ๋ชจ์ง‘ ๊ฒŒ์‹œํŒ์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
private boolean isRecruitmentCategory() {
return "๋ชจ์ง‘ ๊ฒŒ์‹œํŒ".equals(categoryId.getName());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.backend.domain.post.service;

import com.backend.domain.category.entity.Category;
import com.backend.domain.jobposting.entity.JobPosting;
import com.backend.domain.jobposting.repository.JobPostingRepository;
import com.backend.domain.post.dto.PostCreateRequestDto;
import com.backend.domain.post.dto.PostResponseDto;
import com.backend.domain.post.entity.Post;
import com.backend.domain.post.entity.RecruitmentStatus;
import com.backend.domain.post.repository.PostRepository;

import com.backend.domain.category.repository.CategoryRepository;
import com.backend.domain.user.entity.SiteUser;
import com.backend.global.exception.GlobalErrorCode;
import com.backend.global.exception.GlobalException;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,35 +25,47 @@
@RequiredArgsConstructor
public class PostService {

// PostRepository, CategoryRepository, JobPostingRepository ์ฃผ์ž…
private final PostRepository postRepository;
// TODO: category, jobposting ๋ฏธ๊ตฌํ˜„, ๊ตฌํ˜„ ์ดํ›„ ๋‹ค์‹œ ์ž‘์—…
private final CategoryRepository categoryRepository;
// private final JobPostingRepository jobPostingRepository;
private final JobPostingRepository jobPostingRepository;

// ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ (DTO ์ ์šฉ)
// TODO: category, jobposting ๋ฏธ๊ตฌํ˜„, ๊ตฌํ˜„ ์ดํ›„ ๋‹ค์‹œ ์ž‘์—…
// @Transactional
// public PostResponseDto createPost(PostCreateRequestDto requestDto){
// // ํ•„์ˆ˜๊ฐ’์ธ categoryId, jobId ๊ธฐ๋ฐ˜ ์—”ํ‹ฐํ‹ฐ ์กฐํšŒ
// Category category = categoryRepository.findById(requestDto .getCategoryId())
// .orElseThrow(() -> new GlobalException(GlobalErrorCode.CATEGORY_NOT_FOUND));
//
// // DTO -> Entity ๋ณ€ํ™˜
// Post post = Post.builder()
// .subject(requestDto.getSubject())
// .content(requestDto.getContent())
// .postType(requestDto.getPostType())
// .categoryId(category)
// .build();
//
// // DB ์ €์žฅ
// Post savedPost = postRepository.save(post);
//
// return PostResponseDto.fromEntity(savedPost);
// }
// ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ
@Transactional
public PostResponseDto createPost(PostCreateRequestDto requestDto, SiteUser user) {

// 1. ๊ธ€ ์ž‘์„ฑ ์ „ ์นดํ…Œ๊ณ ๋ฆฌ ๋จผ์ € ์กฐํšŒ
Category category = categoryRepository.findById(requestDto.getCategoryId())
.orElseThrow(() -> new GlobalException(GlobalErrorCode.CATEGORY_NOT_FOUND));

JobPosting jobPosting = null;

// ๋ชจ์ง‘ ๊ฒŒ์‹œํŒ์ผ ๋•Œ jobpostingId๊ฐ€ ํ•„์ˆ˜
if ("๋ชจ์ง‘ ๊ฒŒ์‹œํŒ".equals(category.getName())) {
if (requestDto.getJobPostingId() == null) {
throw new GlobalException(GlobalErrorCode.JOB_POSTING_REQUIRED);
}
// JobPostingRepository๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฑ„์šฉ ๊ณต๊ณ  ์กฐํšŒ
jobPosting = jobPostingRepository.findById(requestDto.getJobPostingId())
.orElseThrow(() -> new GlobalException(GlobalErrorCode.JOB_POSTING_REQUIRED));
}

// DTO -> Entity ๋ณ€ํ™˜
Post post = Post.builder()
.subject(requestDto.getSubject())
.content(requestDto.getContent())
.categoryId(category)
.jobId(jobPosting)
.recruitmentStatus(jobPosting != null ? RecruitmentStatus.OPEN : null)
.author(user)
.build();

// DB ์ €์žฅ
Post savedPost = postRepository.save(post);

return PostResponseDto.fromEntity(savedPost);
}

// ๊ฒŒ์‹œ๊ธ€ ์ „์ฒด ์กฐํšŒ (postType โ†’ categoryId ๋ณ€๊ฒฝ)
// ๊ฒŒ์‹œ๊ธ€ ์ „์ฒด ์กฐํšŒ (postType โ†’ categoryId ๋ณ€๊ฒฝ)
@Transactional(readOnly = true)
public Page<PostResponseDto> getAllPosts(Long categoryId, String keyword, String sort,
int page, int size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Object handleResponse(ProceedingJoinPoint joinPoint) throws Throwable {

if (proceed instanceof GenericResponse<?>) {
GenericResponse<?> rsData = (GenericResponse<?>) proceed;
// response.setStatus(rsData.getCodeAsInt());
response.setStatus(rsData.getCode());
}

return proceed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@RequiredArgsConstructor
public enum GlobalErrorCode {


// ์œ ์ € ๋„๋ฉ”์ธ ์—๋Ÿฌ ์ฝ”๋“œ
USER_NOT_FOUND(HttpStatus.NOT_FOUND, 4001, "์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
UNAUTHENTICATION_USER(HttpStatus.UNAUTHORIZED, 4002, "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค."),
Expand All @@ -40,6 +39,10 @@ public enum GlobalErrorCode {
// ์›น ์†Œ์ผ“ ์—๋Ÿฌ ์ฝ”๋“œ
EXCEPTION_IN_WEBSOCKET(HttpStatus.UNAUTHORIZED, 6001, "์›น ์†Œ์ผ“ ์—ฐ๊ฒฐ ์ค‘์— ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค."),

// ์ฑ„์šฉ ๊ณต๊ณ  ๋„๋ฉ”์ธ ์—๋Ÿฌ ์ฝ”๋“œ
JOB_POSTING_NOT_FOUND(HttpStatus.NOT_FOUND, 2001, "์ฑ„์šฉ ์ •๋ณด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
JOB_POSTING_REQUIRED(HttpStatus.BAD_REQUEST, 2002, "์ฑ„์šฉ ์ •๋ณด๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค."),

//๊ณตํ†ต ์„œ๋ฒ„ ์—๋Ÿฌ ์ฝ”๋“œ 500
NOT_VALID(HttpStatus.BAD_REQUEST, 5001, "์š”์ฒญํ•˜์‹  ์œ ํšจ์„ฑ ๊ฒ€์ฆ์— ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค."),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5002, "์„œ๋ฒ„ ๋‚ด๋ถ€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค."),
Expand All @@ -49,7 +52,7 @@ public enum GlobalErrorCode {
TOKEN_NOT_FOUND(HttpStatus.UNAUTHORIZED, 7002, "ํ† ํฐ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");


private final HttpStatus httpStatus;
private final HttpStatus httpStatus;
private final int code;
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public AuthenticationManager authenticationManager(AuthenticationConfiguration a
"/oauth2/authorization/kakao",
"/api/v1/chat/**",
"/ws/**"
"/oauth2/authorization/kakao",
"/api/v1/posts" // ๊ฒŒ์‹œ๊ธ€ ์ „์ฒด ์กฐํšŒ์—๋Š” ๋กœ๊ทธ์ธ ํ•˜์ง€ ์•Š์€ ์œ ์ €๋„ ์ด์šฉ ๊ฐ€๋Šฅํ•ด์•ผ ํ•จ
));
}

Expand Down Expand Up @@ -102,7 +104,9 @@ jwtUtil, ACCESS_EXPIRATION, REFRESH_EXPIRATION, objectMapper, redisRepository, a
);

// ๋‚˜๋จธ์ง€ ํŠน์ • ๊ถŒํ•œ์ด ํ•„์š”ํ•œ URL๋“ค
authorizeRequests.requestMatchers(HttpMethod.POST, "/api/v1/category").hasRole("ADMIN")
authorizeRequests
.requestMatchers(HttpMethod.POST, "/api/v1/posts").hasRole("USER")
.requestMatchers(HttpMethod.POST, "/api/v1/category").hasRole("ADMIN")
.requestMatchers(HttpMethod.PUT, "/api/v1/category/**").hasRole("ADMIN")
.anyRequest().authenticated();
})
Expand Down
Loading
Loading