Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat database access repository #15

Merged
merged 6 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package com.partycipate.Partycipate.controller;

import com.partycipate.Partycipate.service.ISurveyService;
import com.partycipate.Partycipate.repository.SurveyRepository;
import com.partycipate.Partycipate.service.SurveyService;
import com.partycipate.Partycipate.model.Survey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.Optional;


@RestController
@RequestMapping("/api/survey")
public class SurveyController {

private final SurveyService surveyService;
@Autowired
private SurveyRepository surveyRepository;

private final SurveyService surveyService;
@Autowired
public SurveyController(SurveyService surveyService){
this.surveyService=surveyService;
Expand All @@ -33,8 +31,16 @@ public void addSurvey(@RequestBody Survey survey){
}

@GetMapping("")
public List<Survey> getAllSurveys(){
public @ResponseBody Iterable<Survey> getAllSurveys(){
return surveyService.getAllSurveys();
}

@GetMapping("/{id}")
public @ResponseBody Survey getSurvey(@PathVariable("id") int id){
return surveyService.getSurvey(id);
}
/*@GetMapping("/user/{id}")
public @ResponseBody Iterable<Survey> getUserSurveys(@PathVariable("id") int id){
return surveyService.getUserSurveys(id);
}*/
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.partycipate.Partycipate.repository;


import com.partycipate.Partycipate.model.Survey;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AnswerPossibilityRepository extends CrudRepository<Survey, Integer> {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.partycipate.Partycipate.repository;


import com.partycipate.Partycipate.model.Survey;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AnswerRepository extends CrudRepository<Survey, Integer> {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.partycipate.Partycipate.repository;


import com.partycipate.Partycipate.model.Survey;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ParticipantRepository extends CrudRepository<Survey, Integer> {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.partycipate.Partycipate.repository;


import com.partycipate.Partycipate.model.Survey;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface SurveyElementRepository extends CrudRepository<Survey, Integer> {


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.partycipate.Partycipate.repository;


import com.partycipate.Partycipate.model.Survey;
import org.springframework.data.repository.CrudRepository;

import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SurveyRepository extends CrudRepository<Survey, Integer> {
Survey findById(int id);
//Survey findAllByUser_id(int id);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.partycipate.Partycipate.repository;


import com.partycipate.Partycipate.model.Survey;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface Survey_ParticipantRepository extends CrudRepository<Survey, Integer> {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.partycipate.Partycipate.repository;


import com.partycipate.Partycipate.model.Survey;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends CrudRepository<Survey, Integer> {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.partycipate.Partycipate.service;

import com.partycipate.Partycipate.dao.SurveyDao;
import com.partycipate.Partycipate.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class AnswerPossibilityService {

private final SurveyDao surveyDao;
@Autowired
private SurveyRepository surveyRepository;

@Autowired
public AnswerPossibilityService(@Qualifier("fakeDao") SurveyDao surveyDao) {
this.surveyDao = surveyDao;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.partycipate.Partycipate.service;

import com.partycipate.Partycipate.dao.SurveyDao;
import com.partycipate.Partycipate.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class AnswerService {

private final SurveyDao surveyDao;
@Autowired
private SurveyRepository surveyRepository;

@Autowired
public AnswerService(@Qualifier("fakeDao") SurveyDao surveyDao) {
this.surveyDao = surveyDao;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.partycipate.Partycipate.model.Survey;

import com.partycipate.models.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.partycipate.Partycipate.service;

import com.partycipate.Partycipate.dao.SurveyDao;
import com.partycipate.Partycipate.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class ParticipantService {

private final SurveyDao surveyDao;
@Autowired
private SurveyRepository surveyRepository;

@Autowired
public ParticipantService(@Qualifier("fakeDao") SurveyDao surveyDao) {
this.surveyDao = surveyDao;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.partycipate.Partycipate.service;

import com.partycipate.Partycipate.dao.SurveyDao;
import com.partycipate.Partycipate.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class SurveyElementService {

private final SurveyDao surveyDao;
@Autowired
private SurveyRepository surveyRepository;

@Autowired
public SurveyElementService(@Qualifier("fakeDao") SurveyDao surveyDao) {
this.surveyDao = surveyDao;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import com.partycipate.Partycipate.dao.SurveyDao;
import com.partycipate.Partycipate.model.Survey;
import com.partycipate.Partycipate.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Optional;

@Service
public class SurveyService implements ISurveyService{
public class SurveyService {

private final SurveyDao surveyDao;
@Autowired
private SurveyRepository surveyRepository;

@Autowired
public SurveyService(@Qualifier("fakeDao") SurveyDao surveyDao) {
Expand All @@ -25,8 +29,8 @@ public Survey addSurvey(Survey survey){
}

@GetMapping()
public List<Survey> getAllSurveys(){
return surveyDao.selectAllSurveys();
public @ResponseBody Iterable<Survey> getAllSurveys(){
return surveyRepository.findAll();
}


Expand All @@ -36,13 +40,16 @@ public static Survey getRandomSurvey(int id) {
}


@Override

public List<Survey> findAll() {
return null;
}

@Override
public Optional<Survey> getSurvey(Long id) {
return Optional.empty();

public Survey getSurvey(int id) {
return surveyRepository.findById(id);
}
/*public Iterable<Survey> getUserSurveys(int id){
return (Iterable<Survey>) surveyRepository.findAllByUser_id(id);
}*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.partycipate.Partycipate.service;

import com.partycipate.Partycipate.dao.SurveyDao;
import com.partycipate.Partycipate.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class Survey_ParticipantService {

private final SurveyDao surveyDao;
@Autowired
private SurveyRepository surveyRepository;

@Autowired
public Survey_ParticipantService(@Qualifier("fakeDao") SurveyDao surveyDao) {
this.surveyDao = surveyDao;
}


}
28 changes: 28 additions & 0 deletions src/main/java/com/partycipate/Partycipate/service/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.partycipate.Partycipate.service;

import com.partycipate.Partycipate.dao.SurveyDao;
import com.partycipate.Partycipate.model.Survey;
import com.partycipate.Partycipate.repository.SurveyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Optional;

@Service
public class UserService {

private final SurveyDao surveyDao;
@Autowired
private SurveyRepository surveyRepository;

@Autowired
public UserService(@Qualifier("fakeDao") SurveyDao surveyDao) {
this.surveyDao = surveyDao;
}


}