-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMusicController.java
63 lines (52 loc) · 2.28 KB
/
MusicController.java
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
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.music.review.app.controllers;
import com.music.review.app.domain.entities.musics.dtos.MusicCreateDTO;
import com.music.review.app.domain.entities.musics.dtos.MusicGetDTO;
import com.music.review.app.domain.entities.musics.dtos.MusicUpdateDTO;
import com.music.review.app.services.MusicService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("v1/musics")
@SecurityRequirement(name = "bearer-key")
public class MusicController {
private final MusicService musicService;
@Autowired
public MusicController(MusicService musicService){
this.musicService = musicService;
}
@PostMapping
public ResponseEntity<MusicGetDTO> createMusic(@RequestBody @Valid MusicCreateDTO musicCreateDTO){
return ResponseEntity.status(HttpStatus.CREATED)
.body(this.musicService.saveMusic(musicCreateDTO));
}
@GetMapping("/id/{idVar}")
public ResponseEntity<MusicGetDTO> findMusicById(@PathVariable Long idVar){
return ResponseEntity.status(HttpStatus.OK)
.body(new MusicGetDTO(this.musicService.findById(idVar)));
}
@GetMapping("/name/{nameMusic}")
public ResponseEntity<MusicGetDTO> findMusicByName(@PathVariable String nameMusic){
return ResponseEntity.status(HttpStatus.OK)
.body(new MusicGetDTO(this.musicService.findByName(nameMusic)));
}
@GetMapping
public ResponseEntity<List<MusicGetDTO>> findAllMusics(){
return ResponseEntity.status(HttpStatus.OK)
.body(this.musicService.findAll());
}
@DeleteMapping("/{deleteId}")
public ResponseEntity<Object> deleteById(@PathVariable Long deleteId){
this.musicService.deleteMusic(deleteId);
return ResponseEntity.noContent().build();
}
@PutMapping
public ResponseEntity<MusicGetDTO> updateMusic(@RequestBody @Valid MusicUpdateDTO musicUpdateDTO){
return ResponseEntity.status(HttpStatus.OK)
.body(this.musicService.update(musicUpdateDTO));
}
}