aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/terminaldweller/doc/DocController.java
blob: 53f2748853059f6412ac1df919903fe2c113ea09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.terminaldweller.doc;

import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/** The document controller class. */
@RestController
// @CrossOrigin(origins = {"https://localhost:7080, https://editor.terminaldweller.com"})
@CrossOrigin(origins = "https://editor.terminaldweller.com", maxAge = 3600)
@RequestMapping(path = "api/v1/doc")
public class DocController {
  private final DocService docService;

  @Autowired
  public DocController(DocService docService) {
    this.docService = docService;
  }

  @GetMapping(path = "{Id}")
  public Optional<Doc> getDocs(@PathVariable("Id") Long id) {
    return docService.getDocs(id);
  }

  @PostMapping(path = "{Id}")
  @ResponseStatus(HttpStatus.CREATED)
  public void postDocs(@PathVariable("Id") Long id, @RequestBody Doc doc) {
    docService.addNewDoc(id, doc);
  }

  @DeleteMapping(path = "{Id}")
  public void deleteDocs(@PathVariable("Id") Long id) {
    docService.deleteDoc(id);
  }

  @PutMapping(path = "{Id}")
  public void updatDoc(@RequestBody Doc doc, @PathVariable("Id") long id) {
    docService.updateDoc(doc, id);
  }
}