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
1 parent
3ff0556
commit b3f373b
Showing
11 changed files
with
522 additions
and
1 deletion.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
week03/src/main/java/com/spring/week03/Week03Application.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
45 changes: 45 additions & 0 deletions
45
week03/src/main/java/com/spring/week03/controller/MemoController.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,45 @@ | ||
package com.spring.week03.controller; | ||
|
||
import com.spring.week03.domain.Memo; | ||
import com.spring.week03.domain.MemoRepository; | ||
import com.spring.week03.domain.MemoRequestDto; | ||
import com.spring.week03.service.MemoService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class MemoController { | ||
|
||
private final MemoRepository memoRepository; | ||
private final MemoService memoService; | ||
|
||
|
||
|
||
@PostMapping("/api/memos") | ||
public Memo createMemo(@RequestBody MemoRequestDto requestDto){ | ||
Memo memo = new Memo(requestDto); | ||
return memoRepository.save(memo); | ||
} | ||
|
||
@GetMapping("/api/memos") | ||
public List<Memo> readMemo(){ | ||
LocalDateTime start = LocalDateTime.now().minusDays(1); | ||
LocalDateTime end = LocalDateTime.now(); | ||
return memoRepository.findAllByModifiedAtBetweenOrderByModifiedAtDesc(start, end); | ||
} | ||
|
||
@PutMapping("/api/memos/{id}") | ||
public Long updateMemo(@PathVariable Long id, @RequestBody MemoRequestDto requestDto){ | ||
return memoService.update(id, requestDto); | ||
} | ||
|
||
@DeleteMapping("/api/memos/{id}") | ||
public Long deleteMemo(@PathVariable Long id){ | ||
memoRepository.deleteById(id); | ||
return id; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
week03/src/main/java/com/spring/week03/service/MemoService.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,25 @@ | ||
package com.spring.week03.service; | ||
|
||
import com.spring.week03.domain.Memo; | ||
import com.spring.week03.domain.MemoRepository; | ||
import com.spring.week03.domain.MemoRequestDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.transaction.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class MemoService { | ||
|
||
private final MemoRepository memoRepository; | ||
|
||
@Transactional // DB에 반영시켜줘! | ||
public Long update(Long id, MemoRequestDto requestDto) { | ||
Memo memo = memoRepository.findById(id).orElseThrow( | ||
() -> new IllegalArgumentException("아이디가 존재하지 않습니다.") | ||
); | ||
memo.update(requestDto); | ||
return memo.getId(); | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.