Skip to content

Commit

Permalink
fix backend put command for website
Browse files Browse the repository at this point in the history
  • Loading branch information
dieter.jordens committed Feb 23, 2021
1 parent b69b071 commit f032cd1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.RolesAllowed;
Expand All @@ -26,7 +27,7 @@ public Collection<Article> findAll() {

@PutMapping("api/articles")
@RolesAllowed(Role.ADMIN)
public Article save(Article article) {
public Article save(@RequestBody Article article) {
return articleService.save(article);
}
}
14 changes: 2 additions & 12 deletions src/main/java/dj/personal/website/article/ArticleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Collection;
import java.util.Comparator;

Expand All @@ -25,17 +26,6 @@ public Collection<Article> findAll() {
}

public Article save(Article article) {
Article updatedArticle = articleRepository.findById(article.getId())
.map(oldArticle -> Article.builder()
.id(oldArticle.getId())
.category(article.getCategory())
.introduction(article.getIntroduction())
.publicationDate(article.getPublicationDate())
.title(article.getTitle())
.url(article.getUrl())
.build()
).orElse(article);

return articleRepository.save(updatedArticle);
return articleRepository.save(article);
}
}
1 change: 0 additions & 1 deletion src/main/java/dj/personal/website/book/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Book {
@Id
private Long isbn;

@Column(unique = true)
private String title;

private String authors;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cors.exposedHeaders=
cors.allowCredentials=
cors.maxAge=

spring.datasource.url=jdbc:mysql://mysqldb:3306/data
spring.datasource.url=jdbc:mysql://0.0.0.0:3306/data
spring.datasource.username=dieter
spring.datasource.password=secret
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Expand Down

0 comments on commit f032cd1

Please sign in to comment.