Skip to content

Commit

Permalink
Merge pull request #4 from Solux-KimGreen/feat-Post
Browse files Browse the repository at this point in the history
[feat] post
  • Loading branch information
chae33 authored Feb 5, 2024
2 parents e17978b + 2dc0a6a commit c2f1d2d
Show file tree
Hide file tree
Showing 47 changed files with 661 additions and 157 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/github-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: CI/CD

# event trigger
on:
push:
branches:
- master

jobs:
CI-CD:
runs-on: ubuntu-latest




steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin' # https://github.com/actions/setup-java

## create env file
- name: create env file
run: |
touch .env
echo "${{ secrets.PROPERTIES }}" >> .env
## delete : create security.properties
##- name: make security.properties
##run: |
##cd ./src/main/resources

# security.properties 파일 생성
##touch ./security.properties

# GitHub-Actions에서 설정한 값을 security.properties 파일에 쓰기
##echo "${{ secrets.USERNAME }}" > ./security.properties
##shell: bash

- name: create firebase key
run: |
cd ./src/main/resources
touch ./kimgreen-f33e5-firebase-adminsdk-63srz-6817b2eec4.json
echo "${{ secrets.USERNAME }}" > ./kimgreen-f33e5-firebase-adminsdk-63srz-6817b2eec4.json
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
- name: Docker build & push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/kimgreen .
docker push ${{ secrets.DOCKER_USERNAME }}/kimgreen
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST}} # EC2 퍼블릭 IPv4
username: ${{ secrets.USERNAME }} # ec2-user
key: ${{ secrets.PRIVATE_KEY }} # .pem
script: |
sudo systemctl start docker
sudo docker ps
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/kimgreen
docker-compose up -d
sudo docker image prune -f
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ENTRYPOINT ["java", "-jar", "/app.jar"]

# 3. docker hub에 push
# docker push gol2580/kimgreen
# push test
# push test
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ services:



# docker run -d --name server -e TZ=Asia/Seoul -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/kimgreen
# docker run -d --name server -e TZ=Asia/Seoul -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/kimgreen
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ public void setResponse(HttpServletResponse response,int status,String msg) thro
String newResponse = new ObjectMapper().writeValueAsString(json);
response.getWriter().write(newResponse);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

