Skip to content

Commit

Permalink
Use lombok
Browse files Browse the repository at this point in the history
Update guava and spring-web dependency version
  • Loading branch information
HariCazorla committed Jul 20, 2022
1 parent 4eb13b6 commit 9c35315
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 155 deletions.
26 changes: 26 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.22</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -44,6 +55,17 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
Expand All @@ -65,6 +87,10 @@
<version>5.9.0-RC1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public Docket api() {
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Expense-tracker API")
.description("Expense-tracker API reference")
.version("1.0").build();
.version("2.0").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.shreeharibi.expensetracker.exceptions.CategoryNotFoundException;
import com.shreeharibi.expensetracker.model.Category;
import com.shreeharibi.expensetracker.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -18,14 +17,11 @@

@RestController
@RequestMapping("api/v1/category")
@RequiredArgsConstructor
@Slf4j
public class CategoryController {
private final CategoryService categoryService;
Logger logger = LoggerFactory.getLogger(CategoryController.class);

@Autowired
public CategoryController(CategoryService categoryService) {
this.categoryService = categoryService;
}
private final CategoryService categoryService;

@GetMapping()
public List<Category> getCategoryByIdorName(
Expand All @@ -34,19 +30,19 @@ public List<Category> getCategoryByIdorName(
List<Category> result = new ArrayList<Category>();
try {
if ((id == null) && (name == null)) {
logger.info("Getting list of all categories...");
log.info("Getting list of all categories...");
result = categoryService.getCategories();
}
else if (name == null) {
logger.info("Getting category by id "+ id +"...");
log.info("Getting category by id "+ id +"...");
result.add(categoryService.getCategoryById(id));
}
else {
logger.info("Getting category by name "+ name +"...");
log.info("Getting category by name "+ name +"...");
result.add(categoryService.getCategoryByName(name));
}
} catch (CategoryNotFoundException e) {
logger.error("Failed to fetch category information...");
log.error("Failed to fetch category information...");
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
}
Expand All @@ -56,10 +52,10 @@ else if (name == null) {
@PostMapping
public void addNewCategory(@RequestBody Category category) {
try {
logger.info("Adding new category "+ category +"...");
log.info("Adding new category "+ category +"...");
categoryService.addNewCategory(category);
} catch (CategoryExistsException e) {
logger.error("Failed to add new category...");
log.error("Failed to add new category...");
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
}
Expand All @@ -71,15 +67,15 @@ public void deleteCategoryByName(@RequestBody Map<String, List<String>> category
boolean status = false;
for (String category : categories) {
try {
logger.info("Deleting category "+ category +"...");
log.info("Deleting category "+ category +"...");
categoryService.deleteCategoryByName(category);
} catch (CategoryNotFoundException e) {
status = true;
continue;
}
}
if (status) {
logger.error("Failed to delete some category...");
log.error("Failed to delete some category...");
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Expand All @@ -89,10 +85,10 @@ public void deleteCategoryById(
@PathVariable("categoryId") Long categoryId
) {
try {
logger.info("Deleting category id "+ categoryId +"...");
log.info("Deleting category id "+ categoryId +"...");
categoryService.deleteCategoryById(categoryId);
} catch (CategoryNotFoundException e) {
logger.error("Failed to delete category...");
log.error("Failed to delete category...");
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
}
Expand All @@ -104,10 +100,10 @@ public ResponseEntity<Category> updateCategory(
@RequestBody Category category
) {
try {
logger.info("update category name "+ oldCategoryName +"...");
log.info("update category name "+ oldCategoryName +"...");
return categoryService.updateCategory(oldCategoryName, category);
} catch (CategoryNotFoundException e) {
logger.error("Failed to update category...");
log.error("Failed to update category...");
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.shreeharibi.expensetracker.model.Expense;
import com.shreeharibi.expensetracker.service.ExpenseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,15 +18,12 @@

@RestController
@RequestMapping(path = "api/v1/expenses")
@RequiredArgsConstructor
@Slf4j
public class ExpenseController {

private final ExpenseService expenseService;

@Autowired
public ExpenseController(ExpenseService expenseService) {
this.expenseService = expenseService;
}

@GetMapping(path = "about")
@ApiOperation("General information on expense-tracker.")
public String selfDescription() {
Expand Down
50 changes: 7 additions & 43 deletions src/main/java/com/shreeharibi/expensetracker/model/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import javax.persistence.*;
import javax.validation.constraints.Size;

@Entity
@ApiModel(description = "class representing the category")
@Table(name = "category")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Category {
@Id
@SequenceGenerator(
Expand All @@ -29,47 +36,4 @@ public class Category {
@Size(max = 500)
@ApiModelProperty(notes = "Description of the category", example = "Fitness supplements", required = false, allowEmptyValue = true)
private String description;

public Category() {
}

public Category(String name, String description) {
this.name = name;
this.description = description;
}

public Category(Long id, String name, String description) {
this.id = id;
this.name = name;
this.description = description;
}

public Long getId() {
return id;
}

public String getName() {
return name;
}

public String getDescription() {
return description;
}

public void setName(String name) {
this.name = name;
}

public void setDescription(String description) {
this.description = description;
}

@Override
public String toString() {
return "Category{" +
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
'}';
}
}
71 changes: 7 additions & 64 deletions src/main/java/com/shreeharibi/expensetracker/model/Expense.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import net.bytebuddy.implementation.bind.annotation.Default;
import org.springframework.boot.context.properties.bind.DefaultValue;

Expand All @@ -13,6 +17,9 @@
@Entity
@Table(name = "expense")
@ApiModel(description = "class representing the expense")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Expense {
@ApiModelProperty(notes = "Name of the item", example = "Shoes", required = true, allowEmptyValue = false)
@NotEmpty(message = "Expense name cannot be empty")
Expand All @@ -39,68 +46,4 @@ public class Expense {
@ApiModelProperty(notes = "Additional information", example = "Nike running shoes", required = false, allowEmptyValue = true)
@Size(max = 500)
private String comments;

public Expense() {
}

public Expense(String name, Long expenseId, Long categoryId, Double amount, LocalDate creationDate, String comments) {
this.name = name;
this.expenseId = expenseId;
this.categoryId = categoryId;
this.amount = amount;
this.creationDate = creationDate;
this.comments = comments;
}

public Expense(String name, Long categoryId, Double amount, LocalDate creationDate, String comments) {
this.name = name;
this.categoryId = categoryId;
this.amount = amount;
this.creationDate = creationDate;
this.comments = comments;
}

public String getName() {
return name;
}

public Long getExpenseId() {
return expenseId;
}

public Long getCategoryId() {
return categoryId;
}

public Double getAmount() {
return amount;
}

public LocalDate getCreationDate() {
return creationDate;
}

public String getComments() {
return comments;
}

public void setName(String name) {
this.name = name;
}

public void setCategoryId(Long categoryId) {
this.categoryId = categoryId;
}

public void setAmount(Double amount) {
this.amount = amount;
}

public void setCreationDate(LocalDate creationDate) {
this.creationDate = creationDate;
}

public void setComments(String comments) {
this.comments = comments;
}
}
Loading

0 comments on commit 9c35315

Please sign in to comment.