ADD::added buttons and counters for the various activities

they don't have functionality yet, but they are already placed

ADD::added methods to get the name of  the user
This commit is contained in:
Sem van der Hoeven
2019-03-17 14:16:29 +01:00
parent fb6dfcdd20
commit a817d9118a
6 changed files with 154 additions and 20 deletions

View File

@@ -2,11 +2,11 @@ package greenify.server.data.repository;
import greenify.server.data.model.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
public interface UserRepository extends CrudRepository<User, Integer> {
User findByName(@Param("name") String name);
// User findByName(String name);
// User findByName(@Param("name") String name);
User findByName(String name);
User findById(Long id);
<T extends User> T save(T user);
}

View File

@@ -3,6 +3,7 @@ package greenify.server.rest;
import greenify.common.UserDTO;
import greenify.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
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;
@@ -29,4 +30,9 @@ public class UserController {
@RequestParam(value = "name") String name) {
userService.addVeganMeal(id, name);
}
@GetMapping("/getUsername")
public void getUsername(@RequestParam(value = "id") Long id) {
userService.getUsername(id);
}
}

View File

@@ -64,5 +64,12 @@ public class UserService {
user.setVeganMeal(count);
logger.info("Added vegan meal to user(id=" + user.getId() + ", name=" + user.getName() + ")");
}
public String getUsername(Long id) {
User user = userRepository.findById(id);
String name = user.getName();
logger.info("retrieved username from user with username=" + name + ", id=" + id);
return name;
}
}