return http.build();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/kimgreen/backend/domain/AuditEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public void onUpdate() {
String formattedDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
this.modifiedAt = LocalDateTime.parse(formattedDate,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/kimgreen/backend/domain/BadgeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ private BadgeList(String name, int goal, String url,String content, int number)
this.content = content;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.kimgreen.backend.domain.community;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

import java.lang.reflect.Type;

@Component
public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter {

/**
* Converter for support http request with header Content-Type: multipart/form-data
*/
public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper, MediaType.APPLICATION_OCTET_STREAM);
}

@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public Response getComment(@RequestParam("postId") Long postId){
List <GetCommentDto> commentList = commentService.getComment(postId);
return success(GET_COMMENT_SUCCESS, commentList);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,94 @@
package com.kimgreen.backend.domain.community.controller;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.kimgreen.backend.domain.community.dto.WritePostRequestDto;
import com.kimgreen.backend.domain.community.entity.Category;
import com.kimgreen.backend.domain.member.entity.Member;
import com.kimgreen.backend.domain.member.service.MemberService;
import com.kimgreen.backend.domain.community.service.PostService;
import com.kimgreen.backend.domain.profile.repository.BadgeRepository;
import com.kimgreen.backend.response.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.io.IOException;

import static com.kimgreen.backend.response.Message.*;
import static com.kimgreen.backend.response.Response.*;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;

@Tag(name = "Post")
@RestController
@RequiredArgsConstructor
@RequestMapping(value="/post")

public class PostController {

}
private final PostService postService;
private final MemberService memberService;
private final BadgeRepository badgeRepository;

@Operation(summary = "게시글 작성(인증)")
@ResponseStatus(OK)
@PostMapping(path="/check", consumes = MULTIPART_FORM_DATA_VALUE)
public Response writeCheckPost(@RequestPart(name = "jsonData") WritePostRequestDto writePostRequestDto,
@RequestPart(name = "File") MultipartFile multipartFile) throws IOException { //파일 필수 O
postService.writeCheckPost(writePostRequestDto, multipartFile, memberService.getCurrentMember());
return success(WRITE_CERTIFY_POST_SUCCESS);
}

@Operation(summary = "게시글 작성(일상)")
@ResponseStatus(OK)
@PostMapping(path="/daily", consumes = MULTIPART_FORM_DATA_VALUE)
public Response writeDailyPost(@RequestPart(name = "jsonData") WritePostRequestDto writePostRequestDto,
@RequestPart(name = "File", required = false) MultipartFile multipartFile) throws IOException { //파일 필수 X
postService.writeDailyPost(writePostRequestDto, multipartFile, memberService.getCurrentMember());
return success(WRITE_DAILY_POST_SUCCESS);
}

@Operation(summary = "게시글 상세 보기")
@ResponseStatus(OK)
@GetMapping()
public Response getPostInfo(Long postId){
return success(GET_POST_SUCCESS, postService.getPostInfo(postId));
}

@Operation(summary = "게시글 목록 불러오기")
@ResponseStatus(OK)
@GetMapping("/{category}")
public Response getPostList(Category category, com.kimgreen.backend.domain.community.entity.Tag tag) {
return success(GET_POST_LIST_SUCCESS, postService.getPostlist(category, tag));
}

@JsonIgnore
@Operation(summary = "게시글 좋아요 상위목록 불러오기")
@ResponseStatus(OK)
@GetMapping("/best")
public Response getBestPostList() {
return Response.success(GET_BEST_POST_LIST_SUCCESS, postService.getBestPostList());
}

@Operation(summary = "게시글 삭제하기")
@ResponseStatus(OK)
@DeleteMapping()
public Response deletePost(@RequestParam("postId") Long postId){
postService.deletePost(postId);
return success(DELETE_POST_SUCCESS);
}

@Operation(summary = "게시글 수정하기")
@ResponseStatus(OK)
@PutMapping(consumes = MULTIPART_FORM_DATA_VALUE)
public Response editPostInfo(Long postId,
@RequestPart(name = "body(json)") WritePostRequestDto editPostInfoRequestDto,
@RequestPart(name = "files", required = false) MultipartFile multipartFile) throws IOException {

postService.editPost(postId, editPostInfoRequestDto, multipartFile);
return success(EDIT_POST_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class ReportController {
@ResponseStatus(OK)
@PostMapping()
public Response postReport(@ParameterObject Long postId,
@RequestBody ReportRequestDto reportRequestDto) {
@RequestBody ReportRequestDto reportRequestDto) {
reportService.postReport(postId,reportRequestDto);
return success(POST_REPORT_SUCCESS);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.kimgreen.backend.domain.community.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.kimgreen.backend.domain.community.entity.Post;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude
public class GetPostInfoResponseDto {
private String writerNickname;
private String writerBadge;
private String writerProfileImg;
private String imgUrl;
private String content;
private Long postId;
private String category;
private String tag;
private Integer likeCount;
private Integer commentCount;
private Boolean isLiked;
private Boolean isMine;
private String updatedAt;

public void setImgUrl(String fullUrl) {
this.imgUrl = fullUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.kimgreen.backend.domain.community.dto;

import com.kimgreen.backend.domain.community.entity.Category;
import com.kimgreen.backend.domain.community.entity.Post;
import com.kimgreen.backend.domain.community.entity.Tag;
import com.kimgreen.backend.domain.member.entity.Member;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class WritePostRequestDto {
private String category;
private String content;

public Post toCertifyPostEntity(String category, String content, Member member) {
return Post.builder()
.member(member)
.category(Category.valueOf(category))
.content(content)
.tag(Tag.CERTIFY)
.build();
}

public Post toDailyPostEntity(String category, String content, Member member) {
return Post.builder()
.member(member)
.category(Category.valueOf(category))
.content(content)
.tag(Tag.DAILY)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public enum Category {
DAILY("일상");




private String name;
private Category(String name) {
this.name=name;
}
}
}
Loading

0 comments on commit c2f1d2d

Please sign in to comment.