-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Hangar-Tech/developer
Developer
- Loading branch information
Showing
97 changed files
with
4,050 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/com/institutosemprealerta/semprealerta/SempreAlertaApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../institutosemprealerta/semprealerta/application/controllers/AuthenticationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.institutosemprealerta.semprealerta.application.controllers; | ||
|
||
import com.institutosemprealerta.semprealerta.domain.ports.out.request.LoginDTO; | ||
import com.institutosemprealerta.semprealerta.domain.ports.out.responses.LoginResponse; | ||
import com.institutosemprealerta.semprealerta.domain.service.AuthenticationService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
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("/auth") | ||
@Tag(name = "auth") | ||
public class AuthenticationController { | ||
|
||
private final AuthenticationService authenticationService; | ||
|
||
public AuthenticationController(AuthenticationService authenticationService) { | ||
this.authenticationService = authenticationService; | ||
} | ||
|
||
@PostMapping("/login") | ||
@Operation(summary = "Login", description = "You can login with your email and password") | ||
|
||
public ResponseEntity<?> login(@RequestBody @Valid LoginDTO loginRequestBody) { | ||
LoginResponse token = authenticationService.login(loginRequestBody); | ||
return ResponseEntity.ok(token); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...om/institutosemprealerta/semprealerta/application/controllers/FilesStorageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.institutosemprealerta.semprealerta.application.controllers; | ||
|
||
import com.institutosemprealerta.semprealerta.domain.service.StorageService; | ||
import com.institutosemprealerta.semprealerta.domain.ports.out.responses.FileResponse; | ||
import com.institutosemprealerta.semprealerta.swagger.annotations.BadRequestResponse; | ||
import com.institutosemprealerta.semprealerta.swagger.annotations.CreatedResponse; | ||
import com.institutosemprealerta.semprealerta.swagger.annotations.NotFoundResponse; | ||
import com.institutosemprealerta.semprealerta.swagger.annotations.OkResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@Controller | ||
@RequestMapping("/api/v1/files") | ||
@Tag(name = "Files", description = "Files management") | ||
public class FilesStorageController { | ||
private StorageService storageService; | ||
|
||
public FilesStorageController(StorageService storageService) { | ||
this.storageService = storageService; | ||
} | ||
|
||
@Operation(summary = "Faça o upload de um arquivo", description = "Upload de um arquivo para o servidor") | ||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
@CreatedResponse | ||
@BadRequestResponse | ||
public ResponseEntity<String> uploadFile(@RequestPart("file") MultipartFile file, @RequestParam("file_type") String fileType) { | ||
|
||
String fileName = storageService.store(file, fileType); | ||
|
||
String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath() | ||
.path("/api/v1/files/download/") | ||
.path(fileName) | ||
.toUriString(); | ||
|
||
URI uri = URI.create(fileDownloadUri); | ||
return ResponseEntity.created(uri).body("File uploaded successfully, file name: " + fileName + " on path: " + fileDownloadUri); | ||
} | ||
|
||
@GetMapping("/download/{fileName:.+}") | ||
@ResponseBody | ||
@Operation(summary = "Download de um arquivo", description = "Baixe um arquivo pelo nome do arquivo") | ||
@OkResponse | ||
@NotFoundResponse | ||
@BadRequestResponse | ||
public ResponseEntity<Resource> downloadFile( | ||
@PathVariable String fileName, | ||
HttpServletRequest request | ||
) { | ||
|
||
try { | ||
Resource resource = storageService.loadAsResource(fileName); | ||
String contentType = request.getServletContext().getMimeType(resource.getFile().getAbsolutePath()); | ||
|
||
if (contentType == null) { | ||
contentType = MediaType.APPLICATION_OCTET_STREAM.getType(); | ||
} | ||
|
||
return ResponseEntity.ok() | ||
.contentType(MediaType.parseMediaType(contentType)) | ||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"") | ||
.body(resource); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@GetMapping("/list") | ||
@Operation(summary = "List todos os arquivos", description = "Liste todos os arquivos do servidor") | ||
@OkResponse | ||
@BadRequestResponse | ||
public ResponseEntity<List<FileResponse>> listFiles() throws IOException { | ||
List<FileResponse> fileNames = storageService.loadAll(); | ||
|
||
return ResponseEntity.ok(fileNames); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...n/java/com/institutosemprealerta/semprealerta/application/controllers/PostController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.institutosemprealerta.semprealerta.application.controllers; | ||
|
||
import com.institutosemprealerta.semprealerta.domain.service.PostService; | ||
import com.institutosemprealerta.semprealerta.domain.model.Post; | ||
import com.institutosemprealerta.semprealerta.swagger.annotations.*; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.net.URI; | ||
|
||
@RestController | ||
@RequestMapping("api/v1/posts") | ||
@Tag(name = "Post", description = "Post management") | ||
public class PostController { | ||
private final PostService postService; | ||
|
||
public PostController(PostService postService) { | ||
this.postService = postService; | ||
} | ||
|
||
@GetMapping | ||
@Operation(summary = "Lista de todos os posts", description = "Lista de todos os posts com paginação") | ||
@OkResponse | ||
public ResponseEntity<Page<Post>> getAllPosts(Pageable pageable) { | ||
return ResponseEntity.ok(postService.listAll(pageable)); | ||
} | ||
|
||
@PostMapping | ||
@Operation(summary = "Criar postagem", description = "Crie uma nova postagem") | ||
@CreatedResponse | ||
@BadRequestResponse | ||
public ResponseEntity<?> createPost(@Valid @RequestBody Post post) { | ||
String slug = postService.save(post); | ||
return ResponseEntity.created(URI.create("/api/v1/posts/" + slug)).build(); | ||
} | ||
|
||
@GetMapping("/{slug}") | ||
@Operation(summary = "Pegar post pelo slug", description = "Procura um post pelo seu slug") | ||
@OkResponse | ||
@NotFoundResponse | ||
public ResponseEntity<Post> getPostBySlug(@PathVariable String slug) { | ||
return ResponseEntity.ok(postService.findBySlug(slug)); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
@Operation(summary = "Atualizar post", description = "Atualize um post existente pelo seu id") | ||
@NoContentResponse | ||
@NotFoundResponse | ||
@BadRequestResponse | ||
public ResponseEntity<?> updatePost(@PathVariable Long id, @Valid @RequestBody Post post) { | ||
postService.update(id, post); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
@Operation(summary = "Deletar post", description = "Deleta um post existente pelo seu id") | ||
@NoContentResponse | ||
@NotFoundResponse | ||
public ResponseEntity<?> deletePost(@PathVariable Long id) { | ||
postService.delete(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...n/java/com/institutosemprealerta/semprealerta/application/controllers/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.institutosemprealerta.semprealerta.application.controllers; | ||
|
||
import com.institutosemprealerta.semprealerta.domain.service.UserService; | ||
import com.institutosemprealerta.semprealerta.domain.model.UserDTO; | ||
import com.institutosemprealerta.semprealerta.domain.ports.out.responses.UserResponse; | ||
import com.institutosemprealerta.semprealerta.infrastructure.entity.user.User; | ||
import com.institutosemprealerta.semprealerta.swagger.annotations.*; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("api/v1/user") | ||
@Tag(name = "User", description = "Administração de usuários") | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
public UserController(UserService userService) { | ||
this.userService = userService; | ||
} | ||
|
||
@PostMapping | ||
@Operation(summary = "Criação de um usuário", description = "Criação de um usuário no sistema") | ||
@CreatedResponse | ||
@ConflictResponse | ||
public ResponseEntity<?> createUser(@Valid @RequestBody UserDTO user) { | ||
userService.save(user.toDomain()); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
@Operation(summary = "Busca de um usuário", description = "Busca de um usuário pelo id") | ||
@OkResponse | ||
@NotFoundResponse | ||
public ResponseEntity<UserResponse> findById(@PathVariable int id) { | ||
User userFound = userService.findById(id); | ||
return ResponseEntity.ok().body(UserResponse.toResponse(userFound)); | ||
} | ||
|
||
@GetMapping("/registration/{reg}") | ||
@Operation(summary = "Busca de um usuário", description = "Busca de um usuário pela matrícula") | ||
@OkResponse | ||
@NotFoundResponse | ||
public ResponseEntity<UserResponse> findByRegistration(@PathVariable String reg) { | ||
User userFound = userService.findByRegistration(reg); | ||
return ResponseEntity.ok().body(UserResponse.toResponse(userFound)); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
@Operation(summary = "Atualização de um usuário", description = "Atualização de um usuário pelo id") | ||
@NoContentResponse | ||
@NotFoundResponse | ||
@ConflictResponse | ||
public ResponseEntity<?> updateUser(@PathVariable int id, @RequestBody UserDTO user) { | ||
userService.update(id, user.toDomain()); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
@Operation(summary = "Deleção de um usuário", description = "Deleção de um usuário pelo id") | ||
@NoContentResponse | ||
@NotFoundResponse | ||
public ResponseEntity<?> deleteUser(@PathVariable int id) { | ||
userService.delete(id); | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); | ||
} | ||
} |
Oops, something went wrong.