Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.example.vet1177.entities.User;
import org.example.vet1177.services.ActivityLogService;
import org.example.vet1177.services.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -13,6 +15,8 @@
@RequestMapping("/api/activity-logs")
public class ActivityLogController {

private static final Logger log = LoggerFactory.getLogger(ActivityLogController.class);

private final ActivityLogService activityLogService;
private final UserService userService;

Expand All @@ -28,6 +32,7 @@ public List<ActivityLogResponse> getLogsByRecord(
@PathVariable UUID recordId,
@RequestHeader("userId") UUID userId
) {
log.info("GET /api/activity-logs/record/{}", recordId);
User user = userService.getUserEntityById(userId);

return activityLogService.getByRecord(recordId, user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.example.vet1177.dto.response.attachment.AttachmentResponse;
import org.example.vet1177.entities.User;
import org.example.vet1177.services.AttachmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -20,6 +22,8 @@
@RequestMapping("/api/attachments")
public class AttachmentController {

private static final Logger log = LoggerFactory.getLogger(AttachmentController.class);

private final AttachmentService attachmentService;
private final Validator validator;

Expand All @@ -39,6 +43,7 @@ public ResponseEntity<AttachmentResponse> uploadAttachment(
@RequestPart(value = "description", required = false) String description) {


log.info("POST /api/attachments/record/{} - uploading attachment", recordId);
AttachmentRequest request = new AttachmentRequest(recordId, description);

var violations = validator.validate(request);
Expand All @@ -56,6 +61,7 @@ public ResponseEntity<List<AttachmentResponse>> listAttachments(
@AuthenticationPrincipal User currentUser,
@PathVariable UUID recordId) {

log.info("GET /api/attachments/record/{}", recordId);
List<AttachmentResponse> responses = attachmentService.getAttachmentsByRecord(currentUser, recordId);
return ResponseEntity.ok(responses);
}
Expand All @@ -66,6 +72,7 @@ public ResponseEntity<AttachmentResponse> downloadAttachment(
@AuthenticationPrincipal User currentUser,
@PathVariable UUID id) {

log.info("GET /api/attachments/{}/download", id);
AttachmentResponse response = attachmentService.getAttachment(currentUser, id);
return ResponseEntity.ok(response);
}
Expand All @@ -76,6 +83,7 @@ public ResponseEntity<Void> deleteAttachment(
@AuthenticationPrincipal User currentUser,
@PathVariable UUID id) {

log.info("DELETE /api/attachments/{}", id);
attachmentService.deleteAttachment(currentUser, id);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.example.vet1177.dto.request.clinic.UpdateClinicRequest;
import org.example.vet1177.dto.response.clinic.ClinicResponse;
import org.example.vet1177.services.ClinicService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -15,6 +17,8 @@
@RequestMapping("/api/clinics")
public class ClinicController {

private static final Logger log = LoggerFactory.getLogger(ClinicController.class);

private final ClinicService clinicService;

public ClinicController(ClinicService clinicService) {
Expand All @@ -26,6 +30,7 @@ public ClinicController(ClinicService clinicService) {
public ResponseEntity<ClinicResponse> create(
@Valid @RequestBody CreateClinicRequest request) {

log.info("POST /api/clinics - creating clinic");
return ResponseEntity.ok(
ClinicResponse.from(
clinicService.create(
Expand All @@ -40,6 +45,7 @@ public ResponseEntity<ClinicResponse> create(
// READ ALL
@GetMapping
public ResponseEntity<List<ClinicResponse>> getAll() {
log.info("GET /api/clinics");
return ResponseEntity.ok(
clinicService.getAll()
.stream()
Expand All @@ -51,6 +57,7 @@ public ResponseEntity<List<ClinicResponse>> getAll() {
// READ ONE
@GetMapping("/{id}")
public ResponseEntity<ClinicResponse> getById(@PathVariable UUID id) {
log.info("GET /api/clinics/{}", id);
return ResponseEntity.ok(
ClinicResponse.from(
clinicService.getById(id)
Expand All @@ -64,6 +71,7 @@ public ResponseEntity<ClinicResponse> update(
@PathVariable UUID id,
@Valid @RequestBody UpdateClinicRequest request) {

log.info("PUT /api/clinics/{}", id);
return ResponseEntity.ok(
ClinicResponse.from(
clinicService.update(
Expand All @@ -79,6 +87,7 @@ public ResponseEntity<ClinicResponse> update(
// DELETE
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable UUID id) {
log.info("DELETE /api/clinics/{}", id);
clinicService.delete(id);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.example.vet1177.dto.response.comment.CommentResponse;
import org.example.vet1177.entities.User;
import org.example.vet1177.services.CommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -18,6 +20,8 @@
@RequestMapping("/api/comments")
public class CommentController {

private static final Logger log = LoggerFactory.getLogger(CommentController.class);

private final CommentService commentService;

public CommentController(CommentService commentService) {
Expand All @@ -31,6 +35,7 @@ public ResponseEntity<CommentResponse> create(
@Valid @RequestBody CreateCommentRequest request,
@AuthenticationPrincipal User currentUser) {

log.info("POST /api/comments recordId={}", request.recordId());
return ResponseEntity.ok(
CommentResponse.from(
commentService.create(
Expand All @@ -49,6 +54,7 @@ public ResponseEntity<List<CommentResponse>> getByRecord(
@PathVariable UUID recordId,
@AuthenticationPrincipal User currentUser) {

log.info("GET /api/comments/record/{}", recordId);
return ResponseEntity.ok(
commentService.getByRecord(recordId, currentUser)
.stream()
Expand All @@ -65,6 +71,7 @@ public ResponseEntity<CommentResponse> update(
@Valid @RequestBody UpdateCommentRequest request,
@AuthenticationPrincipal User currentUser) {

log.info("PUT /api/comments/{}", id);
return ResponseEntity.ok(
CommentResponse.from(
commentService.update(id, request.body(), currentUser)
Expand All @@ -78,6 +85,7 @@ public ResponseEntity<Void> delete(
@PathVariable UUID id,
@AuthenticationPrincipal User currentUser) {

log.info("DELETE /api/comments/{}", id);
commentService.delete(id, currentUser);
return ResponseEntity.noContent().build();
}
Expand All @@ -88,6 +96,7 @@ public ResponseEntity<Void> delete(
public ResponseEntity<Long> countByRecord(
@PathVariable UUID recordId,
@AuthenticationPrincipal User currentUser) {
log.info("GET /api/comments/record/{}/count", recordId);
return ResponseEntity.ok(
commentService.countByRecord(recordId, currentUser)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.example.vet1177.policy.MedicalRecordPolicy;
import org.example.vet1177.services.MedicalRecordService;
import org.example.vet1177.services.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.example.vet1177.dto.request.medicalrecord.*;
import org.example.vet1177.dto.response.medicalrecord.*;
Expand All @@ -20,6 +22,8 @@
@RequestMapping("/api/medical-records")
public class MedicalRecordController {

private static final Logger log = LoggerFactory.getLogger(MedicalRecordController.class);

private final MedicalRecordService medicalRecordService;
private final MedicalRecordPolicy medicalRecordPolicy;
private final UserService userService;
Expand All @@ -40,6 +44,7 @@ public ResponseEntity<MedicalRecordResponse> create(
@Valid @RequestBody CreateMedicalRecordRequest request,
@AuthenticationPrincipal User currentUser) {

log.info("POST /api/medical-records - creating record for petId={}", request.petId());
return ResponseEntity.ok(
MedicalRecordResponse.from(
medicalRecordService.create(
Expand All @@ -60,6 +65,7 @@ public ResponseEntity<MedicalRecordResponse> getById(
@PathVariable UUID id,
@AuthenticationPrincipal User currentUser) {

log.info("GET /api/medical-records/{}", id);
MedicalRecord record = medicalRecordService.getById(id);
medicalRecordPolicy.canView(currentUser, record);
return ResponseEntity.ok(MedicalRecordResponse.from(record));
Expand All @@ -71,6 +77,7 @@ public ResponseEntity<MedicalRecordResponse> getById(
public ResponseEntity<List<MedicalRecordSummaryResponse>> getMyRecords(
@AuthenticationPrincipal User currentUser) {

log.info("GET /api/medical-records/my-records");
if (currentUser.getRole() != Role.OWNER) {
throw new ForbiddenException("Endast djurägare kan se sina egna ärenden");
}
Expand All @@ -90,6 +97,7 @@ public ResponseEntity<List<MedicalRecordSummaryResponse>> getByOwner(
@PathVariable UUID ownerId,
@AuthenticationPrincipal User currentUser) {

log.info("GET /api/medical-records/owner/{}", ownerId);
if (currentUser.getRole() == Role.OWNER &&
!currentUser.getId().equals(ownerId)) {
throw new ForbiddenException("Du kan bara se dina egna ärenden");
Expand All @@ -111,6 +119,7 @@ public ResponseEntity<List<MedicalRecordSummaryResponse>> getByPet(
@PathVariable UUID petId,
@AuthenticationPrincipal User currentUser) {

log.info("GET /api/medical-records/pet/{}", petId);
return ResponseEntity.ok(
medicalRecordService.getByPetAllowedForUser(petId, currentUser)
.stream()
Expand All @@ -126,6 +135,7 @@ public ResponseEntity<List<MedicalRecordSummaryResponse>> getByClinic(
@PathVariable UUID clinicId,
@AuthenticationPrincipal User currentUser) {

log.info("GET /api/medical-records/clinic/{}", clinicId);
medicalRecordPolicy.canViewClinic(currentUser, clinicId);
return ResponseEntity.ok(
medicalRecordService.getByClinic(clinicId)
Expand All @@ -143,6 +153,7 @@ public ResponseEntity<List<MedicalRecordSummaryResponse>> getByClinicAndStatus(
@PathVariable RecordStatus status,
@AuthenticationPrincipal User currentUser) {

log.info("GET /api/medical-records/clinic/{}/status/{}", clinicId, status);
medicalRecordPolicy.canViewClinic(currentUser, clinicId);
return ResponseEntity.ok(
medicalRecordService.getByClinicAndStatus(clinicId, status)
Expand All @@ -160,6 +171,7 @@ public ResponseEntity<MedicalRecordResponse> update(
@Valid @RequestBody UpdateMedicalRecordRequest request,
@AuthenticationPrincipal User currentUser) {

log.info("PUT /api/medical-records/{}", id);
MedicalRecord record = medicalRecordService.getById(id);
medicalRecordPolicy.canUpdate(currentUser, record);

Expand All @@ -183,6 +195,7 @@ public ResponseEntity<MedicalRecordResponse> assignVet(
@Valid @RequestBody AssignVetRequest request,
@AuthenticationPrincipal User currentUser) {

log.info("PUT /api/medical-records/{}/assign-vet vetId={}", id, request.vetId());
MedicalRecord record = medicalRecordService.getById(id);
User vetToAssign = userService.getUserEntityById(request.vetId());
medicalRecordPolicy.canAssignVet(currentUser, record, vetToAssign);
Expand All @@ -202,6 +215,7 @@ public ResponseEntity<MedicalRecordResponse> updateStatus(
@Valid @RequestBody UpdateStatusRequest request,
@AuthenticationPrincipal User currentUser) {

log.info("PUT /api/medical-records/{}/status status={}", id, request.status());
MedicalRecord record = medicalRecordService.getById(id);
medicalRecordPolicy.canUpdateStatus(currentUser, record, request.status());

Expand All @@ -223,6 +237,7 @@ public ResponseEntity<MedicalRecordResponse> close(
@PathVariable UUID id,
@AuthenticationPrincipal User currentUser) {

log.info("PUT /api/medical-records/{}/close", id);
MedicalRecord record = medicalRecordService.getById(id);
medicalRecordPolicy.canClose(currentUser, record);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.example.vet1177.entities.Pet;
import org.example.vet1177.entities.User;
import org.example.vet1177.services.PetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.example.vet1177.services.UserService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,6 +19,8 @@
@RequestMapping("/pets")
public class PetController {

private static final Logger log = LoggerFactory.getLogger(PetController.class);

private final PetService petService;
private final UserService userService;

Expand All @@ -33,6 +37,7 @@ public PetResponse createPet(
@RequestParam(required = false) UUID ownerId,
@Valid @RequestBody PetRequest request
) {
log.info("POST /pets - creating pet for currentUserId={} ownerId={}", currentUserId, ownerId);
Pet saved = petService.createPet(currentUserId, ownerId, request);
return toResponse(saved);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.example.vet1177.dto.request.user.UserRequest;
import org.example.vet1177.dto.response.user.UserResponse;
import org.example.vet1177.services.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -16,6 +18,8 @@
@RequestMapping("/api/users")
public class UserController {

private static final Logger log = LoggerFactory.getLogger(UserController.class);

private final UserService userService;

public UserController(UserService userService) {
Expand All @@ -25,20 +29,23 @@ public UserController(UserService userService) {
//GET /users- Hämta alla användare
@GetMapping
public ResponseEntity<List<UserResponse>> getAllUsers() {
log.info("GET /api/users");
List<UserResponse> users = userService.getAllUsers();
return ResponseEntity.ok(users);
}

// GET /users/{id}- Hämta 1 användare
@GetMapping("/{id}")
public ResponseEntity<UserResponse> getUserById(@PathVariable UUID id) {
log.info("GET /api/users/{}", id);
UserResponse user = userService.getById(id);
return ResponseEntity.ok(user);
}

//POST /users - skapa ny användare
@PostMapping
public ResponseEntity<UserResponse> createUser(@Valid @RequestBody UserRequest request) {
log.info("POST /api/users - creating user");
UserResponse user = userService.createUser(request);
return ResponseEntity.status(HttpStatus.CREATED).body(user);
}
Expand All @@ -47,13 +54,15 @@ public ResponseEntity<UserResponse> createUser(@Valid @RequestBody UserRequest r
@PutMapping("/{id}")
public ResponseEntity<UserResponse> updateUser(@PathVariable UUID id,
@Valid @RequestBody UserUpdateRequest request) {
log.info("PUT /api/users/{}", id);
UserResponse user = userService.updateUser(id, request);
return ResponseEntity.ok(user);
}

//DELETE /users/{id} - Tar bort användare
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteUser(@PathVariable UUID id) {
log.info("DELETE /api/users/{}", id);
userService.deleteUser(id);
return ResponseEntity.noContent().build();
}
Expand Down
Loading