use spring boot autowired for service injection
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2024-08-07 00:57:39 +02:00
parent c7003c1d02
commit a0dfb3fa59
3 changed files with 27 additions and 13 deletions

View File

@ -1,17 +1,20 @@
package wtf.beatrice.releasehive.resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wtf.beatrice.releasehive.util.JsonUtil;
import wtf.beatrice.releasehive.model.User;
import wtf.beatrice.releasehive.service.AccountService;
import java.util.UUID;
@RequestMapping("/api/v1/users")
@RestController
public class AccountResource {
private final AccountService accountService = new AccountService();
private final AccountService accountService;
public AccountResource(@Autowired AccountService accountService) {
this.accountService = accountService;
}
@PostMapping(

View File

@ -1,17 +1,9 @@
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;
public class AccountService
public interface AccountService
{
public void registerUser(User user) {
Session session = HibernateManager.getSession();
Transaction transaction = session.beginTransaction();
session.save(user);
transaction.commit();
}
void registerUser(User user);
}

View File

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