Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramtin Forouzandehjoo Samavat committed Apr 5, 2024
2 parents 4362c64 + 55fb5c8 commit 9026a2d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
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);
}


}
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);
}
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);
}
}

0 comments on commit 9026a2d

Please sign in to comment.