Skip to content

Commit

Permalink
Merge branch 'feat/Step3-kakao-tech-campus#112-testcode' of https://g…
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-mae committed Nov 9, 2023
2 parents c876c09 + 7b51281 commit ad3a154
Show file tree
Hide file tree
Showing 62 changed files with 987 additions and 479 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified src/.DS_Store
Binary file not shown.
Binary file modified src/main/.DS_Store
Binary file not shown.
Binary file modified src/main/java/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/example/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/example/tily/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions src/main/java/com/example/tily/TiLyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ private Roadmap newIndividualRoadmap(User creator, Category category, String nam
.category(category)
.name(name)
.stepNum(stepNum)
.isPublic(false)
.isRecruit(false)
.build();
}

Expand All @@ -187,6 +189,8 @@ public Roadmap newTilyRoadmap(User creator, Category category, String name, Stri
.currentNum(currentNum)
.stepNum(stepNum)
.image(image)
.isPublic(false)
.isRecruit(false)
.build();
}

Expand Down
Binary file modified src/main/java/com/example/tily/_core/.DS_Store
Binary file not shown.
39 changes: 33 additions & 6 deletions src/main/java/com/example/tily/_core/S3/S3Config.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.example.tily._core.S3;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
public class S3Config {
Expand All @@ -19,17 +22,41 @@ public class S3Config {
@Value("${cloud.aws.region.static}")
private String region;

@Value("krmp-proxy.9rum.cc")
private String proxyHost;

@Value("3128")
private int proxyPort;


@Bean
@Profile({"local", "prod"})
public AmazonS3Client amazonS3Client() {
BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey);
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
return (AmazonS3Client) AmazonS3ClientBuilder
.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.build();
}
}

/*
S3 설정 레퍼런스
https://velog.io/@msung99/AWS-SpringBoot-AWS-S3-에-다중-파일-업로드-API-구현-feat.-Spring-Cloud-AWS
*/
@Bean
@Profile("deploy")
public AmazonS3Client amazonS3ClientForDeploy() {
BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey);

ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionTimeout(60000); // 연결 타임아웃 시간 60000ms = 60s 설정
clientConfiguration.setSocketTimeout(60000); // 소켓 타임아웃 시간 60000ms = 60s 설정
clientConfiguration.setProxyHost(proxyHost);
clientConfiguration.setProxyPort(proxyPort);
clientConfiguration.setProxyProtocol(Protocol.HTTP);

