package com.sckw.example.service;

import com.sckw.example.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * desc TODO
 * author zk
 * date 2023/6/15 0015
 */
@Service
public class StudentService {
    @Autowired
    private MongoTemplate mongoTemplate;

    public void addOne(Student student) {
        mongoTemplate.save(student);
    }

    public void deleteOneById(String studentId) {
        Student stu = mongoTemplate.findById(studentId, Student.class);
        if (stu != null) {
            mongoTemplate.remove(stu);
        }
    }

    public void updateOne(Student student) {
        mongoTemplate.save(student);

    }

    public Student findOneById(String studentId) {
        return mongoTemplate.findById(studentId, Student.class);
    }

    public List<Student> findAll() {
        return mongoTemplate.findAll(Student.class);
    }
}
