mirror of
				https://github.com/grocy/grocy.git
				synced 2025-10-31 10:46:36 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace Grocy\Controllers;
 | |
| 
 | |
| use \Grocy\Services\HabitsService;
 | |
| 
 | |
| class HabitsApiController extends BaseApiController
 | |
| {
 | |
| 	public function __construct(\Slim\Container $container)
 | |
| 	{
 | |
| 		parent::__construct($container);
 | |
| 		$this->HabitsService = new HabitsService();
 | |
| 	}
 | |
| 
 | |
| 	protected $HabitsService;
 | |
| 
 | |
| 	public function TrackHabitExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
 | |
| 	{
 | |
| 		$trackedTime = date('Y-m-d H:i:s');
 | |
| 		if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']) && IsIsoDateTime($request->getQueryParams()['tracked_time']))
 | |
| 		{
 | |
| 			$trackedTime = $request->getQueryParams()['tracked_time'];
 | |
| 		}
 | |
| 
 | |
| 		$doneBy = GROCY_USER_ID;
 | |
| 		if (isset($request->getQueryParams()['done_by']) && !empty($request->getQueryParams()['done_by']))
 | |
| 		{
 | |
| 			$doneBy = $request->getQueryParams()['done_by'];
 | |
| 		}
 | |
| 
 | |
| 		try
 | |
| 		{
 | |
| 			$this->HabitsService->TrackHabit($args['habitId'], $trackedTime, $doneBy);
 | |
| 			return $this->VoidApiActionResponse($response);
 | |
| 		}
 | |
| 		catch (\Exception $ex)
 | |
| 		{
 | |
| 			return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	public function HabitDetails(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
 | |
| 	{
 | |
| 		try
 | |
| 		{
 | |
| 			return $this->ApiResponse($this->HabitsService->GetHabitDetails($args['habitId']));
 | |
| 		}
 | |
| 		catch (\Exception $ex)
 | |
| 		{
 | |
| 			return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
 | |
| 	{
 | |
| 		return $this->ApiResponse($this->HabitsService->GetCurrent());
 | |
| 	}
 | |
| }
 |