return (AmazonS3Client) AmazonS3ClientBuilder
.standard()
.withRegion(region)
.withClientConfiguration(clientConfiguration)
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum ExceptionCode {

// til 관련 에러
TIL_ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 til을 생성할 권한이 없습니다."),
TIL_STEP_EXIST(HttpStatus.BAD_REQUEST, "이미 step에 대한 til이 존재합니다."),
TIL_STEP_EXIST(HttpStatus.BAD_REQUEST, "해당 step에 대한 til이 이미 존재합니다."),
TIL_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 til을 찾을 수 없습니다"),
TIL_UPDATE_FORBIDDEN(HttpStatus.FORBIDDEN, "til을 저장할 권한이 없습니다."),
TIL_CONTENT_NULL(HttpStatus.BAD_REQUEST, "til의 내용을 입력해주세요."),
Expand All @@ -33,12 +33,13 @@ public enum ExceptionCode {
TIL_ALREADY_SUBMIT(HttpStatus.BAD_REQUEST, "이미 til을 제출하였습니다."),
TIL_DELETE_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 til을 삭제할 권한이 없습니다."),
TIL_END_DUEDATE(HttpStatus.BAD_REQUEST, "제출 시간이 지나 til을 제출할 수 없습니다."),
TIL_FORBIDDEN(HttpStatus.FORBIDDEN, "til에 대한 권한이 없습니다."),

// roadmap 관련 에러
ROADMAP_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 roadmap을 찾을 수 없습니다."),
ROADMAP_NOT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드냅에 속하지 않았습니다."),
ROADMAP_NOT_BELONG(HttpStatus.NOT_FOUND, "해당 reoadmap에 속하지 않습니다."),
ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 roadmap을 조회할 권한이 없습니다."),
ROADMAP_NOT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 속하지 않았습니다."),
ROADMAP_NOT_BELONG(HttpStatus.FORBIDDEN, "해당 reoadmap에 속하지 않습니다."),
ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 roadmap에 접근할 권한이 없습니다."),
ROADMAP_SUBMIT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 til을 제출할 권한이 없습니다."),
ROADMAP_ALREADY_APPLY(HttpStatus.BAD_REQUEST, "해당 로드맵에 이미 신청했습니다."),
ROADMAP_REJECT(HttpStatus.BAD_REQUEST, "로드맵 신청이 거절되었습니다."),
Expand All @@ -50,7 +51,7 @@ public enum ExceptionCode {
// step 관련 에러
STEP_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 step을 찾을 수 없습니다."),
STEP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 step을 조회할 권한이 없습니다."),
STEP_NOT_INCLUDE(HttpStatus.BAD_REQUEST, "해당 step은 roadmap에 속하지 않았습니다."),
STEP_NOT_BELONG(HttpStatus.BAD_REQUEST, "해당 step은 roadmap에 속하지 않았습니다."),
STEP_ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 step을 생성할 권한이 없습니다."),

// comment 관련 에러
Expand All @@ -65,6 +66,7 @@ public enum ExceptionCode {

// reference 관련 에러
REFERENCE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 reference를 찾을 수 없습니다."),
REFERENCE_DELETE_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 reference를 삭제할 권한이 없습니다"),

// image 관련 에러
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 image를 찰을 수 없습니다."),
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/example/tily/_core/utils/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public static <T> ApiResult<T> success(T result) {
return new ApiResult<>(true, 200, "ok", result);
}

public static <T> ApiResult<T> success(HttpStatus httpStatus, T result) {
return new ApiResult<>(true, httpStatus.value(), httpStatus.getReasonPhrase(), result);
}

public static ApiResult<?> error(String message, HttpStatus httpStatus) {
return new ApiResult<>(false, httpStatus.value(), message, null);
}
Expand All @@ -23,10 +27,4 @@ public static class ApiResult<T> {
private final String message;
private final T result;
}

// @Getter @Setter @AllArgsConstructor
// public static class ApiError {
// private final String message;
// private final int status;
// }
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/tily/alarm/Alarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public class Alarm extends BaseTimeEntity {
private Comment comment;

@Column
private Boolean isRead;
private boolean isRead;

@Builder
public Alarm(Til til, User receiver, Comment comment, Boolean isRead) {
public Alarm(Til til, User receiver, Comment comment, boolean isRead) {
this.til = til;
this.receiver = receiver;
this.comment = comment;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/example/tily/alarm/AlarmController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class AlarmController {

private final AlarmService alarmService;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/example/tily/alarm/AlarmResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public SenderDTO(User user){

public record AlarmDTO(Long id,
Long tilId,
Boolean isRead,
boolean isRead,
String createDate,
RoadmapDTO roadmap,
StepDTO step,
Expand All @@ -37,7 +37,7 @@ public record AlarmDTO(Long id,
public AlarmDTO(Alarm alarm){
this(alarm.getId(),
alarm.getTil().getId(),
alarm.getIsRead(),
alarm.isRead(),
alarm.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
new RoadmapDTO(alarm.getTil().getRoadmap()),
new StepDTO(alarm.getTil().getStep()),
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/example/tily/comment/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name="comment_tb")
@SQLDelete(sql = "UPDATE comment_tb SET is_deleted = true WHERE id = ?")
@Where(clause = "is_deleted = false")
public class Comment extends BaseTimeEntity {

@Id
Expand All @@ -30,9 +34,11 @@ public class Comment extends BaseTimeEntity {
@JoinColumn(name="writer_id")
private User writer;

@Column(columnDefinition="TEXT", length = 1000)
private String content;


@Column
private boolean isDeleted = false;

@Builder
public Comment (Long id, Roadmap roadmap, Step step, Til til, User writer, String content) {
Expand Down
27 changes: 11 additions & 16 deletions src/main/java/com/example/tily/comment/CommentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,31 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class CommentController {

private final CommentService commentService;

@PostMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}/comments")
public ResponseEntity<?> createComment(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId") Long stepId,
@PathVariable("tilId") Long tilId ,
@RequestBody @Valid CommentRequest.CreateCommentDTO requestDTO,
@PostMapping("/comments")
public ResponseEntity<?> createComment(@RequestBody @Valid CommentRequest.CreateCommentDTO requestDTO,
@AuthenticationPrincipal CustomUserDetails userDetails) {
CommentResponse.CreateCommentDTO responseDTO = commentService.createComment(requestDTO,
roadmapId, stepId, tilId, userDetails.getUser());
CommentResponse.CreateCommentDTO responseDTO = commentService.createComment(requestDTO, userDetails.getUser());

return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

@PatchMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}/comments/{commentId}")
public ResponseEntity<?> updateComment(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId") Long stepId,
@PathVariable("tilId") Long tilId, @PathVariable("commentId") Long commentId,
@RequestBody @Valid CommentRequest.UpdateCommentDTO requestDTO,
@AuthenticationPrincipal CustomUserDetails userDetails) {
commentService.updateComment(requestDTO, commentId, userDetails.getUser());
@PatchMapping("/comments/{id}")
public ResponseEntity<?> updateComment(@PathVariable("id") Long id, @RequestBody @Valid CommentRequest.UpdateCommentDTO requestDTO,
@AuthenticationPrincipal CustomUserDetails userDetails) {
commentService.updateComment(requestDTO, id, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}

@DeleteMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}/comments/{commentId}")
public ResponseEntity<?> deleteComment(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId")Long stepId,
@PathVariable("tilId") Long tilId, @PathVariable("commentId") Long commentId,
@DeleteMapping("/comments/{id}")
public ResponseEntity<?> deleteComment(@PathVariable("id") Long id,
@AuthenticationPrincipal CustomUserDetails userDetails) {

commentService.deleteComment(commentId, userDetails.getUser());
commentService.deleteComment(id, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/example/tily/comment/CommentRepository.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.tily.comment;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

Expand All @@ -10,4 +11,16 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {

@Query("select c from Comment c join fetch c.writer where c.til.id=:tilId")
List<Comment> findByTilId(@Param("tilId") Long tilId);

@Modifying
@Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id = :commentId")
void softDeleteCommentById(Long commentId);

@Modifying
@Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id = :tilId")
void softDeleteCommentsByTilId(Long tilId);

@Modifying
@Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id IN :tilIds")
void softDeleteCommentsByTilIds(List<Long> tilIds);
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/tily/comment/CommentRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class CommentRequest {

public record CreateCommentDTO(@NotBlank(message = "댓글 내용을 입력해주세요.") String content) {
public record CreateCommentDTO(Long roadmapId, Long stepId, Long tilId, @NotBlank(message = "댓글 내용을 입력해주세요.") String content) {
}

public record UpdateCommentDTO(@NotBlank(message = "댓글 내용을 입력해주세요.") String content) {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/example/tily/comment/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public class CommentService {
private final AlarmRepository alarmRepository;

@Transactional
public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateCommentDTO requestDTO,
Long roadmapId, Long stepId, Long tilId, User user) {
public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateCommentDTO requestDTO, User user) {
Long roadmapId = requestDTO.roadmapId();
Long stepId = requestDTO.stepId();
Long tilId = requestDTO.tilId();

Roadmap roadmap = roadmapRepository.findById(roadmapId)
.orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND));
Expand Down Expand Up @@ -69,11 +71,11 @@ public void deleteComment(Long id, User user) {
Comment comment = commentRepository.findById(id)
.orElseThrow(() -> new CustomException(ExceptionCode.COMMENT_NOT_FOUND));

// 댓글 주인 또는 글의 주인만 댓글 삭제 가능
if(!comment.getWriter().getId().equals(user.getId()) || !comment.getTil().getWriter().getId().equals(user.getId()))
// 댓글 주인이 아니고 글의 주인도 아니라면 삭제 불가
if(!comment.getWriter().getId().equals(user.getId()) && !comment.getTil().getWriter().getId().equals(user.getId()))
throw new CustomException(ExceptionCode.COMMENT_DELETE_FORBIDDEN);

alarmRepository.deleteByCommentId(id);
commentRepository.deleteById(id);
commentRepository.softDeleteCommentById(id);
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/example/tily/image/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ public class Image {
@Id
@GeneratedValue
private Long id;

@Column
private String originalImageName;

@Column
private String storageImageName;

@Column
private String imagePath;

public Image(String originalImageName, String storageImageName, String imagePath) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/example/tily/image/ImageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class ImageController {
final private ImageService imageService;

// 폴더 별로 관리 하기 위해 나눔(user, roadmap, post)
@GetMapping("/user/{userId}/image")
@GetMapping("/images/users/{userId}")
public ResponseEntity<?> findUserImage(@PathVariable Long userId){
ImageResponse.UserImageDTO responseDTO = imageService.findUserImage(userId);

return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

@PostMapping("/user/{userId}/image")
@PostMapping("/images/users/{userId}")
public ResponseEntity<?> uploadUserImage(@PathVariable Long userId, @RequestParam("image") MultipartFile file,
@AuthenticationPrincipal CustomUserDetails userDetails) {

Expand All @@ -30,14 +31,14 @@ public ResponseEntity<?> uploadUserImage(@PathVariable Long userId, @RequestPara
return ResponseEntity.ok().body(ApiUtils.success(null));
}

@GetMapping("/roadmap/{roadmapId}/image")
@GetMapping("/images/roadmaps/{roadmapId}")
public ResponseEntity<?> findRoadmapImage(@PathVariable Long roadmapId){
ImageResponse.RoadmapImageDTO responseDTO = imageService.findRoadmapImage(roadmapId);

return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

@PostMapping("/roadmap/{roadmapId}/image")
@PostMapping("/images/roadmaps/{roadmapId}")
public ResponseEntity<?> uploadRoadmapImage(@PathVariable Long roadmapId,
@RequestParam("image") MultipartFile file) {

Expand All @@ -46,7 +47,7 @@ public ResponseEntity<?> uploadRoadmapImage(@PathVariable Long roadmapId,
return ResponseEntity.ok().body(ApiUtils.success(null));
}

@PostMapping("/image/post")
@PostMapping("/images/write")
public ResponseEntity<?> postImage(@RequestParam("image") MultipartFile file){
ImageResponse.PostImageDTO responseDTO = imageService.postImage(file);

Expand Down
Loading

0 comments on commit ad3a154

Please sign in to comment.