msa : monolithic - regist webbook
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
package com.monolithicdemo.controller;
|
||||
|
||||
import com.monolithicdemo.model.form.RegisterWebBookForm;
|
||||
import com.monolithicdemo.model.form.RegisterWriterForm;
|
||||
import com.monolithicdemo.service.WriterService;
|
||||
import com.monolithicdemo.service.WriterWebBookService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/writer")
|
||||
@@ -15,9 +14,17 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class WriterController {
|
||||
|
||||
private final WriterService writerService;
|
||||
private final WriterWebBookService writerWebBookService;
|
||||
|
||||
@PostMapping("/")
|
||||
public ResponseEntity<Long> registerWriter(@RequestBody RegisterWriterForm registerWriterForm) {
|
||||
return ResponseEntity.ok().body(writerService.registerWriter(registerWriterForm));
|
||||
}
|
||||
|
||||
@PostMapping("/{writerId}/webBook")
|
||||
public ResponseEntity<Long> registerWebBook(
|
||||
@PathVariable(value = "writerId") Long writerId,
|
||||
@RequestBody RegisterWebBookForm registerWebBookForm) {
|
||||
return ResponseEntity.ok(writerWebBookService.registerWebBook(writerId, registerWebBookForm));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.monolithicdemo.model.entity;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table
|
||||
@Entity
|
||||
public class WebBook {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long webBookId;
|
||||
//제목
|
||||
private String name;
|
||||
//설명
|
||||
private String description;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import java.time.LocalDateTime;
|
||||
public class Writer {
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
private Long writerId;
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.monolithicdemo.model.form;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@ApiModel
|
||||
public class RegisterWebBookForm {
|
||||
|
||||
@ApiModelProperty(value = "웹소설 제목", example = "MSA 실습")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "웹소설 설명", example = "Monolithic 에서 MSA 로 실습을 해 봅시다.")
|
||||
private String description;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.monolithicdemo.repository;
|
||||
|
||||
import com.monolithicdemo.model.entity.WebBook;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface WebBookRepository extends JpaRepository<WebBook,Long> {
|
||||
}
|
||||
@@ -23,6 +23,6 @@ public class WriterService {
|
||||
Writer.builder()
|
||||
.name(registerWriterForm.getName())
|
||||
.createdAt(LocalDateTime.now()).build()
|
||||
).getId();
|
||||
).getWriterId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.monolithicdemo.service;
|
||||
|
||||
import com.monolithicdemo.model.entity.WebBook;
|
||||
import com.monolithicdemo.model.form.RegisterWebBookForm;
|
||||
import com.monolithicdemo.repository.WebBookRepository;
|
||||
import com.monolithicdemo.repository.WriterRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WriterWebBookService {
|
||||
|
||||
private final WriterRepository writerRepository;
|
||||
private final WebBookRepository webBookRepository;
|
||||
|
||||
public Long registerWebBook(Long writerId, RegisterWebBookForm registerWebBookForm) {
|
||||
|
||||
if (writerRepository.existsById(writerId)) {
|
||||
return webBookRepository.save(
|
||||
WebBook.builder()
|
||||
.name(registerWebBookForm.getName())
|
||||
.description(registerWebBookForm.getDescription())
|
||||
.createdAt(LocalDateTime.now())
|
||||
.build())
|
||||
.getWebBookId();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user