diff --git a/src/main/java/io/company/localhost/controller/api/VoteBoardController.java b/src/main/java/io/company/localhost/controller/api/VoteBoardController.java new file mode 100644 index 0000000..13cfbb0 --- /dev/null +++ b/src/main/java/io/company/localhost/controller/api/VoteBoardController.java @@ -0,0 +1,80 @@ +package io.company.localhost.controller.api; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.github.pagehelper.PageInfo; + +import io.company.localhost.common.annotation.Member; +import io.company.localhost.common.annotation.ParameterCheck; +import io.company.localhost.common.annotation.ReqMap; +import io.company.localhost.common.dto.ApiResponse; +import io.company.localhost.common.dto.MapDto; +import io.company.localhost.service.localvoteService; +import io.company.localhost.utils.AuthUtil; +import io.company.localhost.vo.MemberVo; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RequestMapping("/api/vote") +@RestController +@RequiredArgsConstructor +public class VoteBoardController { + + private final localvoteService localvoteservice; + + /** + * 투표목록조회 + * @param page 페이지번호 , 내가한투표 :0 투표안한것 :1 , 전체:0,투표마감:1,투표중:2 + * @return + */ + @Member + @ParameterCheck + @GetMapping("getVoteList") + public ApiResponse> getVoteList(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) { + + //userId + Long userId = AuthUtil.getUser().getId(); + map.put("userId", userId); + PageInfo VoteList = localvoteservice.getVoteList(map); + + + return ApiResponse.ok(VoteList); + } + + /** + * 투표 등록 + * @param title 제목 ,endDate 종료날짜 ,itemList 항목리스트(항목,링크) ,addvoteIs 항목추가여부, votemMltiIs 다중투표 허용여부 + * @return + */ + @Member + @PostMapping("insertWord") + public ApiResponse insertWord(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) { + + //userId + Long userId = AuthUtil.getUser().getId(); + map.put("userId", userId); + Long result = localvoteservice.insertVote(map); + return ApiResponse.ok(result); + } + + /** + * 투표 선택 + * @param title 제목 ,endDate 종료날짜 ,itemList 항목리스트(항목,링크) ,addvoteIs 항목추가여부, votemMltiIs 다중투표 허용여부 + * @return + */ + @Member + @PostMapping("insertCheckedNums") + public ApiResponse insertCheckedNums(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) { + + Long userId = AuthUtil.getUser().getId(); + map.put("userId", userId); + return ApiResponse.ok(localvoteservice.insertCheckedNums(map)); + } + + +} diff --git a/src/main/java/io/company/localhost/controller/api/worddictController.java b/src/main/java/io/company/localhost/controller/api/worddictController.java index 8d9d4e2..6e7d899 100644 --- a/src/main/java/io/company/localhost/controller/api/worddictController.java +++ b/src/main/java/io/company/localhost/controller/api/worddictController.java @@ -30,7 +30,6 @@ import io.company.localhost.common.dto.ApiResponse; import io.company.localhost.common.dto.MapDto; import io.company.localhost.service.commoncodService; import io.company.localhost.service.worddictyService; -import io.company.localhost.utils.AuthUtil; import io.company.localhost.vo.MemberVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/company/localhost/mapper/VotDetailMapper.java b/src/main/java/io/company/localhost/mapper/VotDetailMapper.java new file mode 100644 index 0000000..6ec0e88 --- /dev/null +++ b/src/main/java/io/company/localhost/mapper/VotDetailMapper.java @@ -0,0 +1,16 @@ +package io.company.localhost.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Mapper; + +import io.company.localhost.common.dto.MapDto; + +@Mapper +public interface VotDetailMapper { + + Long insertdetail(MapDto map); + + List getVoteDetails(int locvotSeq); + +} diff --git a/src/main/java/io/company/localhost/mapper/VotMemberMapper.java b/src/main/java/io/company/localhost/mapper/VotMemberMapper.java new file mode 100644 index 0000000..4da7f8b --- /dev/null +++ b/src/main/java/io/company/localhost/mapper/VotMemberMapper.java @@ -0,0 +1,20 @@ +package io.company.localhost.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Mapper; + +import io.company.localhost.common.dto.MapDto; + +@Mapper +public interface VotMemberMapper { + + void insertmem(MapDto map); + + List getVoteMember(Integer locvotSeq); + + + + + +} diff --git a/src/main/java/io/company/localhost/mapper/VotRecordMapper.java b/src/main/java/io/company/localhost/mapper/VotRecordMapper.java new file mode 100644 index 0000000..a9ad991 --- /dev/null +++ b/src/main/java/io/company/localhost/mapper/VotRecordMapper.java @@ -0,0 +1,14 @@ +package io.company.localhost.mapper; + +import org.apache.ibatis.annotations.Mapper; + +import io.company.localhost.common.dto.MapDto; + +@Mapper +public interface VotRecordMapper { + + int yesVotetotal(MapDto map); + + Long insertCheckedNums(MapDto map); + +} diff --git a/src/main/java/io/company/localhost/mapper/VotchoiceMapper.java b/src/main/java/io/company/localhost/mapper/VotchoiceMapper.java new file mode 100644 index 0000000..9fa11b2 --- /dev/null +++ b/src/main/java/io/company/localhost/mapper/VotchoiceMapper.java @@ -0,0 +1,12 @@ +package io.company.localhost.mapper; + +import org.apache.ibatis.annotations.Mapper; + +import io.company.localhost.common.dto.MapDto; + +@Mapper +public interface VotchoiceMapper { + + void insertChoice(MapDto map); + +} diff --git a/src/main/java/io/company/localhost/mapper/localvoteMapper.java b/src/main/java/io/company/localhost/mapper/localvoteMapper.java new file mode 100644 index 0000000..dadea29 --- /dev/null +++ b/src/main/java/io/company/localhost/mapper/localvoteMapper.java @@ -0,0 +1,19 @@ +package io.company.localhost.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Mapper; + +import com.github.pagehelper.PageInfo; + +import io.company.localhost.common.dto.MapDto; + +@Mapper +public interface localvoteMapper { + + Long insertVote(MapDto map); + + List getVoteList(MapDto map); + + +} diff --git a/src/main/java/io/company/localhost/service/localvoteService.java b/src/main/java/io/company/localhost/service/localvoteService.java new file mode 100644 index 0000000..cdf3ddb --- /dev/null +++ b/src/main/java/io/company/localhost/service/localvoteService.java @@ -0,0 +1,91 @@ +package io.company.localhost.service; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; + +import io.company.localhost.common.dto.MapDto; +import io.company.localhost.mapper.VotDetailMapper; +import io.company.localhost.mapper.VotMemberMapper; +import io.company.localhost.mapper.VotRecordMapper; +import io.company.localhost.mapper.VotchoiceMapper; +import io.company.localhost.mapper.localvoteMapper; +import io.company.localhost.utils.PageUtil; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class localvoteService { + + private final localvoteMapper localvotemapper; + private final VotMemberMapper votmembermapper; + private final VotDetailMapper votdetailmapper; + private final VotRecordMapper votrecordmapper; + private final VotchoiceMapper votchoicemapper; + + public Long insertVote(MapDto map) { + + Long result = 0L; + + int voteIdInt = (int) map.get("voteId"); + if(voteIdInt != 0) { + result = votdetailmapper.insertdetail(map); + }else { + result = localvotemapper.insertVote(map); + if(result == 1) { + //투표 가능 멤버 등록 + votmembermapper.insertmem(map); + //투표 항목,링크 등록 + votdetailmapper.insertdetail(map); + } + } + return result; + } + + public PageInfo getVoteList(MapDto map) { + //투표 목록조회 + int page = map.getString("page") != null ? Integer.parseInt(map.getString("page")) : 1; + PageHelper.startPage(page, 10); + PageInfo localvote = PageUtil.redefineNavigation(new PageInfo<>(localvotemapper.getVoteList(map),10)); + List resultList = new ArrayList<>(); + + List voteList = localvote.getList(); + + for (MapDto vote : voteList) { + MapDto voteMap = new MapDto(); + voteMap.put("localVote", vote); + Integer locvotSeq = (Integer) vote.get("LOCVOTSEQ"); + //투표 항목조회 + List voteDetails = votdetailmapper.getVoteDetails(locvotSeq); + //투표 가능 멤버 조회 + List voteMembers = votmembermapper.getVoteMember(locvotSeq); + voteMap.put("voteDetails", voteDetails); + voteMap.put("voteMembers", voteMembers); + + map.put("id",locvotSeq); + //투표 여부 + int yesVotetotal = votrecordmapper.yesVotetotal(map); + voteMap.put("yesVotetotal", yesVotetotal); + + resultList.add(voteMap); + } + localvote.setList(resultList); + + return localvote; + + } + + public Long insertCheckedNums(MapDto map) { + Long result = votrecordmapper.insertCheckedNums(map); + if(result == 1) { + votchoicemapper.insertChoice(map); + } + return result; + } + + +} diff --git a/src/main/resources/mapper/VotDetailMapper.xml b/src/main/resources/mapper/VotDetailMapper.xml new file mode 100644 index 0000000..b933cbd --- /dev/null +++ b/src/main/resources/mapper/VotDetailMapper.xml @@ -0,0 +1,28 @@ + + + + + INSERT INTO votdetail + (LOCVOTSEQ + ,LOCVOTCON + ,LOCVOTLIK + ) + VALUES + + ( + #{voteId} + ,#{item.content} + ,#{item.url} + ) + + + + + diff --git a/src/main/resources/mapper/VotMemberMapper.xml b/src/main/resources/mapper/VotMemberMapper.xml new file mode 100644 index 0000000..c1985a2 --- /dev/null +++ b/src/main/resources/mapper/VotMemberMapper.xml @@ -0,0 +1,22 @@ + + + + + INSERT INTO votmember + (LOCVOTSEQ + , MEMBERSEQ + ) + VALUES + + (#{voteId}, #{user.id}) + + + + diff --git a/src/main/resources/mapper/VotRecordMapper.xml b/src/main/resources/mapper/VotRecordMapper.xml new file mode 100644 index 0000000..c18361c --- /dev/null +++ b/src/main/resources/mapper/VotRecordMapper.xml @@ -0,0 +1,42 @@ + + + + + + INSERT INTO votrecord + ( + LOCVOTSEQ + ,VOTRECMEM + ,VOTRECRDT + ) + VALUES + ( + #{votenum} + ,#{userId} + ,now() + ) + + + + + + diff --git a/src/main/resources/mapper/VotchoiceMapper.xml b/src/main/resources/mapper/VotchoiceMapper.xml new file mode 100644 index 0000000..817a6b3 --- /dev/null +++ b/src/main/resources/mapper/VotchoiceMapper.xml @@ -0,0 +1,20 @@ + + + + + + INSERT INTO votchoice + ( + LOCVOTSEQ + ,VOTDETSEQ + ) + VALUES + + ( + #{item.LOCVOTSEQ} + ,#{item.VOTDETSEQ} + ) + + + + diff --git a/src/main/resources/mapper/localvoteMapper.xml b/src/main/resources/mapper/localvoteMapper.xml new file mode 100644 index 0000000..0ae28f4 --- /dev/null +++ b/src/main/resources/mapper/localvoteMapper.xml @@ -0,0 +1,38 @@ + + + + + + insert into localvote + ( + LOCVOTREG + ,LOCVOTRDT + ,LOCVOTEDT + ,LOCVOTTTL + ,LOCVOTADD + ,LOCVOTMUL + ) + values + ( + #{userId} + ,now() + ,#{endDate} + ,#{title} + ,#{addvoteIs} + ,#{votemMltiIs} + ) + + +