Skip to content

Commit

Permalink
Fix: Pull Request 22 issues (#35)
Browse files Browse the repository at this point in the history
* feat: reviewing changes from pull request 22

* feat: mapped only existing props from jwt decoded token

* feat: remove autoimport maven files

* ci: autogenerated JaCoCo coverage badge

* feat: fix review comments

* feat: validations, activity enum serialization, logs

* fix: test passing now

* ci: autogenerated JaCoCo coverage badge

* feat: remove props from activity enum

* ci: autogenerated JaCoCo coverage badge

* test: improve and clean test cases

* ci: autogenerated JaCoCo coverage badge

---------

Co-authored-by: Ci Bot <cibot@users.noreply.github.com>
  • Loading branch information
2 people authored and DerekRoberts committed May 4, 2023
1 parent e5fe55e commit 9da8c8a
Show file tree
Hide file tree
Showing 42 changed files with 1,244 additions and 1,386 deletions.
2 changes: 1 addition & 1 deletion .github/badges/branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/badges/jacoco.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ local.properties
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
*.iml
# *.ipr

# CMake
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ca.bc.gov.backendstartapi.dto;

import ca.bc.gov.backendstartapi.entity.FavouriteActivityEntity;
import ca.bc.gov.backendstartapi.enums.ActivityEnum;
import jakarta.validation.constraints.NotNull;

/**
* This record represents a dto when creating a {@link FavouriteActivityEntity}.
*
* @param activity The activity from {@link ca.bc.gov.backendstartapi.enums.ActivityEnum}
*/
public record FavouriteActivityCreateDto(@NotNull ActivityEnum activity) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ca.bc.gov.backendstartapi.dto;

import ca.bc.gov.backendstartapi.entity.FavouriteActivityEntity;
import jakarta.validation.constraints.NotNull;

/**
* This record represents a dto when updating a {@link FavouriteActivityEntity}.
*
* @param highlighted A boolean representing if the activity is highlighted
* @param enabled a boolean representing if the activity is enabled
*/
public record FavouriteActivityUpdateDto(@NotNull Boolean highlighted, @NotNull Boolean enabled) {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ca.bc.gov.backendstartapi.endpoint;

import ca.bc.gov.backendstartapi.dto.FavouriteActivityCreateDto;
import ca.bc.gov.backendstartapi.dto.FavouriteActivityUpdateDto;
import ca.bc.gov.backendstartapi.entity.FavouriteActivityEntity;
import ca.bc.gov.backendstartapi.service.FavouriteActivityService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/** This class contains all {@link FavouriteActivityEntity} resources that a user needs. */
@Setter
@NoArgsConstructor
@RestController
@RequestMapping("/api/favourite-activities")
public class FavouriteActivityEndpoint {

private FavouriteActivityService favouriteActivityService;

@Autowired
FavouriteActivityEndpoint(FavouriteActivityService favouriteActivityService) {
this.favouriteActivityService = favouriteActivityService;
}

/**
* Creates to the logged user a {@link FavouriteActivityEntity} based on the activity title, that
* comes from {@link ca.bc.gov.backendstartapi.enums.ActivityEnum}.
*
* @param createDto a {@link FavouriteActivityCreateDto} with the activity title
* @return a {@link FavouriteActivityEntity} created
*/
@PostMapping(consumes = "application/json", produces = "application/json")
@PreAuthorize("hasRole('user_write')")
public FavouriteActivityEntity createUserActivity(
@Valid @RequestBody FavouriteActivityCreateDto createDto) {
return favouriteActivityService.createUserActivity(createDto);
}

/**
* Retrieve all {@link FavouriteActivityEntity} bound to the user that made the request.
*
* @return a list of {@link FavouriteActivityEntity}
*/
@GetMapping(produces = "application/json")
@PreAuthorize("hasRole('user_read')")
public List<FavouriteActivityEntity> getUserActivities() {
return favouriteActivityService.getAllUserFavoriteActivities();
}

/**
* Update a {@link FavouriteActivityEntity} of the logged user.
*
* @param id The id of the {@link FavouriteActivityEntity}
* @param updateDto a {@link FavouriteActivityUpdateDto} containing highlighted and enabled states
* @return the {@link FavouriteActivityEntity} updated
*/
@PutMapping(value = "/{id}", consumes = "application/json", produces = "application/json")
@PreAuthorize("hasRole('user_write')")
public FavouriteActivityEntity updateFavoriteActivity(
@PathVariable Long id, @Valid @RequestBody FavouriteActivityUpdateDto updateDto) {
return favouriteActivityService.updateUserActivity(id, updateDto);
}

/**
* Delete a user's {@link FavouriteActivityEntity}.
*
* @param id The id of the {@link FavouriteActivityEntity}
*/
@DeleteMapping(value = "/{id}", produces = "application/json")
@PreAuthorize("hasRole('user_write')")
public void deleteFavoriteActivity(@PathVariable Long id) {
favouriteActivityService.deleteUserActivity(id);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package ca.bc.gov.backendstartapi.entity;

import ca.bc.gov.backendstartapi.exception.NotRemovableEntityException;
import com.fasterxml.jackson.annotation.JsonIgnore;
import ca.bc.gov.backendstartapi.enums.ActivityEnum;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.PreRemove;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.With;

/** This class represents a user's favorite activity in the database. */
Expand All @@ -23,32 +20,26 @@
@Setter
@With
@AllArgsConstructor
@Table(name = "favorite_activity")
public class FavoriteActivityEntity {
@Table(name = "favourite_activity")
public class FavouriteActivityEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
@JsonIgnore
private UserEntity user;
@Column(name = "user_id")
private String userId;

@Column(name = "activity_title", updatable = false)
private String activityTitle;
@Column(name = "activity", updatable = false)
@Enumerated(value = EnumType.STRING)
private ActivityEnum activity;

@Column private Boolean highlighted;

@Column private Boolean enabled;

public FavoriteActivityEntity() {
public FavouriteActivityEntity() {
this.highlighted = false;
this.enabled = true;
}

@PreRemove
private void preRemove() {
throw new NotRemovableEntityException();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ca.bc.gov.backendstartapi.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/** This class represents a system User in the database. */
@Entity
@Getter
@Setter
@Table(name = "user_profile")
@AllArgsConstructor
@NoArgsConstructor
public class UserProfileEntity {

@Id
@Column(name = "user_id")
private String userId;

@Column(name = "dark_theme")
private Boolean darkTheme;
}
Loading

0 comments on commit 9da8c8a

Please sign in to comment.