msa : monolithic - regist writer
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.monoloticdemo;
|
||||
package com.monolithicdemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.monolithicdemo.controller;
|
||||
|
||||
import com.monolithicdemo.model.form.RegisterWriterForm;
|
||||
import com.monolithicdemo.service.WriterService;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/writer")
|
||||
@RequiredArgsConstructor
|
||||
public class WriterController {
|
||||
|
||||
private final WriterService writerService;
|
||||
|
||||
@PostMapping("/")
|
||||
public ResponseEntity<Long> registerWriter(@RequestBody RegisterWriterForm registerWriterForm) {
|
||||
return ResponseEntity.ok().body(writerService.registerWriter(registerWriterForm));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.monolithicdemo.model.entity;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table
|
||||
@Entity
|
||||
public class Writer {
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.monolithicdemo.model.form;
|
||||
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class RegisterWriterForm {
|
||||
|
||||
@ApiParam(value = "작가의 이름", example = "홍길동", defaultValue = "홍길동")
|
||||
private String name;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.monolithicdemo.repository;
|
||||
|
||||
import com.monolithicdemo.model.entity.Writer;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface WriterRepository extends JpaRepository<Writer, Long> {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.monolithicdemo.service;
|
||||
|
||||
import com.monolithicdemo.model.entity.Writer;
|
||||
import com.monolithicdemo.model.form.RegisterWriterForm;
|
||||
import com.monolithicdemo.repository.WriterRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* writer 에 대한 CRUD
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WriterService {
|
||||
|
||||
private final WriterRepository writerRepository;
|
||||
|
||||
public Long registerWriter(RegisterWriterForm registerWriterForm) {
|
||||
|
||||
return writerRepository.save(
|
||||
Writer.builder()
|
||||
.name(registerWriterForm.getName())
|
||||
.createdAt(LocalDateTime.now()).build()
|
||||
).getId();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user