-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
232 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 36 additions & 7 deletions
43
linkmind/src/main/java/com/app/toaster/controller/ToastController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,62 @@ | ||
package com.app.toaster.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.app.toaster.common.dto.ApiResponse; | ||
import com.app.toaster.config.UserId; | ||
// import com.app.toaster.config.UserId; | ||
import com.app.toaster.controller.request.toast.IsReadDto; | ||
import com.app.toaster.controller.request.toast.SaveToastDto; | ||
import com.app.toaster.controller.response.auth.SignInResponseDto; | ||
import com.app.toaster.controller.response.toast.IsReadResponse; | ||
import com.app.toaster.exception.Success; | ||
import com.app.toaster.service.toast.ToastService; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/toast") | ||
@Validated | ||
public class ToastController { | ||
private final ToastService toastService; | ||
|
||
@PostMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
@PostMapping("/save") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ApiResponse createToast( | ||
@UserId Long userId, | ||
SaveToastDto requestDto | ||
@RequestHeader("userId") Long userId, | ||
@RequestBody @Valid SaveToastDto requestDto | ||
) { | ||
toastService.createToast(userId, requestDto); | ||
return ApiResponse.success(Success.CREATE_TOAST_SUCCESS, Success.CREATE_TOAST_SUCCESS.getMessage()); | ||
return ApiResponse.success(Success.CREATE_TOAST_SUCCESS); | ||
} | ||
|
||
@PatchMapping("/is-read") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse<IsReadResponse> updateIsRead( | ||
@RequestHeader("userId") Long userId, | ||
@RequestBody IsReadDto requestDto | ||
){ | ||
return ApiResponse.success(Success.UPDATE_ISREAD_SUCCESS, toastService.readToast(userId,requestDto)); | ||
} | ||
|
||
@DeleteMapping("/delete") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse deleteToast( //나중에 softDelete로 변경 | ||
@RequestHeader("userId") Long userId, | ||
@RequestParam Long toastId | ||
) { | ||
toastService.deleteToast(userId, toastId); | ||
return ApiResponse.success(Success.DELETE_TOAST_SUCCESS); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
linkmind/src/main/java/com/app/toaster/controller/request/toast/DeleteToastDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.app.toaster.controller.request.toast; | ||
|
||
public record DeleteToastDto(Long toastId) { | ||
} |
4 changes: 4 additions & 0 deletions
4
linkmind/src/main/java/com/app/toaster/controller/request/toast/IsReadDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.app.toaster.controller.request.toast; | ||
|
||
public record IsReadDto(Long toastId, Boolean isRead) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
linkmind/src/main/java/com/app/toaster/controller/response/toast/IsReadResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.app.toaster.controller.response.toast; | ||
|
||
public record IsReadResponse(Boolean isRead) { | ||
public static IsReadResponse of(Boolean isRead){ | ||
return new IsReadResponse(isRead); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
linkmind/src/main/java/com/app/toaster/controller/valid/Severity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.app.toaster.controller.valid; | ||
|
||
import jakarta.validation.Payload; | ||
|
||
public class Severity { | ||
public static class Info implements Payload {}; | ||
public static class Error implements Payload {}; | ||
} |
20 changes: 20 additions & 0 deletions
20
linkmind/src/main/java/com/app/toaster/controller/valid/TitleValid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.app.toaster.controller.valid; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.util.ArrayList; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
@Documented | ||
@Constraint(validatedBy = TitleValidator.class) | ||
@Target({java.lang.annotation.ElementType.FIELD}) | ||
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) | ||
public @interface TitleValid { | ||
String message() default "Invalid title"; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
String pattern() default "[가-힣|a-z|A-Z|0-9|]"; | ||
} |
39 changes: 39 additions & 0 deletions
39
linkmind/src/main/java/com/app/toaster/controller/valid/TitleValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.app.toaster.controller.valid; | ||
|
||
|
||
import com.app.toaster.exception.Error; | ||
import com.app.toaster.exception.model.CustomException; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
public class TitleValidator implements ConstraintValidator<TitleValid, String> { | ||
|
||
public String pattern; | ||
@Override | ||
public void initialize(TitleValid constraintAnnotation) { | ||
this.pattern = constraintAnnotation.pattern(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(String title, ConstraintValidatorContext context) { | ||
System.out.println("여기는 오는건가"); | ||
context.disableDefaultConstraintViolation(); | ||
// 커스텀 예외를 던집니다. | ||
// null, 공백으로만 이뤄지는 경우, 빈 값인 경우 '' | ||
if (title.isBlank()) { | ||
context.buildConstraintViolationWithTemplate("제목이 공백으로만 차있습니다.") | ||
.addConstraintViolation(); | ||
return false; | ||
} | ||
// 길이가 1보다 작거나 10보다 큰 경우 | ||
if (title.isEmpty()) { | ||
context.buildConstraintViolationWithTemplate("제목이 비어있습니다. ") | ||
.addConstraintViolation(); | ||
return false; | ||
} | ||
|
||
// 첫 글자가 공백인 경우 | ||
return !(title.charAt(0) == ' '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
linkmind/src/main/java/com/app/toaster/exception/model/BadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.app.toaster.exception.model; | ||
|
||
import com.app.toaster.exception.Error; | ||
|
||
public class BadRequestException extends CustomException{ | ||
public BadRequestException(Error error, String message) { | ||
super(error, message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
linkmind/src/main/java/com/app/toaster/infrastructure/CategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.