Skip to content

Commit

Permalink
Merge pull request #230 from Link-MIND/test
Browse files Browse the repository at this point in the history
[Merge] ํ† ์ŠคํŠธ ์ œ๋ชฉ ๋ณ€๊ฒฝ API
  • Loading branch information
sss4920 authored Feb 20, 2024
2 parents 4c431b4 + dc7b889 commit 90ffa18
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.util.List;

import com.app.toaster.controller.request.toast.UpdateToastDto;
import com.app.toaster.controller.response.toast.ModifiedTitle;
import com.app.toaster.controller.response.toast.WeekLinkDto;
import com.app.toaster.service.link.LinkService;
import org.springframework.http.HttpStatus;
Expand All @@ -28,6 +30,7 @@
import com.app.toaster.service.parse.ParsingService;
import com.app.toaster.service.toast.ToastService;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

@RestController
Expand Down Expand Up @@ -86,6 +89,14 @@ public ApiResponse<List<WeekLinkDto>> getWeekLinks(
return ApiResponse.success(Success.GET_LINKS_SUCCESS, linkService.getWeekLinks());
}

@PatchMapping("/title")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<ModifiedTitle> modifyTitle(
@UserId Long userId,
@Valid @RequestBody UpdateToastDto updateToastDto
){
return ApiResponse.success(Success.UPDATE_TOAST_TITLE_SUCCESS, toastService.modifyTitle(userId,updateToastDto));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.app.toaster.controller.request.toast;

import com.app.toaster.controller.valid.Severity;
import com.app.toaster.controller.valid.TitleValid;

import jakarta.validation.constraints.NotNull;

public record UpdateToastDto(Long toastId, @TitleValid(payload = Severity.Error.class) @NotNull String title) {
public static UpdateToastDto of(Long toastId, String title){
return new UpdateToastDto(toastId,title);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.app.toaster.controller.response.toast;

public record ModifiedTitle(String updatedTitle) {
public static ModifiedTitle of(String updatedTitle){
return new ModifiedTitle(updatedTitle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum Error {
* 400 BAD REQUEST EXCEPTION
*/
BAD_REQUEST_ISREAD(HttpStatus.BAD_REQUEST, "isRead ๊ฐ’์ด ์ž˜๋ชป์š”์ฒญ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
BAD_REQUEST_ID(HttpStatus.BAD_REQUEST, "์ž˜๋ชป๋œ id๊ฐ’์ž…๋‹ˆ๋‹ค."),
BAD_REQUEST_VALIDATION(HttpStatus.BAD_REQUEST, "์œ ํšจํ•œ ๊ฐ’์œผ๋กœ ์š”์ฒญ์„ ๋‹ค์‹œ ๋ณด๋‚ด์ฃผ์„ธ์š”."),
BAD_REQUEST_FILE_EXTENSION(HttpStatus.BAD_REQUEST, "ํŒŒ์ผํ˜•์‹์ด ์ž˜๋ชป๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค."),
BAD_REQUEST_FILE_SIZE(HttpStatus.BAD_REQUEST, "ํŒŒ์ผํฌ๊ธฐ๊ฐ€ ์ž˜๋ชป๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ตœ๋Œ€ 5MB"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum Success {
SEARCH_SUCCESS(HttpStatus.OK, "๊ฒ€์ƒ‰ ์„ฑ๊ณต"),
PARSING_OG_SUCCESS(HttpStatus.OK, "og ๋ฐ์ดํ„ฐ ํŒŒ์‹ฑ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค. ํฌ๋กค๋ง์„ ๋ง‰์€ ํŽ˜์ด์ง€๋Š” ๊ธฐ๋ณธ์ด๋ฏธ์ง€๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค."),
UPDATE_PUSH_ALLOWED_SUCCESS(HttpStatus.OK, "ํ‘ธ์‹œ์•Œ๋ฆผ ์ˆ˜์ • ์„ฑ๊ณต"),
UPDATE_TOAST_TITLE_SUCCESS(HttpStatus.OK, "ํ† ์ŠคํŠธ ์ œ๋ชฉ ์ˆ˜์ • ์„ฑ๊ณต"),

UPDATE_ISREAD_SUCCESS(HttpStatus.OK, "์—ด๋žŒ์—ฌ๋ถ€ ์ˆ˜์ • ์™„๋ฃŒ"),
UPDATE_CATEGORY_TITLE_SUCCESS(HttpStatus.OK, "์นดํ…Œ๊ณ ๋ฆฌ ์ˆ˜์ • ์™„๋ฃŒ"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.springframework.transaction.annotation.Transactional;
import com.app.toaster.controller.request.toast.IsReadDto;
import com.app.toaster.controller.request.toast.SaveToastDto;
import com.app.toaster.controller.request.toast.UpdateToastDto;
import com.app.toaster.controller.response.parse.OgResponse;
import com.app.toaster.controller.response.toast.IsReadResponse;
import com.app.toaster.controller.response.toast.ModifiedTitle;
import com.app.toaster.domain.Category;
import com.app.toaster.domain.Toast;
import com.app.toaster.domain.User;
Expand Down Expand Up @@ -131,7 +133,23 @@ public void deleteAllToast(User user) throws IOException {
// s3Service.deleteImages(imageKeyList);
toastRepository.deleteAllById(toasts.stream().map(
(Toast::getId)).collect(Collectors.toList()));
}
}

@Transactional
public ModifiedTitle modifyTitle(Long userId, UpdateToastDto updateToastDto){
User presentUser = userRepository.findByUserId(userId).orElseThrow(
()-> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage())
);
Toast toast = toastRepository.findById(updateToastDto.toastId()).orElseThrow(
() -> new BadRequestException(Error.BAD_REQUEST_ID, Error.BAD_REQUEST_ID.getMessage())
);
if (!presentUser.equals(toast.getUser())){
throw new ForbiddenException(Error.UNAUTHORIZED_ACCESS, Error.UNAUTHORIZED_ACCESS.getMessage());
}
toast.updateTitle(updateToastDto.title());
return ModifiedTitle.of(updateToastDto.title());

}



Expand Down

0 comments on commit 90ffa18

Please sign in to comment.