package com.YuyeTech.HeartRate.service.impl;

import com.YuyeTech.HeartRate.dataobject.SignIn;
import com.YuyeTech.HeartRate.dataobject.SignInReward;
import com.YuyeTech.HeartRate.repository.SignInRepository;
import com.YuyeTech.HeartRate.repository.SignInRewardRepository;
import com.YuyeTech.HeartRate.service.SignInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户信息
 *
 * @author:slambb
 * @date:2021/8/5
 */
@Service
public class SignInServiceImpl implements SignInService {

    @Autowired
    private SignInRepository signInRepository;

    @Autowired
    private SignInRewardRepository signInRewardRepository;

    @Override
    public SignIn findByUserId(String userId) {
        return signInRepository.findByUserId(userId).orElse(null);
    }

    @Override
    public void addSignIn(SignIn signIn) {
        signInRepository.save(signIn);
    }


    @Override
    public SignInReward getSignInRewardByDays(Integer days) {
        return signInRewardRepository.findByDays(days).orElse(null);
    }

    @Override
    public List<SignInReward> getSignInRewardList() {
        return signInRewardRepository.findAll(Sort.by(Sort.Direction.ASC,"days"));
    }
}

