-
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.
Browse files
Browse the repository at this point in the history
[2차 세미나] : 과제 구현
- Loading branch information
Showing
22 changed files
with
613 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
pluginManagement { | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' version '1.9.23' | ||
} | ||
} | ||
rootProject.name = 'assignment' | ||
|
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,11 @@ | ||
package org.sopt.week2; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DiaryApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(DiaryApplication.class, args); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/org/sopt/week2/controller/DiaryController.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,63 @@ | ||
package org.sopt.week2.controller; | ||
|
||
import org.sopt.week2.dto.request.DiaryInformationRequest; | ||
import org.sopt.week2.dto.response.DiariesResponse; | ||
import org.sopt.week2.dto.response.DiaryDetailResponse; | ||
import org.sopt.week2.enums.entity.DiaryCategory; | ||
import org.sopt.week2.service.DiaryService; | ||
import org.sopt.week2.util.TextUtils; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/diaries") | ||
public class DiaryController { | ||
|
||
private final DiaryService diaryService; | ||
|
||
public DiaryController(DiaryService diaryService) { | ||
this.diaryService = diaryService; | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> createDiary( | ||
@RequestBody final DiaryInformationRequest diaryInformationRequest | ||
) { | ||
TextUtils.validateDiaryContent(diaryInformationRequest.content()); | ||
diaryService.createDiary(diaryInformationRequest.title(), diaryInformationRequest.content(), diaryInformationRequest.diaryCategory()); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(null); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<DiariesResponse> getDiaries( | ||
@RequestParam(value = "diaryCategory") final DiaryCategory diaryCategory | ||
) { | ||
return ResponseEntity.status(HttpStatus.OK).body(diaryService.getDiaries(diaryCategory)); | ||
} | ||
|
||
@GetMapping("/{diaryId}") | ||
public ResponseEntity<DiaryDetailResponse> getDiary( | ||
@PathVariable(value = "diaryId") final long diaryId | ||
) { | ||
return ResponseEntity.status(HttpStatus.OK).body(diaryService.getDiary(diaryId)); | ||
} | ||
|
||
@PatchMapping("/{diaryId}") | ||
public ResponseEntity<Void> updateDiary( | ||
@PathVariable(value = "diaryId") final long diaryId, | ||
@RequestBody final DiaryInformationRequest diaryInformationRequest | ||
) { | ||
TextUtils.validateDiaryContent(diaryInformationRequest.content()); | ||
diaryService.updateDiary(diaryId, diaryInformationRequest.title(), diaryInformationRequest.content()); | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
} | ||
|
||
@DeleteMapping("/{diaryId}") | ||
public ResponseEntity<Void> deleteDiary( | ||
@PathVariable(value = "diaryId") final long diaryId | ||
) { | ||
diaryService.deleteDiary(diaryId); | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/sopt/week2/dto/request/DiaryInformationRequest.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 org.sopt.week2.dto.request; | ||
|
||
import org.sopt.week2.enums.entity.DiaryCategory; | ||
|
||
public record DiaryInformationRequest( | ||
String title, | ||
String content, | ||
DiaryCategory diaryCategory | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/sopt/week2/dto/response/DiariesResponse.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,12 @@ | ||
package org.sopt.week2.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record DiariesResponse( | ||
List<DiaryResponse> diaries | ||
) { | ||
|
||
public static DiariesResponse of(final List<DiaryResponse> diaries) { | ||
return new DiariesResponse(diaries); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/sopt/week2/dto/response/DiaryDetailResponse.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,15 @@ | ||
package org.sopt.week2.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record DiaryDetailResponse( | ||
long id, | ||
String title, | ||
String content, | ||
LocalDateTime createAt | ||
) { | ||
|
||
public static DiaryDetailResponse of(final long id, final String title, final String content, final LocalDateTime createAt) { | ||
return new DiaryDetailResponse(id, title, content, createAt); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/sopt/week2/dto/response/DiaryResponse.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,11 @@ | ||
package org.sopt.week2.dto.response; | ||
|
||
public record DiaryResponse( | ||
long id, | ||
String title | ||
) { | ||
|
||
public static DiaryResponse of(final long id, final String title) { | ||
return new DiaryResponse(id, title); | ||
} | ||
} |
Oops, something went wrong.