Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#122
Browse files Browse the repository at this point in the history
  • Loading branch information
rladmstn committed Oct 29, 2024
2 parents 6123b3f + 21ae5c5 commit 743d2f0
Show file tree
Hide file tree
Showing 31 changed files with 439 additions and 244 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/gamzabat/algohub/AlgohubApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class AlgohubApplication {

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/gamzabat/algohub/common/DateFormatUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gamzabat.algohub.common;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public final class DateFormatUtil {
public static String formatDate(LocalDate date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
return date.format(formatter);
}

public static String formatDateTime(LocalDateTime dateTime) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss");
return dateTime.format(formatter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,96 +23,96 @@
@ControllerAdvice
public class CustomExceptionHandler {
@ExceptionHandler(RequestException.class)
protected ResponseEntity<Object> handler(RequestException e) {
protected ResponseEntity<ErrorResponse> handler(RequestException e) {
return ResponseEntity.badRequest()
.body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getError(), e.getMessages()));
}

@ExceptionHandler(UserValidationException.class)
protected ResponseEntity<Object> handler(UserValidationException e) {
protected ResponseEntity<ErrorResponse> handler(UserValidationException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getErrors(), null));
}

@ExceptionHandler(StudyGroupValidationException.class)
protected ResponseEntity<Object> handler(StudyGroupValidationException e) {
protected ResponseEntity<ErrorResponse> handler(StudyGroupValidationException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(GroupMemberValidationException.class)
protected ResponseEntity<Object> handler(GroupMemberValidationException e) {
protected ResponseEntity<ErrorResponse> handler(GroupMemberValidationException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(ProblemValidationException.class)
protected ResponseEntity<Object> handler(ProblemValidationException e) {
protected ResponseEntity<ErrorResponse> handler(ProblemValidationException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(UncorrectedPasswordException.class)
protected ResponseEntity<Object> handler(UncorrectedPasswordException e) {
protected ResponseEntity<ErrorResponse> handler(UncorrectedPasswordException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getErrors(), null));
}

@ExceptionHandler(SolutionValidationException.class)
protected ResponseEntity<Object> handler(SolutionValidationException e) {
protected ResponseEntity<ErrorResponse> handler(SolutionValidationException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getError(), null));
}

@ExceptionHandler(CommentValidationException.class)
protected ResponseEntity<Object> handler(CommentValidationException e) {
protected ResponseEntity<ErrorResponse> handler(CommentValidationException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(CannotFoundGroupException.class)
protected ResponseEntity<Object> handler(CannotFoundGroupException e) {
protected ResponseEntity<ErrorResponse> handler(CannotFoundGroupException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new ErrorResponse(HttpStatus.NOT_FOUND.value(), e.getErrors(), null));
}

@ExceptionHandler(NotBojLinkException.class)
protected ResponseEntity<Object> handler(NotBojLinkException e) {
protected ResponseEntity<ErrorResponse> handler(NotBojLinkException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getError(), null));
}

@ExceptionHandler(CannotFoundSolutionException.class)
protected ResponseEntity<Object> handler(CannotFoundSolutionException e) {
protected ResponseEntity<ErrorResponse> handler(CannotFoundSolutionException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getErrors(), null));
}

@ExceptionHandler(InvalidRoleException.class)
protected ResponseEntity<Object> handler(InvalidRoleException e) {
protected ResponseEntity<ErrorResponse> handler(InvalidRoleException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getError(), null));
}

@ExceptionHandler(CheckBjNicknameValidationException.class)
protected ResponseEntity<Object> handler(CheckBjNicknameValidationException e) {
protected ResponseEntity<ErrorResponse> handler(CheckBjNicknameValidationException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(BOJServerErrorException.class)
protected ResponseEntity<Object> handler(BOJServerErrorException e) {
protected ResponseEntity<ErrorResponse> handler(BOJServerErrorException e) {
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
.body(new ErrorResponse(HttpStatus.SERVICE_UNAVAILABLE.value(), e.getError(), null));
}

@ExceptionHandler(SolvedAcApiErrorException.class)
protected ResponseEntity<Object> handler(SolvedAcApiErrorException e) {
protected ResponseEntity<ErrorResponse> handler(SolvedAcApiErrorException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(BoardValidationExceoption.class)
protected ResponseEntity<Object> handler(BoardValidationExceoption e) {
protected ResponseEntity<ErrorResponse> handler(BoardValidationExceoption e) {
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
.body(new ErrorResponse(HttpStatus.SERVICE_UNAVAILABLE.value(), e.getError(), null));
}

@ExceptionHandler(CheckNicknameValidationException.class)
protected ResponseEntity<Object> handler(CheckNicknameValidationException e) {
protected ResponseEntity<ErrorResponse> handler(CheckNicknameValidationException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(CannotFoundProblemException.class)
protected ResponseEntity<Object> handler(CannotFoundProblemException e) {
protected ResponseEntity<ErrorResponse> handler(CannotFoundProblemException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getErrors(), null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public class BoardController {

@PostMapping
@Operation(summary = "공지 작성API")
public ResponseEntity<String> createBoard(@AuthedUser User user, @Valid @RequestBody CreateBoardRequest request,
public ResponseEntity<Void> createBoard(@AuthedUser User user, @Valid @RequestBody CreateBoardRequest request,
Errors errors) {
if (errors.hasErrors())
throw new RequestException("올바르지 않은 공지 생성 요청입니다", errors);
boardService.createBoard(user, request);
return ResponseEntity.ok().body("OK");
return ResponseEntity.ok().build();
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gamzabat.algohub.feature.board.dto;

import java.time.LocalDateTime;

import com.gamzabat.algohub.common.DateFormatUtil;
import com.gamzabat.algohub.feature.board.domain.Board;

import lombok.Builder;
Expand All @@ -11,15 +10,15 @@ public record GetBoardResponse(String author,
Long boardId,
String boardContent,
String boardTitle,
LocalDateTime createAt) {
String createAt) {

public static GetBoardResponse toDTO(Board board) {
return GetBoardResponse.builder()
.author(board.getAuthor().getNickname())
.boardId(board.getId())
.boardTitle(board.getTitle())
.boardContent(board.getContent())
.createAt(board.getCreatedAt())
.createAt(DateFormatUtil.formatDate(board.getCreatedAt().toLocalDate()))
.build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gamzabat.algohub.common.DateFormatUtil;
import com.gamzabat.algohub.common.annotation.AuthedUser;
import com.gamzabat.algohub.exception.StudyGroupValidationException;
import com.gamzabat.algohub.exception.UserValidationException;
Expand Down Expand Up @@ -71,7 +72,7 @@ public GetBoardResponse getBoard(@AuthedUser User user, Long boardId) {
.boardId(board.getId())
.boardTitle(board.getTitle())
.boardContent(board.getContent())
.createAt(board.getCreatedAt())
.createAt(DateFormatUtil.formatDate(board.getCreatedAt().toLocalDate()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class CommentController {

@PostMapping
@Operation(summary = "댓글 작성 API")
public ResponseEntity<Object> createComment(@AuthedUser User user,
public ResponseEntity<Void> createComment(@AuthedUser User user,
@Valid @RequestBody CreateCommentRequest request, Errors errors) {
if (errors.hasErrors())
throw new RequestException("댓글 작성 요청이 올바르지 않습니다.", errors);
commentService.createComment(user, request);
return ResponseEntity.ok().body("OK");
return ResponseEntity.ok().build();
}

@GetMapping
Expand All @@ -53,18 +53,18 @@ public ResponseEntity<List<GetCommentResponse>> getCommentList(@AuthedUser User

@DeleteMapping
@Operation(summary = "댓글 삭제 API")
public ResponseEntity<Object> deleteComment(@AuthedUser User user, @RequestParam Long commentId) {
public ResponseEntity<Void> deleteComment(@AuthedUser User user, @RequestParam Long commentId) {
commentService.deleteComment(user, commentId);
return ResponseEntity.ok().body("OK");
return ResponseEntity.ok().build();
}

@PutMapping
@Operation(summary = "댓글 수정 API")
public ResponseEntity<String> modifyComment(@AuthedUser User user,
public ResponseEntity<Void> modifyComment(@AuthedUser User user,
@Valid @RequestBody UpdateCommentRequest request, Errors errors) {
if (errors.hasErrors())
throw new RequestException("수정 요청이 올바르지 않습니다", errors);
commentService.updateComment(user, request);
return ResponseEntity.ok().body("OK");
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gamzabat.algohub.feature.comment.dto;

import java.time.LocalDateTime;

import com.gamzabat.algohub.common.DateFormatUtil;
import com.gamzabat.algohub.feature.comment.domain.Comment;

import lombok.Builder;
Expand All @@ -11,14 +10,14 @@ public record GetCommentResponse(Long commentId,
String writerNickname,
String writerProfileImage,
String content,
LocalDateTime createdAt) {
String createdAt) {
public static GetCommentResponse toDTO(Comment comment) {
return GetCommentResponse.builder()
.commentId(comment.getId())
.writerNickname(comment.getUser().getNickname())
.writerProfileImage(comment.getUser().getProfileImage())
.content(comment.getContent())
.createdAt(comment.getCreatedAt())
.createdAt(DateFormatUtil.formatDate(comment.getCreatedAt().toLocalDate()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.gamzabat.algohub.feature.notification.dto;

import java.time.LocalDateTime;

import com.gamzabat.algohub.common.DateFormatUtil;
import com.gamzabat.algohub.feature.notification.domain.Notification;

public record GetNotificationResponse(Long id,
String groupName,
String groupImage,
String message,
String subContent,
LocalDateTime createdAt,
String createdAt,
boolean isRead) {
public static GetNotificationResponse toDTO(Notification notification) {
return new GetNotificationResponse(
Expand All @@ -18,7 +17,7 @@ public static GetNotificationResponse toDTO(Notification notification) {
notification.getStudyGroup().getGroupImage(),
notification.getMessage(),
notification.getSubContent(),
notification.getCreatedAt(),
DateFormatUtil.formatDate(notification.getCreatedAt().toLocalDate()),
notification.isRead()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gamzabat.algohub.feature.notification.enums;

public enum NotificationMessage {
PROBLEM_STARTED("[%s] 문제가 시작되었습니다! 지금 도전해보세요!");

private final String message;

NotificationMessage(String message) {
this.message = message;
}

public String format(String... args) {
return String.format(message, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ public class ProblemController {

@PostMapping
@Operation(summary = "문제 생성 API")
public ResponseEntity<Object> createProblem(@AuthedUser User user,
public ResponseEntity<Void> createProblem(@AuthedUser User user,
@Valid @RequestBody CreateProblemRequest request, Errors errors) {
if (errors.hasErrors())
throw new RequestException("문제 생성 요청이 올바르지 않습니다.", errors);
problemService.createProblem(user, request);
return ResponseEntity.ok().body("OK");
return ResponseEntity.ok().build();
}

@PatchMapping
@Operation(summary = "문제 마감 기한 수정 API")
public ResponseEntity<Object> editProblemDeadline(@AuthedUser User user,
public ResponseEntity<Void> editProblemDeadline(@AuthedUser User user,
@Valid @RequestBody EditProblemRequest request, Errors errors) {
if (errors.hasErrors())
throw new RequestException("문제 마감 기한 수정 요청이 올바르지 않습니다.", errors);
problemService.editProblem(user, request);
return ResponseEntity.ok().body("OK");
return ResponseEntity.ok().build();
}

@GetMapping
Expand Down Expand Up @@ -84,8 +84,8 @@ public ResponseEntity<List<GetProblemResponse>> getQueuedProblemList(@AuthedUser

@DeleteMapping
@Operation(summary = "문제 삭제 API")
public ResponseEntity<Object> deleteProblem(@AuthedUser User user, @RequestParam Long problemId) {
public ResponseEntity<Void> deleteProblem(@AuthedUser User user, @RequestParam Long problemId) {
problemService.deleteProblem(user, problemId);
return ResponseEntity.ok().body("OK");
return ResponseEntity.ok().build();
}
}
Loading

0 comments on commit 743d2f0

Please sign in to comment.