File tree Expand file tree Collapse file tree
src/main/java/com/ajouchong Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ public ApiResponse<List<LinkResponseDto>> getAllLinks() {
3131 return new ApiResponse <>(1 , "링크 목록을 조회했습니다." , links );
3232 }
3333
34+ @ PutMapping ("/{id}" )
35+ public ApiResponse <LinkResponseDto > updateLink (@ PathVariable Long id ,
36+ @ Valid @ RequestBody LinkRequestDto requestDto ) {
37+ LinkResponseDto response = linkService .updateLink (id , requestDto );
38+
39+ return new ApiResponse <>(1 , "링크가 성공적으로 수정되었습니다." , response );
40+ }
41+
3442 @ DeleteMapping ("/{id}/delete" )
3543 public ApiResponse <Void > deleteLink (@ PathVariable Long id ) {
3644 linkService .deleteLink (id );
Original file line number Diff line number Diff line change 11package com .ajouchong .controller .user ;
22
33import com .ajouchong .common .ApiResponse ;
4- import com .ajouchong .dto .request .LinkRequestDto ;
54import com .ajouchong .dto .response .LinkResponseDto ;
65import com .ajouchong .service .LinkService ;
76import lombok .RequiredArgsConstructor ;
87import org .springframework .web .bind .annotation .*;
98
10- import jakarta .validation .Valid ;
119import java .util .List ;
1210
1311@ RestController
1614public class LinkController {
1715 private final LinkService linkService ;
1816
19- @ PostMapping ("/upload" )
20- public ApiResponse <LinkResponseDto > uploadLink (@ Valid @ RequestBody LinkRequestDto requestDto ) {
21- LinkResponseDto response = linkService .uploadLink (requestDto );
22-
23- return new ApiResponse <>(1 , "링크가 성공적으로 업로드되었습니다." , response );
24- }
25-
2617 @ GetMapping
2718 public ApiResponse <List <LinkResponseDto >> getAllLinks () {
2819 List <LinkResponseDto > links = linkService .getAllLinks ();
Original file line number Diff line number Diff line change @@ -55,6 +55,24 @@ public List<LinkResponseDto> getAllLinks() {
5555 .collect (Collectors .toList ());
5656 }
5757
58+ @ Transactional
59+ public LinkResponseDto updateLink (Long id , LinkRequestDto requestDto ) {
60+ Link link = linkRepository .findById (id )
61+ .orElseThrow (() -> new IllegalArgumentException ("링크를 찾을 수 없습니다. ID: " + id ));
62+
63+ link .setTitle (requestDto .getTitle ());
64+ link .setLink (requestDto .getLink ());
65+
66+ Link updatedLink = linkRepository .save (link );
67+
68+ return LinkResponseDto .builder ()
69+ .id (updatedLink .getId ())
70+ .title (updatedLink .getTitle ())
71+ .link (updatedLink .getLink ())
72+ .createdAt (updatedLink .getCreatedAt ())
73+ .build ();
74+ }
75+
5876 @ Transactional
5977 public void deleteLink (Long id ) {
6078 Link link = linkRepository .findById (id )
You can’t perform that action at this time.
0 commit comments