package com.tzld.piaoquan.recommend.server.web;

import com.tzld.piaoquan.recommend.server.client.ProtobufUtils;
import com.tzld.piaoquan.recommend.server.gen.tab.TabRequest;
import com.tzld.piaoquan.recommend.server.gen.tab.TabResponse;
import com.tzld.piaoquan.recommend.server.service.tab.TabService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TabController {

    @Autowired
    private TabService tabService;

    @PostMapping("/homepage/tab")
    public String homepageTab(@RequestBody TabRequest request) {
        MDC.put("appType", String.valueOf(request.getAppType()));
        TabResponse tabResponse = tabService.homepageTab(request);
        String result = "";
        try {
            result = ProtobufUtils.toJson(tabResponse);
        } catch (Exception e) {
            log.error("homepageTab ProtobufUtils.toJson", e);
        }
        return result;
    }

}
