Skip to content

Commit

Permalink
🔀 :: dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
leeseojune53 authored Jan 11, 2023
2 parents 194437e + 3e9b477 commit 94c7b52
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
Expand All @@ -36,14 +37,14 @@ public QueryNotificationListLatestResponse queryListLatest() {
@Operation(summary = "FCM 토큰 등록")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/token")
public void registerFcmToken(@RequestBody RegisterFcmTokenRequest request) {
public void registerFcmToken(@Valid @RequestBody RegisterFcmTokenRequest request) {
notificationService.registerFcmToken(request);
}

@Operation(summary = "즉시 푸쉬알림 발송")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public void sendInstance(@RequestBody SendInstanceRequest request) {
public void sendInstance(@Valid @RequestBody SendInstanceRequest request) {
notificationService.sendInstance(request);
}

Expand All @@ -69,21 +70,22 @@ public void deleteByNotificationId(
@PostMapping("/experience")
@DisableSecurity
public void sendInstanceToMeBeforeSignUp(
@RequestBody SendInstanceToMeBeforeSignUpRequest request) {
@Valid @RequestBody SendInstanceToMeBeforeSignUpRequest request) {
notificationService.sendInstanceToMeBeforeSignUp(request);
}

@Operation(summary = "예약 푸쉬알림 발송")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/reservation")
public void sendReservation(@RequestBody SendReservationRequest request) {
public void sendReservation(@Valid @RequestBody SendReservationRequest request) {
reservationService.sendReservation(request);
}

@Operation(summary = "예약 푸쉬알림 시간수정")
@ResponseStatus(HttpStatus.OK)
@PatchMapping("/reservation")
public void changeSendAtReservation(@RequestBody ChangeSendAtReservationRequest request) {
public void changeSendAtReservation(
@Valid @RequestBody ChangeSendAtReservationRequest request) {
reservationService.changeSendAtReservation(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import lombok.Getter;

@Getter
public class ChangeSendAtReservationRequest {
private Long reservationId;
@JsonFormat private LocalDateTime sendAt;
@NotNull private Long reservationId;
@Future @NotNull @JsonFormat private LocalDateTime sendAt;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.depromeet.knockknockbackend.domain.notification.presentation.dto.request;


import javax.validation.constraints.NotBlank;
import lombok.Getter;

@Getter
public class RegisterFcmTokenRequest {

private String deviceId;
private String token;
@NotBlank private String deviceId;
@NotBlank private String token;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.depromeet.knockknockbackend.domain.notification.presentation.dto.request;


import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Getter;

@Getter
public class SendInstanceRequest {

private Long groupId;
@NotNull private Long groupId;
private String title;
private String content;
@NotBlank private String content;
private String imageUrl;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.depromeet.knockknockbackend.domain.notification.presentation.dto.request;


import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import lombok.Getter;

@Getter
public class SendInstanceToMeBeforeSignUpRequest {

private String token;
private String content;
@NotBlank private String token;
@NotEmpty private String content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Getter;

@Getter
public class SendReservationRequest {
private Long groupId;
@NotNull private Long groupId;
private String title;
private String content;
@NotBlank private String content;
private String imageUrl;
@JsonFormat private LocalDateTime sendAt;
@Future @NotNull @JsonFormat private LocalDateTime sendAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -29,7 +30,7 @@ public class ReactionController {
@Operation(summary = "알림에 리액션 등록")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public void registerReaction(@RequestBody RegisterReactionRequest request) {
public void registerReaction(@Valid @RequestBody RegisterReactionRequest request) {
reactionService.registerReaction(request);
}

Expand All @@ -38,7 +39,7 @@ public void registerReaction(@RequestBody RegisterReactionRequest request) {
@PatchMapping("{notification_reaction_id}")
public void changeReaction(
@PathVariable("notification_reaction_id") Long notificationReactionId,
@RequestBody RegisterReactionRequest request) {
@Valid @RequestBody RegisterReactionRequest request) {
reactionService.changeReaction(notificationReactionId, request);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.depromeet.knockknockbackend.domain.reaction.presentation.dto.request;


import javax.validation.constraints.NotNull;
import lombok.Getter;

@Getter
public class RegisterReactionRequest {

private Long notificationId;
private Long reactionId;
@NotNull private Long notificationId;
@NotNull private Long reactionId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public List<Relation> findFriendList(Long userId) {
@Override
public Optional<Relation> findRelationBySendUserIdAndReceiveUserId(
Long sendUserId, Long receiveUserId) {
return Optional.of(
return Optional.ofNullable(
queryFactory
.selectFrom(relation)
.where(
relation.isFriend
.eq(false)
.and(friendPredicated(sendUserId, receiveUserId)))
.fetchFirst());
.fetchOne());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void saveNotificationToStorage(@PathVariable("notification_id") Long noti
@Operation(summary = "보관함에 저장한 푸쉬알림 삭제")
@ResponseStatus(HttpStatus.OK)
@DeleteMapping
public void deleteNotificationFromStorage(@RequestBody DeleteStorage request) {
public void deleteNotificationFromStorage(@Valid @RequestBody DeleteStorage request) {
storageService.deleteNotificationFromStorage(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@


import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Getter;

@Getter
public class DeleteStorage {
@Size(min = 1)
@NotNull
List<Long> storageIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.depromeet.knockknockbackend.global.error.exception.KnockException;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,35 +20,36 @@ public class ExceptionFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
throws IOException {
try {
filterChain.doFilter(request, response);
} catch (KnockException e) {
response.getWriter()
.write(
objectMapper.writeValueAsString(
getErrorResponse(
e.getErrorCode(), request.getRequestURL().toString())));
writeErrorResponse(response, e.getErrorCode(), request.getRequestURL().toString());
} catch (Exception e) {
if (e.getCause() instanceof KnockException) {
response.getWriter()
.write(
objectMapper.writeValueAsString(
getErrorResponse(
((KnockException) e.getCause()).getErrorCode(),
request.getRequestURL().toString())));
writeErrorResponse(
response,
((KnockException) e.getCause()).getErrorCode(),
request.getRequestURL().toString());
} else {
e.printStackTrace();
getErrorResponse(
ErrorCode.INTERNAL_SERVER_ERROR, request.getRequestURL().toString());
writeErrorResponse(
response,
ErrorCode.INTERNAL_SERVER_ERROR,
request.getRequestURL().toString());
}
} finally {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
}
}

private ErrorResponse getErrorResponse(ErrorCode errorCode, String path) {
return new ErrorResponse(
errorCode.getStatus(), errorCode.getCode(), errorCode.getReason(), path);
private void writeErrorResponse(HttpServletResponse response, ErrorCode errorCode, String path)
throws IOException {
ErrorResponse errorResponse =
new ErrorResponse(
errorCode.getStatus(), errorCode.getCode(), errorCode.getReason(), path);

response.setStatus(errorCode.getStatus());
response.setCharacterEncoding("UTF-8");
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
}
}

0 comments on commit 94c7b52

Please sign in to comment.