diff --git a/.github/workflows/new-pr.yml b/.github/workflows/new-pr.yml index 00f4fd8..84c3aa8 100644 --- a/.github/workflows/new-pr.yml +++ b/.github/workflows/new-pr.yml @@ -15,6 +15,6 @@ jobs: uses: Ilshidur/action-discord@0.3.0 with: args: | - Nova contribuição recebida. \(>_<)/ + Nova contribuição recebida. \\(>_<)/ ${{ github.event.pull_request.title }} ${{ github.event.pull_request.html_url}} diff --git a/README.md b/README.md index 2ef7edb..80d4d06 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,14 @@ Add in VMArguments to run in an IDE -Dspring.profiles.active=local +### Development data + +You can use the file [data.sql](src/test/resources/db/data/data.sql) to insert data to your local db. + +### Cleaning DB + +All data volume is mapped to directory `tmp`. You can delete this folder to get rid of development data. + ## How to run You can run with maven @@ -44,7 +52,7 @@ tip: --rm parameter will exclude container image after execution and it cause da ### Writing Tests -If you wanna use db connection on your test you must extend the class `AbstractIntegrationTest`. This class will run the docker container and configure the spring datasource. +If you want to use db connection on your test you must extend the class `AbstractIntegrationTest`. This class will run the docker container and configure the spring datasource. ## How to contribute diff --git a/openapi.yaml b/openapi.yaml index 9b846d0..5c66ed0 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -42,9 +42,9 @@ paths: - bearerAuth: [] tags: - Author - /cordels: + /cordels/summaries: get: - summary: "Retrieve all cordels by pages" + summary: "Retrieve all summaries by pages" parameters: - name: page in: query @@ -79,6 +79,7 @@ paths: $ref: '#/components/schemas/ReponsePage' tags: - Cordel + /cordels: post: summary: "Create a new cordel" requestBody: @@ -94,7 +95,7 @@ paths: - Cordel /cordels/{id}: get: - summary: "Get a specific cordel with all content" + summary: "Get a cordel with full content" parameters: - name: "id" in: "path" @@ -108,7 +109,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/FullCordel' + $ref: '#/components/schemas/Cordel' 404: description: "Not found" tags: @@ -240,6 +241,8 @@ components: content: type: string description: cordel text + xilogravuraUrl: + type: string published: type: boolean tags: @@ -261,30 +264,6 @@ components: xilogravuraUrl: type: string description: image url - FullCordel: - type: object - description: Cordel data with content. For operations like POST and PUT the inner objects only need the id - properties: - id: - type: integer - description: cordel id - author: - $ref: '#/components/schemas/Author' - title: - type: string - description: cordel title - description: - type: string - description: cordel's description - content: - type: string - description: cordel text - xilogravura: - $ref: '#/components/schemas/Xilogravura' - tags: - type: array - items: - type: string Page: type: object properties: @@ -333,16 +312,6 @@ components: type: string expiresAt: type: integer - Xilogravura: - type: object - properties: - id: - type: integer - description: - type: string - url: - type: string - securitySchemes: bearerAuth: type: http diff --git a/pom.xml b/pom.xml index a750040..01c3345 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,13 @@ org.springframework.boot spring-boot-starter-parent - 2.5.1 + 2.5.5 br.com.itsmemario ecordel - 0.6.0-SNAPSHOT + 1.0.0-SNAPSHOT e-cordel e-reader for cordels @@ -180,7 +180,10 @@ org.owasp dependency-check-maven - 6.2.0 + 6.3.2 + + 6 + diff --git a/src/main/java/br/com/itsmemario/ecordel/author/AuthorDto.java b/src/main/java/br/com/itsmemario/ecordel/author/AuthorDto.java index 7ae340e..149d2d9 100644 --- a/src/main/java/br/com/itsmemario/ecordel/author/AuthorDto.java +++ b/src/main/java/br/com/itsmemario/ecordel/author/AuthorDto.java @@ -30,6 +30,15 @@ public class AuthorDto { private String name; private String email; + public static AuthorDto of(Author author) { + var dto = new AuthorDto(); + dto.setName(author.getName()); + dto.setAbout(author.getAbout()); + dto.setEmail(author.getEmail()); + dto.setId(author.getId()); + return dto; + } + public Author toEntity() { var author = new Author(); author.setId(id); diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/Cordel.java b/src/main/java/br/com/itsmemario/ecordel/cordel/Cordel.java index c0b5596..a9ef3b7 100644 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/Cordel.java +++ b/src/main/java/br/com/itsmemario/ecordel/cordel/Cordel.java @@ -18,15 +18,15 @@ package br.com.itsmemario.ecordel.cordel; import br.com.itsmemario.ecordel.author.Author; -import br.com.itsmemario.ecordel.xilogravura.Xilogravura; import javax.persistence.*; import javax.validation.constraints.NotBlank; +import java.util.Collections; import java.util.Objects; import java.util.Set; @Entity -public class Cordel implements CordelView { +public class Cordel { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @@ -38,9 +38,7 @@ public class Cordel implements CordelView { private String title; @NotBlank private String content; - @OneToOne - @JoinColumn(name = "xilogravura_id") - private Xilogravura xilogravura; + private String xilogravuraUrl; private String description; @ElementCollection @CollectionTable(name = "cordel_tags") @@ -87,12 +85,12 @@ public void setContent(String content) { this.content = content; } - public Xilogravura getXilogravura() { - return xilogravura; + public String getXilogravuraUrl() { + return xilogravuraUrl; } - public void setXilogravura(Xilogravura xilogravura) { - this.xilogravura = xilogravura; + public void setXilogravuraUrl(String xilogravuraUrl) { + this.xilogravuraUrl = xilogravuraUrl; } public String getDescription() { @@ -104,7 +102,7 @@ public void setDescription(String description) { } public Set getTags() { - return tags; + return Collections.unmodifiableSet(tags); } public void setTags(Set tags) { diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelController.java b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelController.java index cb0218d..574a94c 100644 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelController.java +++ b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelController.java @@ -17,7 +17,6 @@ package br.com.itsmemario.ecordel.cordel; -import br.com.itsmemario.ecordel.xilogravura.Xilogravura; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -45,19 +44,20 @@ public class CordelController { } @GetMapping("{id}") - public ResponseEntity getCordel(@PathVariable Long id) { + public ResponseEntity getCordel(@PathVariable Long id) { logger.info("request received get cordel by id: {}", id); Optional cordel = service.findById(id); if (cordel.isPresent()) { - return ResponseEntity.ok(cordel.get()); + CordelDto body = CordelDto.of(cordel.get()); + return ResponseEntity.ok(body); } else { logger.info("cordel with id {} not fond", id); return ResponseEntity.notFound().build(); } } - @GetMapping + @GetMapping("summaries") public Page getCordels(@RequestParam(required = false) String title, @RequestParam(defaultValue = "true") boolean published, Pageable pageable) { @@ -76,14 +76,14 @@ public ResponseEntity create(@RequestBody @Valid CordelDto dto, UriCompo } @PutMapping("{id}/xilogravura") - public ResponseEntity putXilogravura(@PathVariable Long id, Xilogravura xilogravura, @RequestParam("file") MultipartFile file) { + public ResponseEntity putXilogravura(@PathVariable Long id, @RequestParam("file") MultipartFile file) { logger.info("request received, update xilogravura for cordel: {}", id); - Cordel cordel = service.updateXilogravura(id, xilogravura, file); - return ResponseEntity.ok(cordel); + Cordel cordel = service.updateXilogravura(id, file); + return ResponseEntity.ok(CordelDto.of(cordel)); } @PutMapping("{id}") - public ResponseEntity update(@RequestBody @Valid CordelDto dto, @PathVariable Long id) { + public ResponseEntity update(@RequestBody @Valid CordelDto dto, @PathVariable Long id) { logger.info("request received update cordel with id: {}", id); Optional existingCordel = service.findById(id); @@ -93,8 +93,8 @@ public ResponseEntity update(@RequestBody @Valid CordelDto dto, @PathVar var cordel = dto.toEntity(); cordel.setId(id); - - return ResponseEntity.ok(service.save(cordel)); + Cordel updatedCordel = service.save(cordel); + return ResponseEntity.ok(CordelDto.of(updatedCordel)); } } diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelDto.java b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelDto.java index b9c0e7a..1761b5a 100644 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelDto.java +++ b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelDto.java @@ -41,6 +41,21 @@ public class CordelDto { private String content; private boolean published; private Set tags; + private String xilogravuraUrl; + + public static CordelDto of( Cordel cordel ){ + var dto = new CordelDto(); + var authorDto = AuthorDto.of(cordel.getAuthor()); + dto.setAuthor(authorDto); + dto.setTags(cordel.getTags()); + dto.setPublished(cordel.isPublished()); + dto.setId(cordel.getId()); + dto.setContent(cordel.getContent()); + dto.setDescription(cordel.getDescription()); + dto.setTitle(cordel.getTitle()); + dto.setXilogravuraUrl(cordel.getXilogravuraUrl()); + return dto; + } public Cordel toEntity() { var cordel = new Cordel(); @@ -51,6 +66,7 @@ public Cordel toEntity() { cordel.setContent( content ); cordel.setPublished( published ); cordel.setTags( tags ); + cordel.setXilogravuraUrl( xilogravuraUrl ); return cordel; } diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelRepository.java b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelRepository.java index 25bfc6f..01c3392 100644 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelRepository.java +++ b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelRepository.java @@ -20,9 +20,16 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; -interface CordelRepository extends CustomCordelRepository, JpaRepository{ +interface CordelRepository extends JpaRepository{ - Page findAllProjectedBy(Pageable pageable); + @Query("SELECT new br.com.itsmemario.ecordel.cordel.CordelSummary(c.id, c.title, c.xilogravuraUrl, a.name) " + + "FROM Cordel c JOIN c.author a WHERE c.published = :published") + Page findAllByPublished(boolean published, Pageable pageable); + + @Query("SELECT new br.com.itsmemario.ecordel.cordel.CordelSummary(c.id, c.title, c.xilogravuraUrl, a.name) " + + "FROM Cordel c JOIN c.author a WHERE c.published = :published and lower(c.title) LIKE lower( :title ) ") + Page findAllByPublishedAndTitleLike(boolean published, String title, Pageable pageable); } diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelService.java b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelService.java index 9f17d62..ebdae6c 100644 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelService.java +++ b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelService.java @@ -17,7 +17,6 @@ package br.com.itsmemario.ecordel.cordel; -import br.com.itsmemario.ecordel.xilogravura.Xilogravura; import br.com.itsmemario.ecordel.xilogravura.XilogravuraService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -25,12 +24,13 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -import java.util.List; import java.util.Optional; @Service public class CordelService { + private static final int MINIMUM_SIZE = 3; + private CordelRepository repository; private XilogravuraService xilogravuraService; @@ -41,36 +41,36 @@ public CordelService(CordelRepository repository, XilogravuraService xilogravura this.xilogravuraService = xilogravuraService; } - public Page getCordels(Pageable pageable) { - return repository.findAllProjectedBy(pageable); - } - public Cordel save(Cordel cordel) { return repository.save(cordel); } - public Page findByTags(List tags, Pageable pageable){ - return repository.findByTags(tags, pageable); - } - public Optional findById(Long id) { return repository.findById(id); } public Page findPublishedByTitle(boolean published, String title, Pageable pageable) { - return repository.findPublishedByTitleLike(published, title, pageable); + if (isAValidString(title)) { + return repository.findAllByPublishedAndTitleLike(published, String.format("%%%s%%", title), pageable); + } + + return repository.findAllByPublished(published, pageable); } - public Cordel updateXilogravura(Long cordelId, Xilogravura xilogravura, MultipartFile file) { + public Cordel updateXilogravura(Long cordelId, MultipartFile file) { Optional byId = findById(cordelId); if(byId.isPresent()) { Cordel cordel = byId.get(); - Xilogravura xilogravuraWithFile = xilogravuraService.createXilogravuraWithFile(xilogravura, file); - cordel.setXilogravura(xilogravuraWithFile); + String xilogravuraUrl = xilogravuraService.createXilogravuraWithFile(file); + cordel.setXilogravuraUrl( xilogravuraUrl ); return save(cordel); }else{ throw new CordelNotFoundException(); } } + + private boolean isAValidString(String title) { + return title != null && title.length() >= MINIMUM_SIZE; + } } diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelView.java b/src/main/java/br/com/itsmemario/ecordel/cordel/CordelView.java deleted file mode 100644 index 42ee317..0000000 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/CordelView.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2020 Projeto e-cordel (http://ecordel.com.br) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package br.com.itsmemario.ecordel.cordel; - -import br.com.itsmemario.ecordel.author.AuthorView; -import br.com.itsmemario.ecordel.xilogravura.Xilogravura; - -import java.util.Set; - - -public interface CordelView { - - Long getId(); - AuthorView getAuthor(); - String getTitle(); - Xilogravura getXilogravura(); - String getDescription(); - Set getTags(); - -} diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/CustomCordelRepository.java b/src/main/java/br/com/itsmemario/ecordel/cordel/CustomCordelRepository.java deleted file mode 100644 index 64c23dc..0000000 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/CustomCordelRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020-2021 Projeto e-cordel (http://ecordel.com.br) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package br.com.itsmemario.ecordel.cordel; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -interface CustomCordelRepository { - - Page findByTags(List tags, Pageable pageable); - - Page findPublishedByTitleLike(boolean published, String title, Pageable pageable); -} diff --git a/src/main/java/br/com/itsmemario/ecordel/cordel/CustomCordelRepositoryImpl.java b/src/main/java/br/com/itsmemario/ecordel/cordel/CustomCordelRepositoryImpl.java deleted file mode 100644 index 7d95605..0000000 --- a/src/main/java/br/com/itsmemario/ecordel/cordel/CustomCordelRepositoryImpl.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2020-2021 Projeto e-cordel (http://ecordel.com.br) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package br.com.itsmemario.ecordel.cordel; - -import br.com.itsmemario.ecordel.author.Author; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.TypedQuery; -import java.math.BigInteger; -import java.util.List; -import java.util.stream.Collectors; - - -@Repository -@Transactional(readOnly = true) -class CustomCordelRepositoryImpl implements CustomCordelRepository { - - private static final int MINIMUM_SIZE = 3; - private static final String TAGS = "tags"; - private static final String LIMIT = "limit"; - private static final String OFFSET = "offset"; - - private static final String LIMIT_SQL = " limit :limit offset :offset "; - - private static final String FIND_BY_TAGS_SQL_FROM = " from cordel_tags ct \n" + - "join cordel c on c.id = ct.cordel_id \n" + - "join author a on a.id = c.author_id \n" + - "where ct.tags in (:tags) \n"; - - private static final String FIND_BY_TAGS_SQL = "select distinct(c.id) as id, c.title, c.description, a.name, a.email " + FIND_BY_TAGS_SQL_FROM + LIMIT_SQL; - - private static final String FIND_BY_TAGS_SQL_COUNT = "select COUNT(distinct(c.id)) " + FIND_BY_TAGS_SQL_FROM ; - - private static final String CORDEL_SUMMARY = " SELECT new br.com.itsmemario.ecordel.cordel.CordelSummary(c.id, c.title, x.url, a.name) " + - " FROM Cordel c JOIN c.author a LEFT JOIN c.xilogravura x WHERE c.published = :published "; - - private static final String COUNT_CORDEL_SUMMARY = "SELECT COUNT(c.id) FROM Cordel c JOIN c.author a " + - " LEFT JOIN c.xilogravura x WHERE c.published = :published "; - - private static final String TITLE = "title"; - public static final String PUBLISHED = "published"; - - @PersistenceContext - private EntityManager entityManager; - - @Override - public Page findByTags(List tags, Pageable pageable) { - long count = countResults(tags); - if(count == 0) return Page.empty(pageable); - - var query = entityManager.createNativeQuery(FIND_BY_TAGS_SQL); - query.setParameter(TAGS, tags); - query.setParameter(LIMIT, pageable.getPageSize()); - query.setParameter(OFFSET, pageable.getOffset()); - List resultList = query.getResultList(); - List cordels = resultList.stream().map(this::buildCordel).collect(Collectors.toList()); - - return new PageImpl<>(cordels, pageable, count); - } - - private long countResults(List tags) { - BigInteger count = (BigInteger) entityManager.createNativeQuery(FIND_BY_TAGS_SQL_COUNT).setParameter(TAGS, tags).getSingleResult(); - return count.longValue(); - } - - private Cordel buildCordel(Object[] fields) { - Cordel cordel = new Cordel(); - cordel.setId(((BigInteger)fields[0]).longValue()); - cordel.setTitle(String.valueOf(fields[1])); - cordel.setDescription(String.valueOf(fields[2])); - cordel.setAuthor(buildAuthor(fields[3],fields[4])); - return cordel; - } - - private Author buildAuthor(Object name, Object email) { - Author author = new Author(String.valueOf(name)); - author.setEmail(String.valueOf(email)); - return author; - } - - @Override - public Page findPublishedByTitleLike(boolean published, String title, Pageable pageable) { - - StringBuilder sql = new StringBuilder(CORDEL_SUMMARY); - StringBuilder countSql = new StringBuilder(COUNT_CORDEL_SUMMARY); - - TypedQuery countQuery = entityManager.createQuery(countSql.toString(), Long.class); - TypedQuery query = entityManager.createQuery(sql.toString(), CordelSummary.class); - - if(isAValidString(title)){ - query = addTitleFilter(title, sql, CordelSummary.class); - countQuery = addTitleFilter(title, countSql, Long.class); - } - - countQuery.setParameter(PUBLISHED, published); - Long count = countQuery.getSingleResult(); - if(count == 0) return Page.empty(pageable); - - query.setMaxResults(pageable.getPageSize()); - query.setFirstResult((int)pageable.getOffset()); - query.setParameter(PUBLISHED, published); - - List resultList = query.getResultList(); - - return new PageImpl<>(resultList, pageable, count); - } - - private boolean isAValidString(String title) { - return title != null && title.length() >= MINIMUM_SIZE; - } - - private TypedQuery addTitleFilter(String title, StringBuilder sql, Class clazz) { - var where = " AND lower(c.title) LIKE lower( :title ) "; - TypedQuery query; - sql.append(where); - query = entityManager.createQuery(sql.toString(), clazz); - query.setParameter(TITLE, String.format("%%%s%%", title)); - return query; - } - -} diff --git a/src/main/java/br/com/itsmemario/ecordel/xilogravura/Xilogravura.java b/src/main/java/br/com/itsmemario/ecordel/xilogravura/Xilogravura.java deleted file mode 100644 index 1d6a5d9..0000000 --- a/src/main/java/br/com/itsmemario/ecordel/xilogravura/Xilogravura.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2020 Projeto e-cordel (http://ecordel.com.br) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package br.com.itsmemario.ecordel.xilogravura; - -import br.com.itsmemario.ecordel.author.Author; - -import javax.persistence.*; - -@Entity -public class Xilogravura { - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - private Long id; - - private String url; - private String description; - - @ManyToOne - @JoinColumn(name = "xilografo_id") - private Author xilografo; - - public Long getId() { - return id; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Author getXilografo() { - return xilografo; - } - - public void setXilografo(Author xilografo) { - this.xilografo = xilografo; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/src/main/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraRepository.java b/src/main/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraRepository.java deleted file mode 100644 index d402c2e..0000000 --- a/src/main/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 Projeto e-cordel (http://ecordel.com.br) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package br.com.itsmemario.ecordel.xilogravura; - -import org.springframework.data.jpa.repository.JpaRepository; - -interface XilogravuraRepository extends JpaRepository { - -} diff --git a/src/main/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraService.java b/src/main/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraService.java index 1c1c4b3..095a1bb 100644 --- a/src/main/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraService.java +++ b/src/main/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraService.java @@ -30,35 +30,25 @@ public class XilogravuraService { private static final String JPG = ".jpg"; - private final String XILOGRAVURA_NAME_PATTERN = "http://xilos.ecordel.com.br/{file}"; - private XilogravuraRepository repository; private FileManager fileManager; @Autowired - public XilogravuraService(XilogravuraRepository repository, FileManager fileManager) { - this.repository = repository; + public XilogravuraService(FileManager fileManager) { this.fileManager = fileManager; } - public Xilogravura save(Xilogravura xilogravura){ - return repository.save(xilogravura); - } - - public Xilogravura createXilogravuraWithFile(Xilogravura xilogravura, MultipartFile file){ + public String createXilogravuraWithFile(MultipartFile file){ try { - String fileName = generateRandomFileName(); - String url = fileManager.saveFile(file.getBytes(), fileName); - xilogravura.setUrl(url); - return repository.save(xilogravura); + var fileName = generateRandomFileName(); + return fileManager.saveFile(file.getBytes(), fileName); } catch (IOException e) { - e.printStackTrace(); throw new FileProcessException("Error while saving file", e); } } private String generateRandomFileName() { - return UUID.randomUUID().toString() + JPG; + return UUID.randomUUID() + JPG; } } diff --git a/src/main/resources/db/migration/V1__schema-definition.sql b/src/main/resources/db/migration/V1.0.0__schema-definition.sql similarity index 71% rename from src/main/resources/db/migration/V1__schema-definition.sql rename to src/main/resources/db/migration/V1.0.0__schema-definition.sql index 729231d..8d4e469 100644 --- a/src/main/resources/db/migration/V1__schema-definition.sql +++ b/src/main/resources/db/migration/V1.0.0__schema-definition.sql @@ -5,8 +5,8 @@ CREATE TABLE public.author ( id bigint primary key, - name character varying(255), - about character varying(255), + name character varying(255) not null , + about text, email character varying(255) ); @@ -19,32 +19,15 @@ CREATE SEQUENCE public.author_id_seq ALTER SEQUENCE public.author_id_seq OWNED BY public.author.id; -CREATE TABLE public.xilogravura ( - id bigint primary key, - description character varying(255), - url character varying(255), - xilografo_id bigint, - FOREIGN KEY (xilografo_id) REFERENCES author (id) -); - -CREATE SEQUENCE public.xilogravura_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - -ALTER SEQUENCE public.xilogravura_id_seq OWNED BY public.xilogravura.id; - CREATE TABLE public.cordel ( id bigint primary key, author_id bigint, content text, description character varying(255), title character varying(255), - xilogravura_id bigint, - FOREIGN KEY (author_id) REFERENCES author (id), - FOREIGN KEY (xilogravura_id) REFERENCES xilogravura (id) + published boolean not null default false, + xilogravura_url character varying(255), + FOREIGN KEY (author_id) REFERENCES author (id) ); CREATE SEQUENCE public.cordel_id_seq @@ -101,8 +84,28 @@ ALTER TABLE ONLY public.cordel ALTER COLUMN id SET DEFAULT nextval('public.corde ALTER TABLE ONLY public.author ALTER COLUMN id SET DEFAULT nextval('public.author_id_seq'::regclass); -ALTER TABLE ONLY public.xilogravura ALTER COLUMN id SET DEFAULT nextval('public.xilogravura_id_seq'::regclass); - ALTER TABLE ONLY public.cordel_user ALTER COLUMN id SET DEFAULT nextval('public.cordel_user_id_seq'::regclass); ALTER TABLE ONLY public.cordel_authority ALTER COLUMN id SET DEFAULT nextval('public.cordel_authority_id_seq'::regclass); + +-- token + +CREATE TABLE IF NOT EXISTS jwt_token ( + id bigint primary key, + expiration bigint, + secret_key TEXT, + active boolean not null +); + +CREATE SEQUENCE IF NOT EXISTS jwt_token_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE public.jwt_token_id_seq OWNED BY jwt_token.id; + +ALTER TABLE ONLY jwt_token ALTER COLUMN id SET DEFAULT nextval('public.jwt_token_id_seq'::regclass); + +INSERT INTO jwt_token (id, expiration, secret_key, active) VALUES ((SELECT nextval('public.jwt_token_id_seq')), 86400000, 'rm''!@N=Ke!~p8VTA2ZRK~nMDQX5Uvm!m''D&]{@Vr?G;2?XhbC:Qa#9#eMLN\}x3?JR3.2zr~v)gYF^8\:8>:XfB:Ww75N/emt9Yj[bQMNCWwW\J?N,nvH.<2\.r~w]*e~vgak)X"v8H`MH/7"2E`,^k@nL/zBq`}C6tT*cCSVC^c]-L}&/', true); diff --git a/src/main/resources/db/migration/V1.1__add-published-field.sql b/src/main/resources/db/migration/V1.1__add-published-field.sql deleted file mode 100644 index fc9f115..0000000 --- a/src/main/resources/db/migration/V1.1__add-published-field.sql +++ /dev/null @@ -1,8 +0,0 @@ --- schema definition v1 --- --- Copyright 2021 Projeto e-cordel. --- e-cordel project (http://www.ecordel.com.br/). - -alter table public.cordel add column published boolean not null default false; - -update public.cordel set published = true; diff --git a/src/main/resources/db/migration/V1.2__author-type-changed-field.sql b/src/main/resources/db/migration/V1.2__author-type-changed-field.sql deleted file mode 100644 index e3f4988..0000000 --- a/src/main/resources/db/migration/V1.2__author-type-changed-field.sql +++ /dev/null @@ -1,8 +0,0 @@ --- schema definition v1 --- --- Copyright 2021 Projeto e-cordel. --- e-cordel project (http://www.ecordel.com.br/). - -ALTER TABLE public.author ALTER COLUMN about TYPE text; - -ALTER TABLE public.author ALTER COLUMN name SET NOT NULL; diff --git a/src/main/resources/db/migration/V1.3__create-jwt-token-table.sql b/src/main/resources/db/migration/V1.3__create-jwt-token-table.sql deleted file mode 100644 index 9ef1049..0000000 --- a/src/main/resources/db/migration/V1.3__create-jwt-token-table.sql +++ /dev/null @@ -1,24 +0,0 @@ --- schema definition v1 --- --- Copyright 2021 Projeto e-cordel. --- e-cordel project (http://www.ecordel.com.br/). - -CREATE TABLE IF NOT EXISTS jwt_token ( - id bigint primary key, - expiration bigint, - secret_key TEXT, - active boolean not null -); - -CREATE SEQUENCE IF NOT EXISTS jwt_token_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - -ALTER SEQUENCE public.jwt_token_id_seq OWNED BY jwt_token.id; - -ALTER TABLE ONLY jwt_token ALTER COLUMN id SET DEFAULT nextval('public.jwt_token_id_seq'::regclass); - -INSERT INTO jwt_token (id, expiration, secret_key, active) VALUES ((SELECT nextval('public.jwt_token_id_seq')), 86400000, 'rm''!@N=Ke!~p8VTA2ZRK~nMDQX5Uvm!m''D&]{@Vr?G;2?XhbC:Qa#9#eMLN\}x3?JR3.2zr~v)gYF^8\:8>:XfB:Ww75N/emt9Yj[bQMNCWwW\J?N,nvH.<2\.r~w]*e~vgak)X"v8H`MH/7"2E`,^k@nL/zBq`}C6tT*cCSVC^c]-L}&/', true); \ No newline at end of file diff --git a/src/test/java/br/com/itsmemario/ecordel/cordel/CordelControllerTest.java b/src/test/java/br/com/itsmemario/ecordel/cordel/CordelControllerTest.java index 457f32b..60808a7 100644 --- a/src/test/java/br/com/itsmemario/ecordel/cordel/CordelControllerTest.java +++ b/src/test/java/br/com/itsmemario/ecordel/cordel/CordelControllerTest.java @@ -85,7 +85,7 @@ void ifACordelDoesNotExists_ItMustReturn404() { void ifPublishedParamIsFalse_theOnlyDraftCordelsMustBeRetrieved() { insertCordel(false); - ResponseEntity response = restTemplate.getForEntity(getBaseUrl()+"?published=false", Map.class); + ResponseEntity response = restTemplate.getForEntity(getBaseUrl()+"/summaries?published=false", Map.class); assertThat(response.getBody()).containsEntry("totalElements",1); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); } @@ -94,7 +94,7 @@ void ifPublishedParamIsFalse_theOnlyDraftCordelsMustBeRetrieved() { void ifPublishedParamIsNotInformed_itMustBeConsideredTrue() { insertCordel(true); - ResponseEntity response = restTemplate.getForEntity(getBaseUrl(), Map.class); + ResponseEntity response = restTemplate.getForEntity(getBaseUrl()+"/summaries", Map.class); assertThat(response.getBody()).containsEntry("totalElements",1); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/src/test/java/br/com/itsmemario/ecordel/cordel/CordelRepositoryTest.java b/src/test/java/br/com/itsmemario/ecordel/cordel/CordelRepositoryTest.java index c0da494..5e1d80e 100644 --- a/src/test/java/br/com/itsmemario/ecordel/cordel/CordelRepositoryTest.java +++ b/src/test/java/br/com/itsmemario/ecordel/cordel/CordelRepositoryTest.java @@ -17,7 +17,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -56,30 +55,14 @@ void saveBigTextAsContent() throws IOException { .extracting(Cordel::getContent).asString().isNotEmpty(); } - @Test - void findAllProjectedBy() { - insertNewCordel(true); - Page cordelSummaries = repository.findAllProjectedBy(Pageable.unpaged()); - assertThat(cordelSummaries).isNotEmpty(); - assertThat(cordelSummaries.getContent().get(0)).isInstanceOf(CordelView.class); - } - - @Test - void findByTagsProjectedBy() { - insertNewCordel(true); - Page cordels = repository.findByTags(Arrays.asList("tag1", "tag2"), PageRequest.of(0,1)); - assertThat(cordels).hasSize(1); - assertThat(cordels.getContent().get(0)).extracting(CordelView::getDescription).isEqualTo("description"); - } - @Test void findByPublishedTitleLike() { insertNewCordel(true); - Page page = repository.findPublishedByTitleLike(true, "tit", PageRequest.of(0,10)); - page.getContent().forEach(cordel -> System.out.println(cordel.getTitle())); + Page page = repository.findAllByPublishedAndTitleLike(true, "%tit%", PageRequest.of(0,10)); + assertThat(page.getContent().get(0).getAuthorName()).isEqualTo("name"); assertThat(page).hasSize(1); - page = repository.findPublishedByTitleLike(true, "aaa", PageRequest.of(0,10)); + page = repository.findAllByPublishedAndTitleLike(true, "%aaa%", PageRequest.of(0,10)); assertThat(page).hasSize(0); } @@ -87,7 +70,7 @@ void findByPublishedTitleLike() { void testPaginationResultsByPublishedTitle() throws Exception { IntStream.range(0,5).forEach( i -> insertNewCordel(true)); - Page page = repository.findPublishedByTitleLike(true, "tit", PageRequest.of(1,3)); + Page page = repository.findAllByPublishedAndTitleLike(true, "%tit%", PageRequest.of(1,3)); page.getContent().forEach(cordel -> System.out.println(cordel.getTitle())); assertThat(page).hasSize(2); } @@ -95,10 +78,10 @@ void testPaginationResultsByPublishedTitle() throws Exception { @Test void findNotPublishedWorkTest() { insertNewCordel(false); - Page page = repository.findPublishedByTitleLike(true, "tit", PageRequest.of(0, 10)); + Page page = repository.findAllByPublishedAndTitleLike(true, "%tit%", PageRequest.of(0, 10)); assertThat(page).isEmpty(); - page = repository.findPublishedByTitleLike(false, "tit", PageRequest.of(0, 10)); + page = repository.findAllByPublishedAndTitleLike(false, "%tit%", PageRequest.of(0, 10)); assertThat(page).isNotEmpty().hasSize(1); } diff --git a/src/test/java/br/com/itsmemario/ecordel/cordel/CordelServiceTest.java b/src/test/java/br/com/itsmemario/ecordel/cordel/CordelServiceTest.java new file mode 100644 index 0000000..5b03b54 --- /dev/null +++ b/src/test/java/br/com/itsmemario/ecordel/cordel/CordelServiceTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021 Projeto e-cordel (http://ecordel.com.br) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package br.com.itsmemario.ecordel.cordel; + +import br.com.itsmemario.ecordel.xilogravura.XilogravuraService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.data.domain.Pageable; + +import static org.mockito.Mockito.times; + +class CordelServiceTest { + + @Mock + private XilogravuraService xilogravuraService; + @Mock + private CordelRepository cordelRepository; + + private final Pageable page = Pageable.unpaged(); + private CordelService cordelService; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + cordelService = new CordelService(cordelRepository, xilogravuraService); + } + + @Test + void testIfTitleIsInvalid_QueryOnlyByPublished() { + String invalidTitle = ""; + + cordelService.findPublishedByTitle(true, invalidTitle, page); + Mockito.verify(cordelRepository, times(1)).findAllByPublished(true, page); + + cordelService.findPublishedByTitle(true, null, page); + Mockito.verify(cordelRepository, times(2)).findAllByPublished(true, page); + + Mockito.verify(cordelRepository, times(0)).findAllByPublishedAndTitleLike(true, invalidTitle, page); + } + + @Test + void testIfTitleIsValid_QueryOnlyByPublishedAndTitleLike() { + String validTitle = "cordel"; + + cordelService.findPublishedByTitle(true, validTitle, page); + Mockito.verify(cordelRepository, times(1)).findAllByPublishedAndTitleLike(true, String.format("%%%s%%", validTitle), page); + + Mockito.verify(cordelRepository, times(0)).findAllByPublished(true, page); + } +} \ No newline at end of file diff --git a/src/test/java/br/com/itsmemario/ecordel/security/jwt/JwtTokenTest.java b/src/test/java/br/com/itsmemario/ecordel/security/jwt/JwtTokenTest.java deleted file mode 100644 index 5f963de..0000000 --- a/src/test/java/br/com/itsmemario/ecordel/security/jwt/JwtTokenTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2021 Projeto e-cordel (http://ecordel.com.br) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package br.com.itsmemario.ecordel.security.jwt; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class JwtTokenTest { - - @Autowired - private JwtToken jwtToken; - - @Test - public void getJwtTokenTest() { - assertThat(jwtToken).isNotNull(); - } - -} diff --git a/src/test/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraRepositoryTest.java b/src/test/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraRepositoryTest.java deleted file mode 100644 index dd1665a..0000000 --- a/src/test/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraRepositoryTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package br.com.itsmemario.ecordel.xilogravura; - - -import br.com.itsmemario.ecordel.AbstractIntegrationTest; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(SpringExtension.class) -@SpringBootTest -public class XilogravuraRepositoryTest extends AbstractIntegrationTest { - - @Autowired - XilogravuraRepository repository; - - @Test - public void saveTest() { - Xilogravura xilogravura = new Xilogravura(); - xilogravura.setUrl("url"); - xilogravura.setDescription("description"); - - Xilogravura saved = repository.save(xilogravura); - - assertThat(saved).isNotNull(); - assertThat(saved.getId()).isGreaterThan(0); - } -} diff --git a/src/test/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraServiceTest.java b/src/test/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraServiceTest.java index a19b25a..2377e11 100644 --- a/src/test/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraServiceTest.java +++ b/src/test/java/br/com/itsmemario/ecordel/xilogravura/XilogravuraServiceTest.java @@ -2,7 +2,6 @@ import br.com.itsmemario.ecordel.AbstractIntegrationTest; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,9 +28,6 @@ public class XilogravuraServiceTest extends AbstractIntegrationTest { @Autowired XilogravuraService service; - @Autowired - XilogravuraRepository repository; - static final String FTP_HOME = "/ftp"; static final String USER = "user"; static final String PASSWORD = "pass"; @@ -57,23 +53,14 @@ public static void afterClass() throws Exception { fakeFtpServer.stop(); } - @AfterEach - public void tearDown() throws Exception { - repository.deleteAll(); - } - @Test public void createXilogravuraWithFile() { - Xilogravura xilogravura = new Xilogravura(); - xilogravura.setDescription("Description"); - MockMultipartFile file = new MockMultipartFile("file.txt", "content".getBytes()); - Xilogravura xilogravuraWithFile = service.createXilogravuraWithFile(xilogravura, file); - System.out.println(xilogravuraWithFile.getUrl()); + String xilogravuraUrl = service.createXilogravuraWithFile(file); + System.out.println(xilogravuraUrl); - assertThat(xilogravuraWithFile.getUrl()).isNotEmpty(); - assertThat(xilogravuraWithFile.getId()).isGreaterThan(0); - assertThat(repository.findById(1l)).isNotEmpty(); + assertThat(xilogravuraUrl).isNotEmpty(); + //TODO check if file exists } } \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index c60bd40..7232db7 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,11 +7,6 @@ ftp: password: pass baseUrl: "http://xilos.ecordel.com.br/" -jwt: - token: - expiration: 86400000 - secretKey: rm'!@N=Ke!~p8VTA2ZRK~nMDQX5Uvm!m'D&]{@Vr?G;2?XhbC:Qa#9#eMLN\}x3?JR3.2zr~v)gYF^8\:8>:XfB:Ww75N/emt9Yj[bQMNCWwW\J?N,nvH.<2\.r~w]*e~vgak)X"v8H`MH/7"2E`,^k@nL/zBq`}C6tT*cCSVC^c]-L}&/ - spring: datasource: url: jdbc:postgresql://localhost:5432/ecd diff --git a/src/main/resources/db/migration/data.sql b/src/test/resources/db/data/data.sql similarity index 66% rename from src/main/resources/db/migration/data.sql rename to src/test/resources/db/data/data.sql index 330f946..6dcac47 100644 --- a/src/main/resources/db/migration/data.sql +++ b/src/test/resources/db/data/data.sql @@ -7,50 +7,41 @@ values ('Author 2', 'About Author 2', 'author2@ecordel.com'); insert into author (name, about, email) values ('Author 3', 'About Author 3', 'author3@ecordel.com'); -insert into xilogravura (description, xilografo_id, url) -values ('xilo', 1, 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg'); - -insert into xilogravura (description, xilografo_id, url) -values ('xilo', 2, 'https://i.pinimg.com/564x/81/bf/ba/81bfbafaba269d02d357c9fa88e1a856.jpg'); - -insert into xilogravura (description, xilografo_id, url) -values ('xilo', 3, 'https://www5.usp.br/wp-content/uploads/portal20140507_1.jpg'); - -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 01', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 1, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 01', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); insert into cordel_tags (cordel_id, tags) values (1,'tag1'); insert into cordel_tags (cordel_id, tags) values (1,'tag2'); insert into cordel_tags (cordel_id, tags) values (1,'tag3'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 01', 2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 2, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 01', 2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); insert into cordel_tags (cordel_id, tags) values (2,'tag1'); insert into cordel_tags (cordel_id, tags) values (2,'tag2'); insert into cordel_tags (cordel_id, tags) values (2,'tag3'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 03', 3, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 3, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 03', 3, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 04', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 1, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 04', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 05', 2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 2, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 05', 2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 06', 3, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 3, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 06', 3, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 07', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 1, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 07', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 08', 2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 2, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 08', 2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 09', 3, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 3, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 09', 3, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); -insert into cordel (title, author_id, content, xilogravura_id, description) -values ('Title 10', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 1, 'Cordel descrition'); +insert into cordel (title, author_id, content, xilogravura_url, description) +values ('Title 10', 1, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis nisi, mollis vitae odio ac, dignissim gravida nunc. Nam ac bibendum lectus. Nulla id fermentum eros, sed ornare risus. Pellentesque faucibus dui et luctus efficitur.', 'https://i.pinimg.com/originals/25/9d/47/259d47304bf26a4678cb039b8d8ce7f9.jpg', 'Cordel descrition'); insert into cordel_authority(authority) values ('ADMIN'); insert into cordel_authority(authority) values ('USER');