-
Notifications
You must be signed in to change notification settings - Fork 0
Tickets #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Tickets #43
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
fe229be
Resolved #11
dukris c2aeb9d
Tickets implemented
dukris b05dc41
Fixed script
dukris e8799c6
Tickets fixed
dukris dd429b7
Unit tests added
dukris ee70e9a
Unit tests fixed
dukris e979c80
String format refactored
dukris ef95fc1
It tests implemented
dukris 52a1404
Controller advice added
dukris d465c06
Resolved #34
dukris e6fe1f7
Unit tests for controllers added
dukris 92cb531
It tests for database
dukris dc6907d
It tests for controllers
dukris 0e52ba8
AccessDenied exception hanlked
dukris f5f4944
Tests fixed
dukris 4a19165
Inheritance removed
dukris c8a1dcd
Constructors fixed
dukris e62950f
Tables renamed
dukris a853d93
Token fixed
dukris 33f2213
Resolved #16
dukris 18650a3
Tests fixed
dukris 1628928
Resolved #47
dukris c1abcf4
Values passed
dukris f0fd18c
Tests fixed
dukris 8518ac4
Increment fixed
dukris d3c00d3
Platform refactored
dukris 56a718d
Tests fixed
dukris cc5d1f4
Mocked objects moved to new classes
dukris cc0964d
Component added
dukris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
src/main/java/git/tracehub/pmo/controller/AdviceController.java
This file contains hidden or 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,132 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to read | ||
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify, | ||
* merge, publish, distribute, sublicense, and/or sell copies of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package git.tracehub.pmo.controller; | ||
|
||
import git.tracehub.pmo.exception.ResourceNotFoundException; | ||
import io.github.eocqrs.eokson.Jocument; | ||
import io.github.eocqrs.eokson.MutableJson; | ||
import java.util.stream.Collectors; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.support.DefaultMessageSourceResolvable; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
/** | ||
* Exception handler. | ||
* | ||
* @checkstyle NonStaticMethodCheck (90 lines) | ||
* @since 0.0.0 | ||
*/ | ||
@Slf4j | ||
@RestControllerAdvice | ||
public class AdviceController { | ||
|
||
/** | ||
* Handle MethodArgumentNotValidException. | ||
* | ||
* @param exception Exception | ||
* @return ResponseEntity | ||
*/ | ||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
public ResponseEntity<byte[]> handle( | ||
final MethodArgumentNotValidException exception | ||
) { | ||
log.warn(exception.getMessage(), exception); | ||
return new ResponseEntity<>( | ||
new Jocument( | ||
new MutableJson() | ||
.with( | ||
"message", | ||
exception.getBindingResult().getFieldErrors() | ||
.stream() | ||
.map(DefaultMessageSourceResolvable::getDefaultMessage) | ||
.collect(Collectors.joining(", ")) | ||
) | ||
).byteArray(), | ||
HttpStatus.BAD_REQUEST | ||
); | ||
} | ||
|
||
/** | ||
* Handle ResourceNotFoundException. | ||
* | ||
* @param exception Exception | ||
* @return ResponseEntity | ||
*/ | ||
@ExceptionHandler(ResourceNotFoundException.class) | ||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
public ResponseEntity<byte[]> handle( | ||
final ResourceNotFoundException exception | ||
) { | ||
log.warn(exception.getMessage(), exception); | ||
return new ResponseEntity<>( | ||
new Jocument( | ||
new MutableJson() | ||
.with("message", exception.getMessage()) | ||
).byteArray(), | ||
HttpStatus.NOT_FOUND | ||
); | ||
} | ||
|
||
/** | ||
* Handle AccessDeniedException. | ||
* | ||
* @param exception Exception | ||
* @return ResponseEntity | ||
*/ | ||
@ExceptionHandler(AccessDeniedException.class) | ||
@ResponseStatus(HttpStatus.FORBIDDEN) | ||
public ResponseEntity<byte[]> handle( | ||
final AccessDeniedException exception | ||
) { | ||
log.warn(exception.getMessage(), exception); | ||
return new ResponseEntity<>( | ||
new Jocument( | ||
new MutableJson() | ||
.with("message", exception.getMessage()) | ||
).byteArray(), | ||
HttpStatus.FORBIDDEN | ||
); | ||
} | ||
|
||
/** | ||
* Handle Exception. | ||
* | ||
* @param exception Exception | ||
* @return ResponseEntity | ||
*/ | ||
@ExceptionHandler(Exception.class) | ||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
public ResponseEntity<byte[]> handle(final Exception exception) { | ||
log.warn(exception.getMessage(), exception); | ||
return new ResponseEntity<>( | ||
new Jocument( | ||
new MutableJson() | ||
.with("message", exception.getMessage()) | ||
).byteArray(), | ||
HttpStatus.INTERNAL_SERVER_ERROR | ||
); | ||
} | ||
|
||
} |
This file contains hidden or 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
94 changes: 94 additions & 0 deletions
94
src/main/java/git/tracehub/pmo/controller/TicketController.java
This file contains hidden or 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,94 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to read | ||
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify, | ||
* merge, publish, distribute, sublicense, and/or sell copies of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package git.tracehub.pmo.controller; | ||
|
||
import git.tracehub.pmo.controller.request.RqTicket; | ||
import git.tracehub.pmo.controller.request.TicketFromReq; | ||
import git.tracehub.pmo.ticket.Ticket; | ||
import git.tracehub.pmo.ticket.Tickets; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
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.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* Ticket Controller. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/tickets") | ||
public class TicketController { | ||
|
||
/** | ||
* Tickets. | ||
*/ | ||
private final Tickets tickets; | ||
|
||
/** | ||
* Ticket by path to job and repository. | ||
* | ||
* @param job Path to job | ||
* @param repo Repository name | ||
* @return Ticket | ||
*/ | ||
@GetMapping("/job") | ||
public Ticket byJob( | ||
@RequestParam final String job, | ||
@RequestParam final String repo | ||
) { | ||
return this.tickets.byJob(job, repo); | ||
} | ||
|
||
/** | ||
* Ticket by issue number and repository. | ||
* | ||
* @param number Issue number | ||
* @param repo Repository name | ||
* @return Ticket | ||
*/ | ||
@GetMapping("/number") | ||
public Ticket byNumber( | ||
@RequestParam final Integer number, | ||
@RequestParam final String repo | ||
) { | ||
return this.tickets.byNumber(number, repo); | ||
} | ||
|
||
/** | ||
* Create ticket. | ||
* | ||
* @param ticket Ticket | ||
* @return Ticket | ||
*/ | ||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public Ticket create(@RequestBody @Valid final RqTicket ticket) { | ||
return this.tickets.create( | ||
new TicketFromReq(ticket) | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.