-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into develop
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/edu/ntnu/idatt2105/quizapp/controller/quiz/TagController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package edu.ntnu.idatt2105.quizapp.controller.quiz; | ||
|
||
import edu.ntnu.idatt2105.quizapp.dto.quiz.TagDto; | ||
import edu.ntnu.idatt2105.quizapp.mapper.TagMapper; | ||
import edu.ntnu.idatt2105.quizapp.services.quiz.TagService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import java.util.List; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/tag-management") | ||
@CrossOrigin(origins = "http://localhost:3000") | ||
public class TagController { | ||
|
||
@NonNull | ||
TagService tagService; | ||
|
||
@NonNull | ||
TagMapper tagMapper; | ||
|
||
/** | ||
* Get all possible tags stored in the database | ||
* | ||
* @return a list of all possible tags | ||
*/ | ||
@Operation(summary = "Get all possible tags") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Successfully retrieved all tags"), | ||
@ApiResponse(responseCode = "500", description = "Internal server error") | ||
}) | ||
@GetMapping("/tags") | ||
public ResponseEntity<List<TagDto>> getAllTags( | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(defaultValue = "10") int size | ||
) { | ||
List<TagDto> receivedTags = tagService.getAllPossibleTags(Pageable.ofSize(size).withPage(page)) | ||
.stream() | ||
.map(tagMapper::mapToTagDto) | ||
.toList(); | ||
return new ResponseEntity<>(receivedTags, HttpStatus.OK); | ||
} | ||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/edu/ntnu/idatt2105/quizapp/repositories/TagRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package edu.ntnu.idatt2105.quizapp.repositories; | ||
|
||
import edu.ntnu.idatt2105.quizapp.model.quiz.Tag; | ||
import lombok.NonNull; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* Repository interface for managing Tag entities. | ||
* | ||
* @author Tobias Oftedal | ||
*/ | ||
@Repository | ||
public interface TagRepository extends JpaRepository<Tag, Long> { | ||
|
||
@NonNull Page<Tag> findAll(@NonNull Pageable pageable); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/edu/ntnu/idatt2105/quizapp/services/quiz/TagService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package edu.ntnu.idatt2105.quizapp.services.quiz; | ||
|
||
import edu.ntnu.idatt2105.quizapp.model.quiz.Tag; | ||
import edu.ntnu.idatt2105.quizapp.repositories.TagRepository; | ||
import lombok.AllArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service class for managing Tag entities. | ||
*/ | ||
@Service | ||
@Slf4j | ||
@AllArgsConstructor | ||
public class TagService { | ||
@NonNull | ||
TagRepository tagRepository; | ||
|
||
public Page<Tag> getAllPossibleTags(Pageable pageable) { | ||
return tagRepository.findAll(pageable); | ||
} | ||
} |