Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c16b611
[#20] Feat: Post 관련 파일 Swagger API 명세 설명 설정
jeanniejang Aug 24, 2022
d375d35
[#20] Feat: PostCreateResponseDto field name 수정
jeanniejang Aug 24, 2022
4b71d8d
Merge branch 'develop' into feature#20
jeanniejang Aug 24, 2022
1453af3
Merge pull request #21 from Inssagram-CloneCode/feature#20
Moveuk Aug 24, 2022
c8d0f49
[#22]Fix: 스웨거 회원가입 로그인 기본 example 수정
Moveuk Aug 24, 2022
0caccd7
Merge branch 'develop' into feature#22
Moveuk Aug 24, 2022
9cdd2b3
Merge pull request #23 from Inssagram-CloneCode/feature#22
Moveuk Aug 24, 2022
dc38c64
[#1] Feat: 게시물 조회 시 HttpStatus 수정
jeanniejang Aug 24, 2022
3ad1498
Merge pull request #25 from Inssagram-CloneCode/feature#1
Moveuk Aug 24, 2022
5758f8a
[#18] feat: 마이페이지 기능 구현
HASEUNGHEEE Aug 24, 2022
d7f5c2e
[#18] fix: 스웨거 설정 오타 수정
HASEUNGHEEE Aug 24, 2022
6b8fe50
Merge pull request #27 from Inssagram-CloneCode/feature#18
HASEUNGHEEE Aug 24, 2022
29a0001
[#28] Feat: Heart 관련 파일 스웨거 설정
HASEUNGHEEE Aug 24, 2022
c871afe
Build: 빌드 yml 설정 암호화 테스트
Moveuk Aug 24, 2022
b3e8612
Merge pull request #29 from Inssagram-CloneCode/feature#28
Moveuk Aug 24, 2022
2c3842b
Build: 빌드 yml 설정 암호화 테스트2
Moveuk Aug 24, 2022
fae36d5
🔥!HOTFIX: 긴급배포를 위한 수정
jeanniejang Aug 24, 2022
92f4a3d
Build: v2.0.0-SNAPSHOT Release
Moveuk Aug 24, 2022
dbdabfc
[#26]Fix: 본인만 수정 가능하도록 수정
Moveuk Aug 24, 2022
09feb56
Merge pull request #31 from Inssagram-CloneCode/feature#26
Moveuk Aug 24, 2022
76ee7ce
Build: v2.0.1 version Release
Moveuk Aug 25, 2022
d8f9d6b
[#32]Build: 자동 배포 환경 변수 설정 테스트
Moveuk Aug 25, 2022
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
76 changes: 38 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# 언어와 jdk의 버전을 지정한다.
language: java
jdk:
- openjdk11
- openjdk11

# 어느 브랜치가 push 될 때 수행할지 지정한다.
# 오직 main 브랜치가 push될 때 수행하도록 지정하였다.
branches:
only:
- main
- main

# 빌드 전에 gradlew의 권한을 추가한다.
# 빌드 전에 할 일
# application 복호화하여 사용할 수있도록 하기
# gradlew의 권한을 추가한다.
before_install:
- chmod +x gradlew
- chmod +x gradlew

# Travis CI 서버의 Home
# gradle을 통하여 의존성을 받게 되면 이를 캐시하여 배포할 때 마다 다시 받지 않도록 설정한다.
cache:
directories:
- '$HOME/.m2/repository'
- '$HOME/.gradle'
- "$HOME/.m2/repository"
- "$HOME/.gradle"

# main 브랜치에 push 되면 수행되는 명령어이다.
# 프로젝트 내에 권한이 추가된 gradlew를 활용하여 clean, build를 진행한다.
Expand All @@ -28,42 +30,40 @@ script: "./gradlew clean build"
notifications:
email:
recipients:
- v_donguk@naver.com
- v_donguk@naver.com

# deploy 명령어가 실행되기 전 전처리 과정
# CodeDeploy는 Jar 파일을 인식 못하므로 Jar+기타 설정 파일들을 모아 압축함.
before_deploy:
- mkdir -p before-deploy # zip에 파합시킬 파일들을 담을 디렉토리 생성
- cp scripts/*.sh before-deploy/ # 스크립트 파일 복사
- cp appspec.yml before-deploy/ # CodeDeploy 설정 파일 복사
- cp build/libs/*.jar before-deploy/ # jar 배포파일 복사
- cd before-deploy && zip -r before-deploy * # before-deploy로 이동하여 전체 파일 압축함
- cd ../ && mkdir -p deploy # 상위 디렉토리 이동하여 deploy 디렉토리 생성
- mv before-deploy/before-deploy.zip deploy/backend_server.zip # deploy로 zip파일 이동
- mkdir -p before-deploy # zip에 파합시킬 파일들을 담을 디렉토리 생성
- cp scripts/*.sh before-deploy/ # 스크립트 파일 복사
- cp appspec.yml before-deploy/ # CodeDeploy 설정 파일 복사
- cp build/libs/*.jar before-deploy/ # jar 배포파일 복사
- cd before-deploy && zip -r before-deploy * # before-deploy로 이동하여 전체 파일 압축함
- cd ../ && mkdir -p deploy # 상위 디렉토리 이동하여 deploy 디렉토리 생성
- mv before-deploy/before-deploy.zip deploy/backend_server.zip # deploy로 zip파일 이동

# S3 파일 업로드 혹은 CodeDeploy로 배포 등 외부 서비스와 연동될 행위들을 선언.
deploy:
- provider: s3
access_key_id: $AWS_ACCESS_KEY # Travis repo settings에서 설정된 값
secret_access_key: $AWS_SECRET_KEY # Travis repo settings에서 설정된 값
bucket: ldu-springboot-build # S3 버킷 이름
region: ap-northeast-2 # 지역이름
skip_cleanup: true
acl: private # zip 파일 접근을 private으로 설정
local_dir: deploy # before_deploy에서 생성한 디렉토리에 있는 파일들만 S3로 정송
on:
all_branches: true

- provider: codedeploy
access_key_id: $AWS_ACCESS_KEY # Travis repo settings에서 설정된 값
secret_access_key: $AWS_SECRET_KEY # Travis repo settings에서 설정된 값
bucket: ldu-springboot-build # S3 버킷 이름
key: backend_server.zip # 빌드 파일을 압축해서 전달
bundle_type: zip # 압축 확장자
application: backend_server # 웹 콘솔에서 등록한 CodeDeploy 애플리케이션
deployment_group: backend_server-group # 웹 콘솔에서 등록한 CodeDeploy 배포 그룹 이름
region: ap-northeast-2 # 지역이름
wait-until-deployed: true
on:
all_branches: true

- provider: s3
access_key_id: "$AWS_ACCESS_KEY" # Travis repo settings에서 설정된 값
secret_access_key: "$AWS_SECRET_KEY" # Travis repo settings에서 설정된 값
bucket: ldu-springboot-build # S3 버킷 이름
region: ap-northeast-2 # 지역이름
skip_cleanup: true
acl: private # zip 파일 접근을 private으로 설정
local_dir: deploy # before_deploy에서 생성한 디렉토리에 있는 파일들만 S3로 정송
on:
all_branches: true
- provider: codedeploy
access_key_id: "$AWS_ACCESS_KEY" # Travis repo settings에서 설정된 값
secret_access_key: "$AWS_SECRET_KEY" # Travis repo settings에서 설정된 값
bucket: ldu-springboot-build # S3 버킷 이름
key: backend_server.zip # 빌드 파일을 압축해서 전달
bundle_type: zip # 압축 확장자
application: backend_server # 웹 콘솔에서 등록한 CodeDeploy 애플리케이션
deployment_group: backend_server-group # 웹 콘솔에서 등록한 CodeDeploy 배포 그룹 이름
region: ap-northeast-2 # 지역이름
wait-until-deployed: true
on:
all_branches: true
Binary file added application.tar.enc
Binary file not shown.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.clonecode'
version = '1.0.1-SNAPSHOT'
version = '2.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ chmod +x $JAR_NAME # JAR 파일에 대한 권한이 없으므로 부여함.

echo "> $JAR_NAME 실행"

nohup java -jar -Dspring.config.location=classpath:/application.yml,/home/ubuntu/app/application-server.yml $JAR_NAME > $REPOSITORY/nohup.out 2>&1 & # nobup 실행하면 CodeDeploy가 무한 대기하므로 nobup.out을 표준 입출력용으로 별도로 사용함.
nohup java -jar $JAR_NAME > $REPOSITORY/nohup.out 2>&1 & # nobup 실행하면 CodeDeploy가 무한 대기하므로 nobup.out을 표준 입출력용으로 별도로 사용함.
# 이렇게 하지 않으면 nohup.out 파일이 생성되지 않고, CodeDeploy 로그에 표준 입출력이 출력됨.
# nohup이 끝나기 전까지 CodeDeploy도 끝나지 않으니 꼭 이렇게 해야만 함.
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.clonecode.inssagram.controller;

import com.clonecode.inssagram.dto.request.HeartRequestDto;
import com.clonecode.inssagram.dto.response.HeartResponseDto;
import com.clonecode.inssagram.service.HeartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.RestController;

@Api(tags = {"좋아요 API Controller"})
@RestController
@RequiredArgsConstructor
public class HeartController {
private final HeartService heartService;

@ApiOperation(value = "좋아요", notes = "좋아요 기능", response = HeartResponseDto.class)
@PostMapping("/api/likes/{postId}")
public ResponseEntity toggleHeart(@PathVariable(name = "postId") Long postId,
@RequestBody HeartRequestDto requestDto) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.clonecode.inssagram.controller;

import com.clonecode.inssagram.dto.response.MyPageResponseDto;
import com.clonecode.inssagram.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = {"마이페이지 API Controller"})
@RestController
@RequestMapping("/api/users")
@RequiredArgsConstructor
public class MyPageController {
private final PostService postService;

@ApiOperation(value = "마이페이지 조회", notes = "마이페이지 조회 기능", response = MyPageResponseDto.class)
@RequestMapping(value = "/{userId}", method = RequestMethod.GET)
public ResponseEntity getMyPage(@PathVariable(name = "userId") Long userId) {
return new ResponseEntity<>(
postService.getMyPage(userId),
HttpStatus.valueOf(HttpStatus.OK.value()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
import com.clonecode.inssagram.global.error.ErrorCode;
import com.clonecode.inssagram.jwt.TokenProvider;
import com.clonecode.inssagram.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = {"게시물 API Controller"})
@RestController
@RequestMapping("/api/posts")
@RequiredArgsConstructor
Expand All @@ -27,10 +30,10 @@ public class PostController {
private final TokenProvider tokenProvider;

@ApiOperation(value = "게시물 작성", notes = "게시물 작성 기능", response = PostCreateResponseDto.class)
@PostMapping()
@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<?> createPost(
PostRequestDto requestDto,
List<MultipartFile> imageFileList) {
@RequestPart PostRequestDto requestDto,
@RequestPart List<MultipartFile> imageFileList) {

User user = tokenProvider.getUserFromAuthentication();
if (imageFileList == null) {
Expand All @@ -45,7 +48,7 @@ public ResponseEntity<?> getPosts() {
if (tokenProvider.getUserFromAuthentication() == null) {
throw new InvalidValueException(ErrorCode.LOGIN_REQUIRED);
}
return new ResponseEntity<>(postService.getAllPosts(), HttpStatus.valueOf(HttpStatus.FOUND.value()));
return new ResponseEntity<>(postService.getAllPosts(), HttpStatus.valueOf(HttpStatus.OK.value()));
}

@ApiOperation(value = "상세 게시물 조회", notes = "상세 게시물 조회 기능", response = PostDetailResponseDto.class)
Expand All @@ -54,7 +57,7 @@ public ResponseEntity<?> getPost(@PathVariable Long postId) {
if (tokenProvider.getUserFromAuthentication() == null) {
throw new InvalidValueException(ErrorCode.LOGIN_REQUIRED);
}
return new ResponseEntity<>(postService.getOnePost(postId), HttpStatus.valueOf(HttpStatus.FOUND.value()));
return new ResponseEntity<>(postService.getOnePost(postId), HttpStatus.valueOf(HttpStatus.OK.value()));
}

@ApiOperation(value = "게시물 수정", notes = "게시물 수정 기능", response = PostUpdateResponseDto.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public ResponseEntity<?> logout(HttpServletRequest request) {

@RequestMapping(value = "/users/{userId}", method = RequestMethod.PUT)
@ApiOperation(value = "유저 프로필 수정", notes = "유저 프로필 수정 기능")
public ResponseEntity<?> editUserProfile(EditUserProfileRequestDto editUserProfileRequestDto,
List<MultipartFile> profileImageFile, @PathVariable Long userId) {
public ResponseEntity<?> editUserProfile(@RequestPart EditUserProfileRequestDto editUserProfileRequestDto,
@RequestPart List<MultipartFile> profileImageFile, @PathVariable Long userId) {
userService.editUserProfile(editUserProfileRequestDto, profileImageFile, userId);
return new ResponseEntity<>("회원 정보 수정이 성공적으로 반영되었습니다", HttpStatus.valueOf(HttpStatus.OK.value()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/clonecode/inssagram/domain/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Image {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn (name = "postId")
@JoinColumn (name = "postId", nullable = false)
private Post post;

@NotNull
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/clonecode/inssagram/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public class Post extends Timestamped {
@Column
private Long heartNum;

public Post(User user, PostRequestDto postRequestDto) {
public Post(User user, PostRequestDto postRequestDto, Long heartNum) {
this.user = user;
this.postContents = postRequestDto.getPostContents();
this.heartNum = heartNum;
}

public void update(PostRequestDto requestDto){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.clonecode.inssagram.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

@Getter
public class HeartRequestDto {
@ApiModelProperty(example = "현재 좋아요 상태")
private Long isHeart;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.clonecode.inssagram.dto.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,6 +11,8 @@
@AllArgsConstructor
@NoArgsConstructor
public class HeartResponseDto {
@ApiModelProperty(example = "좋아요 수")
private Long heartNum;
@ApiModelProperty(example = "현재 좋아요 상태")
private Long isHeart;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.clonecode.inssagram.dto.response;

import com.clonecode.inssagram.domain.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
public class MyPageResponseDto {

@ApiModelProperty(example = "사용자 정보")
private UserDetailProfileResponseDto user;

@ApiModelProperty(example = "사용자가 작성한 총 게시글 수")
private Long postTotalNum;

@ApiModelProperty(example = "사용자가 받은 총 하트 수")
private Long heartTotalNum;

@ApiModelProperty(example = "사용자가 작성한 게시글 목록")
private List<PostCreateResponseDto> contentList;

@Builder
public MyPageResponseDto(User user, Long postTotalNum, Long heartTotalNum,
List<PostCreateResponseDto> contentList) {
this.user = new UserDetailProfileResponseDto(user);
this.postTotalNum = postTotalNum;
this.heartTotalNum = heartTotalNum;
this.contentList = contentList;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.clonecode.inssagram.domain.Image;
import com.clonecode.inssagram.domain.Post;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -12,13 +13,23 @@

@Getter
public class PostAllResponseDto {
@ApiModelProperty(example = "게시물 DB Id")
private Long postId;
@ApiModelProperty(example = "게시물 작성자 정보")
private UserProfileResponseDto user;
@ApiModelProperty(example = "게시물 글 내용")
private String postContents;
@ApiModelProperty(example = "게시물 사진 URL")
private List<String> imageUrlList;
@ApiModelProperty(example = "게시물 하트 수")
private Long heartNum;
@ApiModelProperty(example = "게시물 댓글 수")
private Long commentNum;
@ApiModelProperty(example = "로그인한 사용자의 게시물 하트 여부")
private Long isHeart;
@ApiModelProperty(example = "게시물 댓글 목록")
private List<CommentResponseDto> commentList;
@ApiModelProperty(example = "게시물 생성일자")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime createdAt;

Expand All @@ -28,6 +39,7 @@ public PostAllResponseDto(Post post, Long heartNum, Long commentNum, Long isHear
this.user = new UserProfileResponseDto(post.getUser());
this.postContents = post.getPostContents();
this.imageUrlList = post.getImageList().stream().map(Image::getImageUrl).collect(Collectors.toList());
this.commentList = post.getCommentList().stream().map(CommentResponseDto::new).limit(2).collect(Collectors.toList());
this.createdAt = post.getCreatedAt();
this.heartNum = heartNum;
this.commentNum = commentNum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

@Getter
public class PostCreateResponseDto {
@ApiModelProperty(example = "게시물 Id")
@ApiModelProperty(example = "게시물 DB Id")
@NotBlank
private Long postId;
@ApiModelProperty(example = "사진 url")
@ApiModelProperty(example = "게시물 사진 URL")
@NotBlank
private String imageUrl;
@ApiModelProperty(example = "게시물 좋아요 수")
@ApiModelProperty(example = "게시물 하트 수")
@NotBlank
private Long heartNum;
@ApiModelProperty(example = "게시물 댓글 수")
Expand Down
Loading