use spring boot autowired for service injection
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c7003c1d02
commit
a0dfb3fa59
@ -1,17 +1,20 @@
|
|||||||
package wtf.beatrice.releasehive.resource;
|
package wtf.beatrice.releasehive.resource;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import wtf.beatrice.releasehive.util.JsonUtil;
|
import wtf.beatrice.releasehive.util.JsonUtil;
|
||||||
import wtf.beatrice.releasehive.model.User;
|
import wtf.beatrice.releasehive.model.User;
|
||||||
import wtf.beatrice.releasehive.service.AccountService;
|
import wtf.beatrice.releasehive.service.AccountService;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@RequestMapping("/api/v1/users")
|
@RequestMapping("/api/v1/users")
|
||||||
@RestController
|
@RestController
|
||||||
public class AccountResource {
|
public class AccountResource {
|
||||||
|
|
||||||
private final AccountService accountService = new AccountService();
|
private final AccountService accountService;
|
||||||
|
|
||||||
|
public AccountResource(@Autowired AccountService accountService) {
|
||||||
|
this.accountService = accountService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping(
|
@PostMapping(
|
||||||
|
@ -1,17 +1,9 @@
|
|||||||
package wtf.beatrice.releasehive.service;
|
package wtf.beatrice.releasehive.service;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import wtf.beatrice.releasehive.db.HibernateManager;
|
|
||||||
import wtf.beatrice.releasehive.model.User;
|
import wtf.beatrice.releasehive.model.User;
|
||||||
|
|
||||||
public class AccountService
|
public interface AccountService
|
||||||
{
|
{
|
||||||
|
|
||||||
public void registerUser(User user) {
|
void registerUser(User user);
|
||||||
Session session = HibernateManager.getSession();
|
|
||||||
Transaction transaction = session.beginTransaction();
|
|
||||||
session.save(user);
|
|
||||||
transaction.commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package wtf.beatrice.releasehive.service;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import wtf.beatrice.releasehive.db.HibernateManager;
|
||||||
|
import wtf.beatrice.releasehive.model.User;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AccountServiceImpl implements AccountService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerUser(User user) {
|
||||||
|
Session session = HibernateManager.getSession();
|
||||||
|
Transaction transaction = session.beginTransaction();
|
||||||
|
session.save(user);
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user