Files
Greenify/OOPP/Server/build/jacocoHtml/gogreen.server.service/UserService.java.html
2019-03-04 10:18:36 +01:00

41 lines
3.2 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>UserService.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Server</a> &gt; <a href="index.source.html" class="el_package">gogreen.server.service</a> &gt; <span class="el_source">UserService.java</span></div><h1>UserService.java</h1><pre class="source lang-java linenums">package gogreen.server.service;
import gogreen.common.ApplicationException;
import gogreen.common.UserDTO;
import gogreen.server.data.model.User;
import gogreen.server.data.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
<span class="fc" id="L13">public class UserService {</span>
<span class="fc" id="L14"> Logger logger = LoggerFactory.getLogger(UserService.class);</span>
@Autowired
UserRepository userRepository;
public UserDTO registerUser(String name, String password) {
<span class="fc" id="L19"> User user = userRepository.findByName(name);</span>
<span class="fc bfc" id="L20" title="All 2 branches covered."> if (user != null) {</span>
<span class="fc" id="L21"> throw new ApplicationException(&quot;User already exists&quot;);</span>
} else {
<span class="fc" id="L23"> user = userRepository.save(new User(null, name, password));</span>
}
<span class="fc" id="L25"> logger.info(&quot;Created user id=&quot; + user.getId() + &quot;, name=&quot; + user.getName());</span>
<span class="fc" id="L26"> return new UserDTO(user.getId(), user.getName());</span>
}
public UserDTO login(String name, String password) {
<span class="nc" id="L30"> User user = userRepository.findByName(name);</span>
<span class="nc bnc" id="L31" title="All 2 branches missed."> if (user == null) {</span>
<span class="nc" id="L32"> throw new ApplicationException(&quot;User does not exist&quot;);</span>
} else {
<span class="nc bnc" id="L34" title="All 2 branches missed."> if (!user.getPassword().equals(password)) {</span>
<span class="nc" id="L35"> throw new ApplicationException(&quot;Wrong password&quot;);</span>
}
}
<span class="nc" id="L38"> return new UserDTO(user.getId(), user.getName());</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.2.201808211720</span></div></body></html>