Skip to content

Commit

Permalink
Merge pull request #43 from Gongjakso/feat/post
Browse files Browse the repository at this point in the history
[#4, #6] Post class 게시물 CRUD 구현
  • Loading branch information
dl-00-e8 authored Feb 10, 2024
2 parents 6dfaae6 + 476b89b commit 2943612
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.gongjakso.server.domain.apply.enumerate.PostType;
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Post;
import java.util.Optional;

public record ApplyReq(
String application,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
package com.gongjakso.server.domain.post.controller;

import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.dto.PostDeleteRes;
import com.gongjakso.server.domain.post.dto.PostReq;
import com.gongjakso.server.domain.post.dto.PostRes;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.service.PostService;
import com.gongjakso.server.global.common.ApplicationResponse;
import com.gongjakso.server.global.security.PrincipalDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.pulsar.PulsarProperties.Authentication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/post")
@RequiredArgsConstructor
@Tag(name = "Post", description = "공고 관련 API")
public class PostController {

private final PostService postService;

// @PostMapping
// public ResponseEntity<> createPost() {
//
// }
@PostMapping("")
public ApplicationResponse<PostRes> create(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestBody PostReq req) {
return ApplicationResponse.ok(postService.create(principalDetails.getMember(), req));
}

@GetMapping("/{id}")
public ResponseEntity<PostRes> read(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id) {
return ResponseEntity.ok(postService.read(principalDetails.getMember(), id));
}

@PutMapping("/{id}")
public ApplicationResponse<PostRes> modify(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id, @RequestBody PostReq req) {
return ApplicationResponse.ok(postService.modify(principalDetails.getMember(), id, req));
}

/** 모집글 게시(CREATE) */
// @PostMapping("/posts")
// public ResponseEntity<PostCreationResponse> createPost(
// @RequestBody @Validated PostCreationRequest request,
// @AuthenticationPrincipal OAuth2User user) {
//
// String email = user.getName();
// Post post = postService.createPost(request, email);
// keywordService.addKeywords(post, request);
//
// return ResponseEntity.ok(
// PostCreationResponse.builder()
// .id(post.getId())
// .title(post.getThumbnail().getTitle())
// .createdDate(post.getCreatedDate())
// .build());
// }
}
@PatchMapping("/{id}")
public ApplicationResponse<PostDeleteRes> delete(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id){
return ApplicationResponse.ok(postService.delete(principalDetails.getMember(), id));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package com.gongjakso.server.domain.post.dto;public class GetProjectRes {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.gongjakso.server.domain.post.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
public class PostDeleteRes {
private Long postId;
private Long memberId;

@Builder
public PostDeleteRes(Long postId, Long memberId){
this.postId = postId;
this.memberId = memberId;
}
}
32 changes: 26 additions & 6 deletions src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
package com.gongjakso.server.domain.post.dto;

import com.gongjakso.server.domain.post.enumerate.PostType;
import lombok.Builder;
import com.gongjakso.server.domain.post.enumerate.MeetingMethod;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import org.springframework.cglib.core.Local;

@Data
@Getter
@NoArgsConstructor
public class PostReq {
private String title;
private String contents;
private PostType status;
private PostStatus status;
private LocalDateTime startDate;
private LocalDateTime endDate;
private LocalDateTime finishDate;
private Long maxPerson;
private PostType meetingMethod;
private MeetingMethod meetingMethod;
private String meetingArea;
private boolean questionMethod;
private String questionLink;
private boolean isProject;
private boolean postType;

/*
* @Builder
* public PostReq(String title, String contents, PostStatus status, LocalDateTime
* startDate, LocalDateTime endDate,
* Long maxPerson, PostType meetingMethod, String meetingArea, boolean
* questionMethod, String questionLink, boolean isProject){
* this.title = title;
* this.contents = contents;
* this.status = status;
* this.startDate = startDate;
* this.endDate = endDate;
* this.maxPerson = maxPerson;
* this.meetingArea = meetingArea;
* this.meetingMethod = meetingMethod;
* this.questionMethod = questionMethod;
* this.questionLink = questionLink;
* this.isProject = isProject;
* }
*/
}
50 changes: 49 additions & 1 deletion src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
package com.gongjakso.server.domain.post.dto;

import com.gongjakso.server.domain.post.enumerate.MeetingMethod;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class PostRes {
}
private Long postId;
private Long memberId;
private String title;
private String contents;
private PostStatus status;
private LocalDateTime startDate;
private LocalDateTime endDate;
private LocalDateTime finishDate;
private Long maxPerson;
private MeetingMethod meetingMethod;
private String meetingArea;
private boolean questionMethod;
private String questionLink;
private boolean postType;
private LocalDateTime createdAt;
private LocalDateTime modifiedAt;
private LocalDateTime deletedAt;

@Builder
public PostRes(Long postId, Long memberId, String title, String contents, PostStatus status, LocalDateTime startDate, LocalDateTime endDate,
LocalDateTime finishDate, Long maxPerson, MeetingMethod meetingMethod, String meetingArea, boolean questionMethod, String questionLink,
boolean postType, LocalDateTime createdAt, LocalDateTime modifiedAt, LocalDateTime deletedAt) {
this.postId = postId;
this.memberId = memberId;
this.title = title;
this.contents = contents;
this.status = status;
this.startDate = startDate;
this.endDate = endDate;
this.finishDate = finishDate;
this.maxPerson = maxPerson;
this.meetingArea = meetingArea;
this.meetingMethod = meetingMethod;
this.questionMethod = questionMethod;
this.questionLink = questionLink;
this.postType = postType;
this.createdAt = createdAt;
this.modifiedAt = modifiedAt;
this.deletedAt = deletedAt;
}
}
77 changes: 49 additions & 28 deletions src/main/java/com/gongjakso/server/domain/post/entity/Post.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package com.gongjakso.server.domain.post.entity;

import com.gongjakso.server.domain.post.enumerate.PostType;
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.dto.PostReq;
import com.gongjakso.server.domain.post.enumerate.MeetingMethod;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import com.gongjakso.server.global.common.BaseTimeEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.*;
import org.hibernate.annotations.SQLDelete;
import java.time.LocalDateTime;

import lombok.*;

@Getter
@Setter
@Entity
@Table(name = "post")
@SQLDelete(sql="UPDATE post SET deleted_at = NOW() where post_id=?")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Post extends BaseTimeEntity {

Expand All @@ -26,28 +23,35 @@ public class Post extends BaseTimeEntity {
@Column(name = "post_id", nullable = false, columnDefinition = "bigint")
private Long postId;

@Column(name = "title", nullable = false, columnDefinition = "varchar(20)")
@ManyToOne(targetEntity = Member.class, fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@Column(name = "title", nullable = false, columnDefinition = "varchar(40)")
private String title;

@Column(name = "contents", nullable = false, columnDefinition = "varchar(500)")
private String contents;

@Column(name = "status", columnDefinition = "varchar(255)")
@Enumerated(EnumType.STRING)
private PostType status;
private PostStatus status;

@Column(name = "start_date", nullable = false, columnDefinition = "timestamp")
private LocalDateTime startDate;

@Column(name = "end_date", nullable = false, columnDefinition = "timestamp")
private LocalDateTime endDate;

@Column(name = "finish_date", nullable = false, columnDefinition = "timestamp")
private LocalDateTime finishDate;

@Column(name = "max_person", nullable = false, columnDefinition = "bigint")
private Long maxPerson;

@Column(name = "meeting_method", columnDefinition = "varchar(10)")
@Enumerated(EnumType.STRING)
private PostType meetingMethod;
private MeetingMethod meetingMethod;

@Column(name = "meeting_area", columnDefinition = "varchar(100)")
private String meetingArea;
Expand All @@ -58,22 +62,39 @@ public class Post extends BaseTimeEntity {
@Column(name = "question_link", nullable = false, columnDefinition = "text")
private String questionLink;

@Column(name = "is_project", nullable = false, columnDefinition = "tinyint")
private boolean isProject;
@Column(name = "post_type", nullable = false, columnDefinition = "tinyint")
private boolean postType;

@Builder
public Post(Long postId, String title, String contents, PostType status, LocalDateTime startDate, LocalDateTime endDate, Long maxPerson, PostType meetingMethod, String meetingArea, boolean questionMethod, String questionLink, boolean isProject) {
this.postId = postId;
this.title = title;
this.contents = contents;
this.status = status;
this.startDate = startDate;
this.endDate = endDate;
this.maxPerson = maxPerson;
this.meetingMethod = meetingMethod;
this.meetingArea = meetingArea;
this.questionMethod = questionMethod;
this.questionLink = questionLink;
this.isProject = isProject;
public Post(Member member, PostReq req) {
this.title = req.getTitle();
this.member = member;
this.contents = req.getContents();
this.status = req.getStatus();
this.startDate = req.getStartDate();
this.finishDate = req.getFinishDate();
this.endDate = req.getEndDate();
this.maxPerson = req.getMaxPerson();
this.meetingMethod = req.getMeetingMethod();
this.meetingArea = req.getMeetingArea();
this.questionMethod = req.isQuestionMethod();
this.questionLink = req.getQuestionLink();
this.postType = req.isPostType();
}

public void modify(PostReq req) {
this.title = req.getTitle();
this.contents = req.getContents();
this.status = req.getStatus();
this.startDate = req.getStartDate();
this.endDate = req.getEndDate();
this.finishDate = req.getFinishDate();
this.maxPerson = req.getMaxPerson();
this.meetingMethod = req.getMeetingMethod();
this.meetingArea = req.getMeetingArea();
this.questionMethod = req.isQuestionMethod();
this.questionLink = req.getQuestionLink();
this.postType = req.isPostType();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.gongjakso.server.domain.post.enumerate;

public enum MeetingMethod {
NULL, OFFLINE, ONLINE, BOTH
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gongjakso.server.domain.post.enumerate;

public enum PostStatus {
RECRUITING,
CANCEL,
CLOSE,
ACTIVE,
COMPLETE
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.gongjakso.server.domain.post.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface PostRepository extends JpaRepository<Post, Long> {
//Page<Post> findAll(Pageable pageable); //전체 조회(페이징)
//Page<Post> findByCategory(StackName stackname, Pageable pageable);
Post findByPostId(Long post_id);
Optional<Post> findByPostIdAndDeletedAtIsNull(Long postId);
}
Loading

0 comments on commit 2943612

Please sign in to comment.