package com.lovenav.controller;

import com.lovenav.entity.UrlAccess;
import com.lovenav.service.UrlAccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

@RestController
public class UrlAccessController {

    @Autowired
    UrlAccessService urlAccessService;

    //浏览url，访问量加1
    @RequestMapping("/addUrlAccessViews")
    public String addUrlAccessViews(UrlAccess urlAccess){
        String result=urlAccessService.inreaseUrlViews(urlAccess);
        return result;
    }

    @RequestMapping("/getUrlAccess")
    public HashMap<Date, Object> getUrlAccess(UrlAccess urlAccess){
        HashMap<Date,Object> map=new HashMap<>();
        map=urlAccessService.getUrlAccess(urlAccess);
        if (map.isEmpty()){
            Date date=new Date();
            map.put(date,"查不到该数据");
            return map;
        }
        return map;
    }
}
