Skip to content

Commit

Permalink
Merge pull request #12 from Likelion-Inner-Join/feat/11
Browse files Browse the repository at this point in the history
[Feat]: 홍보글 리스트
  • Loading branch information
luna156 authored Dec 7, 2024
2 parents ff60b2c + e9e6f0c commit 969959f
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public enum ErrorCode {

//error
INTERNAL_SERVER_ERROR(false,HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부에서 문제가 발생했습니다."),
POST_NOT_FOUND(false, 404, "Post not found."),
WRONG_SESSION_ERROR(false, HttpStatus.UNAUTHORIZED.value(), "세션값이 잘못되었습니다."),
JSON_CONVERT_ERROR(false, HttpStatus.INTERNAL_SERVER_ERROR.value(), "JSON 변환중 오류가 발생하였습니다.")
;



private final Boolean isSuccess;
private final int code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.likelion.innerjoin.post.controller;

import com.likelion.innerjoin.common.response.CommonResponse;
import com.likelion.innerjoin.post.model.dto.PostResponseDTO;
import com.likelion.innerjoin.post.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/posts")
public class PostController {

@Autowired
private PostService postService;

@GetMapping
public CommonResponse<List<PostResponseDTO>> getPosts() {
List<PostResponseDTO> response = postService.getAllPosts();
return new CommonResponse<>(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.likelion.innerjoin.post.model.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

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

@Data
@Builder
@AllArgsConstructor
public class PostResponseDTO {

private Long postId;
private Long clubId;
private String title;
private String body;

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime startTime;

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime endTime;

private String status;
private String recruitmentType;
private Integer recruitmentCount;

private List<PostImageDTO> image;

@Data
@Builder
@AllArgsConstructor
public static class PostImageDTO {
private Long imageId;
private String imageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public class Form extends DataEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "club_id")
@JoinColumn(name = "club_id")
private Club club;

private String title;

private String description;

@OneToMany(mappedBy = "form", orphanRemoval = true, cascade = CascadeType.ALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public class Post extends DataEntity {
private Club club;

private String title;

@Column(name = "start_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;

@Column(name = "end_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;

private String body;

@Enumerated(EnumType.STRING)
Expand All @@ -46,7 +49,7 @@ public class Post extends DataEntity {
private String recruitmentCount;

@Column(name = "recruitment_type")
private String recruitment_type;
private String recruitmentType;

@OneToMany(mappedBy = "post", orphanRemoval = true, cascade = CascadeType.ALL)
private List<PostImage> imageList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.likelion.innerjoin.post.repository;

import com.likelion.innerjoin.post.model.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PostRepository extends JpaRepository<Post, Long> {
}
46 changes: 46 additions & 0 deletions src/main/java/com/likelion/innerjoin/post/service/PostService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.likelion.innerjoin.post.service;

import com.likelion.innerjoin.post.model.dto.PostResponseDTO;
import com.likelion.innerjoin.post.model.entity.Post;
import com.likelion.innerjoin.post.repository.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class PostService {

@Autowired
private PostRepository postRepository;

public List<PostResponseDTO> getAllPosts() {
List<Post> posts = postRepository.findAll(); // 게시글 목록을 데이터베이스에서 가져옴


// Post 엔티티 리스트를 PostResponseDTO로 변환
return posts.stream()
.map(post -> toPostResponseDTO(post)) // Post -> PostResponseDTO 변환
.collect(Collectors.toList());
}

// Post 엔티티를 PostResponseDTO로 변환하는 메서드
private PostResponseDTO toPostResponseDTO(Post post) {
return PostResponseDTO.builder()
.postId(post.getId())
.clubId(post.getClub().getId())
.title(post.getTitle())
.body(post.getBody())
.createdAt(post.getCreatedAt())
.startTime(post.getStartTime())
.endTime(post.getEndTime())
.status(post.getStatus().toString())
.recruitmentType(post.getRecruitmentType())
.recruitmentCount(Integer.parseInt(post.getRecruitmentCount())) // String -> Integer 변환
.image(post.getImageList().stream()
.map(image -> new PostResponseDTO.PostImageDTO(image.getId(), image.getUrl()))
.collect(Collectors.toList()))
.build();
}
}
10 changes: 8 additions & 2 deletions src/main/java/com/likelion/innerjoin/user/model/entity/Club.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ public class Club extends DataEntity implements User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "club_id")
private Integer id;
private Long id;

private String name;

@Column(name = "image_url")
private String imageUrl;

private String school;

private String email;

private String password;
@Column(name = "id", unique = true, nullable = false)

@Column(name = "login_id", unique = true, nullable = false)
private String loginId;

@Column(name = "cate_list")
private String categoryList;

Expand Down

0 comments on commit 969959f

Please sign in to comment.