-
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.
- Loading branch information
1 parent
594f2f0
commit 7df49ff
Showing
9 changed files
with
386 additions
and
18 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
98 changes: 98 additions & 0 deletions
98
src/main/java/org/petmarket/users/controller/ComplaintsAdminController.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,98 @@ | ||
package org.petmarket.users.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.constraints.Positive; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.petmarket.users.dto.ComplaintResponseDto; | ||
import org.petmarket.users.entity.ComplaintStatus; | ||
import org.petmarket.users.service.ComplaintService; | ||
import org.petmarket.utils.annotations.parametrs.ParameterPageNumber; | ||
import org.petmarket.utils.annotations.parametrs.ParameterPageSize; | ||
import org.petmarket.utils.annotations.responses.ApiResponseForbidden; | ||
import org.petmarket.utils.annotations.responses.ApiResponseNotFound; | ||
import org.petmarket.utils.annotations.responses.ApiResponseSuccessful; | ||
import org.petmarket.utils.annotations.responses.ApiResponseUnauthorized; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Tag(name = "Complaints", description = "the user complaints API") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RestController | ||
@Validated | ||
@RequestMapping(value = "/v1/admin/complaints") | ||
public class ComplaintsAdminController { | ||
private final ComplaintService complaintService; | ||
|
||
@Operation(summary = "Delete complaint") | ||
@ApiResponseSuccessful | ||
@ApiResponseUnauthorized | ||
@ApiResponseForbidden | ||
@PreAuthorize("isAuthenticated()") | ||
@DeleteMapping("/{id}") | ||
public void deleteComplaint(@PathVariable Long id) { | ||
log.info("Deleting complaint"); | ||
complaintService.deleteComplaint(id); | ||
} | ||
|
||
@Operation(summary = "Get complaint") | ||
@ApiResponseSuccessful | ||
@ApiResponseNotFound | ||
@ApiResponseUnauthorized | ||
@ApiResponseForbidden | ||
@PreAuthorize("isAuthenticated()") | ||
@GetMapping("/{id}") | ||
public ComplaintResponseDto getComplaint(@PathVariable Long id) { | ||
log.info("Getting complaint"); | ||
return complaintService.getComplaint(id); | ||
} | ||
|
||
@Operation(summary = "Get complaints") | ||
@ApiResponseSuccessful | ||
@ApiResponseUnauthorized | ||
@ApiResponseForbidden | ||
@PreAuthorize("isAuthenticated()") | ||
@GetMapping | ||
public List<ComplaintResponseDto> getComplaints( | ||
@RequestParam(required = false, defaultValue = "PENDING") ComplaintStatus complaintStatus, | ||
@ParameterPageNumber @RequestParam(defaultValue = "1") @Positive int page, | ||
@ParameterPageSize @RequestParam(defaultValue = "30") @Positive int size, | ||
@RequestParam(defaultValue = "DESC") Sort.Direction direction) { | ||
log.info("Getting complaints"); | ||
return complaintService.getComplaints(complaintStatus, size, page, direction); | ||
} | ||
|
||
@Operation(summary = "Get complaints by user id") | ||
@ApiResponseSuccessful | ||
@ApiResponseUnauthorized | ||
@ApiResponseForbidden | ||
@PreAuthorize("isAuthenticated()") | ||
@GetMapping("/user/{userId}") | ||
public List<ComplaintResponseDto> getComplaintsByUserId( | ||
@PathVariable Long userId, | ||
@RequestParam(required = false, defaultValue = "PENDING") ComplaintStatus status, | ||
@ParameterPageNumber @RequestParam(defaultValue = "1") @Positive int page, | ||
@ParameterPageSize @RequestParam(defaultValue = "30") @Positive int size, | ||
@RequestParam(defaultValue = "DESC") Sort.Direction direction) { | ||
log.info("Getting complaints by user id"); | ||
return complaintService.getComplaintsByUserId(userId, status, size, page, direction); | ||
} | ||
|
||
@Operation(summary = "Update complaint status") | ||
@ApiResponseSuccessful | ||
@ApiResponseUnauthorized | ||
@ApiResponseForbidden | ||
@PreAuthorize("isAuthenticated()") | ||
@PutMapping("/{id}") | ||
public void updateComplaintStatus(@PathVariable Long id, | ||
@RequestParam(defaultValue = "RESOLVED") ComplaintStatus status) { | ||
log.info("Updating complaint status"); | ||
complaintService.updateStatusById(id, status); | ||
} | ||
} |
25 changes: 22 additions & 3 deletions
25
src/main/java/org/petmarket/users/controller/ComplaintsController.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 |
---|---|---|
@@ -1,17 +1,36 @@ | ||
package org.petmarket.users.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.petmarket.users.dto.ComplaintRequestDto; | ||
import org.petmarket.users.service.ComplaintService; | ||
import org.petmarket.utils.annotations.responses.ApiResponseBadRequest; | ||
import org.petmarket.utils.annotations.responses.ApiResponseSuccessful; | ||
import org.petmarket.utils.annotations.responses.ApiResponseUnauthorized; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Tag(name = "Users", description = "the users API") | ||
@Tag(name = "Complaints", description = "the user complaints API") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RestController | ||
@Validated | ||
@RequestMapping(value = "/v1/complaints") | ||
public class ComplaintsController { | ||
private final ComplaintService complaintService; | ||
|
||
@Operation(summary = "Add complaint") | ||
@ApiResponseSuccessful | ||
@ApiResponseUnauthorized | ||
@ApiResponseBadRequest | ||
@PreAuthorize("isAuthenticated()") | ||
@PostMapping | ||
public void addComplaint(@RequestBody @Valid ComplaintRequestDto complaintRequestDto) { | ||
log.info("Adding complaint"); | ||
complaintService.addComplaint(complaintRequestDto); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/petmarket/users/dto/ComplaintRequestDto.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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
package org.petmarket.users.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.*; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Setter | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Validated | ||
public class ComplaintRequestDto { | ||
@NotBlank(message = "The 'text' cannot be empty") | ||
@Schema(example = "Hello, how are you?") | ||
@Size(max = 10000, message = "The 'text' length must be less than or equal to 10000") | ||
private String complaint; | ||
|
||
@Schema(example = "1") | ||
@JsonProperty("complained_user_id") | ||
private Long complainedUserId; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/petmarket/users/dto/ComplaintResponseDto.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,20 @@ | ||
package org.petmarket.users.dto; | ||
|
||
import lombok.*; | ||
|
||
import java.util.Date; | ||
|
||
@Setter | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ComplaintResponseDto { | ||
private Long id; | ||
private String complaint; | ||
private Long userId; | ||
private Long complainedUserId; | ||
private String status; | ||
private Date created; | ||
private Date updated; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/petmarket/users/mapper/ComplaintMapper.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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
package org.petmarket.users.mapper; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.petmarket.config.MapperConfig; | ||
import org.petmarket.users.dto.ComplaintRequestDto; | ||
import org.petmarket.users.dto.ComplaintResponseDto; | ||
import org.petmarket.users.entity.Complaint; | ||
|
||
import java.util.List; | ||
|
||
@Mapper(config = MapperConfig.class) | ||
public interface ComplaintMapper { | ||
Complaint mapDtoToComplaint(ComplaintRequestDto complaintRequestDto); | ||
|
||
@Mapping(target = "userId", source = "user.id") | ||
@Mapping(target = "complainedUserId", source = "complainedUser.id") | ||
ComplaintResponseDto mapComplaintToDto(Complaint complaint); | ||
|
||
List<ComplaintResponseDto> mapComplaintToDto(List<Complaint> complaints); | ||
} |
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
Oops, something went wrong.