Skip to content

Commit

Permalink
Merge pull request #7 from AND-SOPT-SERVER/seminar/#2
Browse files Browse the repository at this point in the history
[2차 세미나] : 과제 구현
  • Loading branch information
sansan20535 authored Oct 31, 2024
2 parents 13458b3 + 1ba266a commit f67a4de
Show file tree
Hide file tree
Showing 22 changed files with 613 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 106 additions & 32 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'org.jetbrains.kotlin.jvm'
}

group = 'org.sopt'
Expand All @@ -9,11 +12,26 @@ repositories {
mavenCentral()
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'

testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}

test {
useJUnitPlatform()
}
}
5 changes: 5 additions & 0 deletions settings.gradle
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'

11 changes: 11 additions & 0 deletions src/main/java/org/sopt/week2/DiaryApplication.java
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 src/main/java/org/sopt/week2/controller/DiaryController.java
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);
}
}
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 src/main/java/org/sopt/week2/dto/response/DiariesResponse.java
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 src/main/java/org/sopt/week2/dto/response/DiaryDetailResponse.java
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 src/main/java/org/sopt/week2/dto/response/DiaryResponse.java
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);
}
}
Loading

0 comments on commit f67a4de

Please sign in to comment.