Skip to content

Commit

Permalink
Merge pull request #35 from urashin/base-api-impl
Browse files Browse the repository at this point in the history
add volunteer function : listen,accept,rush
  • Loading branch information
urashin authored Feb 16, 2022
2 parents 2e76f2a + 8bbae22 commit 32349e8
Show file tree
Hide file tree
Showing 15 changed files with 564 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,21 @@ public String default_handicap_register(@PathVariable String token, HandicapRegi
return "my_profile";
}

@PostMapping("/default/matching/listen")
public String default_handicap_register(ListenRequest listenRequest, Model model){
logger.info("handicap register API");
String user_id = tokenService.getUserId(listenRequest.getToken());
/*
<a th:href="@{/v1/matching/listen/{token}(token=${token})}" class="secondary-content"><i class="material-icons">hearing</i></a>
<a th:href="@{/v1/matching/checkin/{token}(token=${token})}" class="secondary-content"><i class="material-icons">location_on</i></a>
*/
@GetMapping("/default/matching/listen/{token}")
public String default_listen(@PathVariable String token, Model model){
logger.info("listen API");
String user_id = tokenService.getUserId(token);
// listen_listをしゅとくする
AcceptRequest acceptRequest= new AcceptRequest();
model.addAttribute(acceptRequest);
model.addAttribute("token", listenRequest.getToken());
return "listen_list";
ListenRequest listenRequest = ListenRequest.builder()
.token(token)
.build();
model.addAttribute(listenRequest);
model.addAttribute("token", token);
return "listen";
}

@PostMapping("/default/user/register/{token}")
Expand Down Expand Up @@ -252,6 +258,49 @@ public String default_help_cancel(CancelRequest cancelRequest, Model model) {
return "my_profile";
}

@PostMapping("/default/matching/listen-signals")
public String default_listen_signals(ListenRequest listenRequest, Model model) {
logger.info("listen-signals API");
String token = listenRequest.getToken();
String user_id = tokenService.getUserId(token);
SignalList signalList = matchingService.getHelpSignals(user_id, listenRequest.getX_geometry(), listenRequest.getY_geometry());

AcceptRequest acceptRequest = new AcceptRequest();
model.addAttribute(acceptRequest);
model.addAttribute(signalList);
model.addAttribute("token", token);
return "listen_signals";
}

@GetMapping("/default/matching/accept/{token}/{help_id}")
public String default_accept(@PathVariable String token, @PathVariable Integer help_id, Model model) {
logger.info("listen-signals API");
String user_id = tokenService.getUserId(token);
Location geo = matchingService.getMyGeometry(user_id);
HelpSignal helpSignal = matchingService.getHelpSignal(help_id,geo.getX_geometry(), geo.getY_geometry());

AcceptRequest acceptRequest = new AcceptRequest();
model.addAttribute(acceptRequest);
model.addAttribute(helpSignal);
model.addAttribute("token", token);
return "accept";
}

@PostMapping("/default/matching/accept")
public String default_accept_rush(AcceptRequest acceptRequest, Model model) {
logger.info("accept API");
String user_id = tokenService.getUserId(acceptRequest.getToken());
Location geo = matchingService.getMyGeometry(user_id);
matchingService.accept(acceptRequest.getHelp_id(),user_id);
HelpSignal helpSignal = matchingService.getHelpSignal(acceptRequest.getHelp_id(),geo.getX_geometry(), geo.getY_geometry());

CancelRequest cancelRequest = new CancelRequest();
model.addAttribute(cancelRequest);
model.addAttribute(helpSignal);
model.addAttribute("token", acceptRequest.getToken());
return "rush";
}

@GetMapping("/default/user/thanks_list/{token}")
public String default_thanks_list(@PathVariable String token, Model model) {
logger.info("thanks list");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.microvolunteer.platform.domain.resource;

import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@Builder
public class HelpSignal {
private Integer help_id;
private String area_name;
private String handicap_name;
private String x_geometory;
private String y_geometory;
private Integer distance;
private Integer handicap_type;
private Integer handicap_level;
private String comment;
private LocalDateTime created_at;
private LocalDateTime updated_at;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.microvolunteer.platform.domain.resource;

import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class SignalList {
List<HelpSignal> help_signals;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ListenRequest {
@Size(min=16, max=64)
private String token;

private Integer area_id;
private String x_geometry;
private String y_geometry;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.ibatis.annotations.Mapper;
import org.microvolunteer.platform.domain.resource.Help;
import org.microvolunteer.platform.domain.resource.HelpSignal;
import org.microvolunteer.platform.domain.resource.NeighborDistance;
import org.microvolunteer.platform.domain.resource.RegisterHelp;

Expand All @@ -15,6 +16,8 @@ public interface HelpMapper {
Integer getHelpId(String user_id);
String getVolunteerId(Integer help_id);
String getHandicappedId(Integer help_id);
List<HelpSignal> getHelpSignals(String my_id, String location);
HelpSignal getHelpSignal(Integer help_id, String location);
//Integer countTargetVolunteers(Integer help_id); // 対象となるボランティア数をカウントする
void accept(Integer help_id,String volunteer_id);
//void closeHelp(Integer help_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
Expand Down Expand Up @@ -86,13 +87,38 @@ public void help(String my_id, HelpRequest request, HandicapInfo handicapInfo) {
lineMessageRestClient.requestHelp(sns_id, neighborDistance, handicapInfo);
}
} catch(Exception e) {
logger.info("line message error.");
logger.error("line message error.");
}
}

public void help_cancel(String my_id) {
helpMapper.cancel(my_id);
}

public SignalList getHelpSignals(String my_id, String x_geometry, String y_geometry) {
String location = GeometryDto.getPoint(x_geometry, y_geometry);
List<HelpSignal> helpSignals;
try {
helpSignals = helpMapper.getHelpSignals(my_id, location);
} catch (Exception e) {
helpSignals = new ArrayList<>();
logger.info("no help signal found.");
}
return SignalList.builder().help_signals(helpSignals).build();
}

public HelpSignal getHelpSignal(Integer help_id, String x_geometry, String y_geometry) {
String location = GeometryDto.getPoint(x_geometry, y_geometry);
HelpSignal helpSignal;
try {
helpSignal = helpMapper.getHelpSignal(help_id, location);
} catch (Exception e) {
helpSignal = null;
logger.info("no help signal found.");
}
return helpSignal;
}

public List<NeighborDistance> getNeigborhood(String my_id, String location) {
List<NeighborDistance> neighborList = helpMapper.getNeighborhood(my_id, location);
return neighborList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,49 @@
from Help
where help_id = #{help_id};
</select>
<select id="getHelp">
<!--select id="getHelp">
select CONVERT(ST_X(location),NCHAR), CONVERT(ST_Y(location),NCHAR)
from MyGeometry
where user_id = #{user_id}
</select-->
<select id="getHelpSignals" resultType="org.microvolunteer.platform.domain.resource.HelpSignal">
SELECT
h.help_id,
ca.area_name,
hm.handicap_name,
ST_X(h.location) y_geometry,
ST_Y(h.location) x_geometry,
ST_Distance(h.location, ST_GeomFromText(#{location},4326)) distance,
h.handicap_type,
h.handicap_level,
h.comment,
h.created_at,
h.updated_at
FROM Help h
LEFT JOIN CheckinArea ca ON h.area_id = ca.area_id
LEFT JOIN HandicapMaster hm ON h.handicap_type = hm.handicap_type
WHERE
h.handicapped_id != #{my_id} AND h.status = 1
order by distance LIMIT 5;
</select>
<select id="getHelpSignal" resultType="org.microvolunteer.platform.domain.resource.HelpSignal">
SELECT
h.help_id,
ca.area_name,
hm.handicap_name,
ST_X(h.location) y_geometry,
ST_Y(h.location) x_geometry,
ST_Distance(h.location, ST_GeomFromText(#{location},4326)) distance,
h.handicap_type,
h.handicap_level,
h.comment,
h.created_at,
h.updated_at
FROM Help h
LEFT JOIN CheckinArea ca ON h.area_id = ca.area_id
LEFT JOIN HandicapMaster hm ON h.handicap_type = hm.handicap_type
WHERE
h.help_id = #{help_id}
</select>
<select id="getNeighborhood" resultType="org.microvolunteer.platform.domain.resource.NeighborDistance">
SELECT user_id,
Expand Down
71 changes: 71 additions & 0 deletions src/main/resources/templates/accept.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link type="text/css" rel="stylesheet" th:href="@{/css/my.css}" media="screen,projection"/>

<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>micro-volunteer</title>
</head>
<body>
<header>
<nav>
<div class="nav-wrapper">
<a th:href="@{/v1/user/mypage/{token}(token=${token})}" method="get" class="brand-logo">micro-volunteer</a>
<a href="#" data-target="mobile-demo" class="sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<li><a href="#">checkin!</a></li>
<li><a href="#">Help!</a></li>
<li><a th:href="@{/v1/default/user/thanks_list/{token}(token=${token})}" method="post">Thanks</a></li>
<li><a th:href="@{/v1/default/user/history/{token}(token=${token})}" method="post">history</a></li>
</ul>
</div>
</nav>
<ul class="sidenav" id="mobile-demo">
<li><a href="#">checkin!</a></li>
<li><a href="#">Help!</a></li>
<li><a th:href="@{/v1/default/user/thanks_list/{token}(token=${token})}" method="post">Thanks</a></li>
<li><a th:href="@{/v1/default/user/history/{token}(token=${token})}" method="post">history</a></li>
</ul>
</header>

<div class="card_list">
<ul class="collection">
<form th:action="@{/v1/default/matching/accept}" method="post" th:object="${acceptRequest}" class="col s12">
<span class="card-title">以下のHelpに応じますか?</span>
<li class="collection-item avatar">
<i class="material-icons">
<img th:src="@{/img/{handicap_type}.png(handicap_type=${helpSignal.handicap_type})}" class="circle">
</i>
<p>[[${helpSignal.handicap_name}]]</p>
<p>障がいの程度: [[${helpSignal.handicap_level}]] <br>
コメント: [[${helpSignal.comment}]] </p>
<div class="input-field col s6" hidden>
<input name="help_id" th:value="${helpSignal.help_id}">
<input name="y_geometry" th:value="35.7107654">
<input name="x_geometry" th:value="139.795978">
<input name="token" th:value="${token}">
</div>
<button class="btn waves-effect waves-light btn-small" type="submit" name="action">accept
<i class="material-icons right">directions_run</i>
</button>
</li>
</form>
</ul>
<div align="center">
<a class="btn-floating btn-large waves-effect waves-light red" th:href="@{/v1/user/mypage/{token}(token=${token})}" method="get"><i class="material-icons">clear</i></a>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems);
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>
71 changes: 71 additions & 0 deletions src/main/resources/templates/help_call.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link type="text/css" rel="stylesheet" th:href="@{/css/my.css}" media="screen,projection"/>

<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>micro-volunteer</title>
</head>
<body>
<header>
<nav>
<div class="nav-wrapper">
<a th:href="@{/v1/user/mypage/{token}(token=${token})}" method="get" class="brand-logo">micro-volunteer</a>
<a href="#" data-target="mobile-demo" class="sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<li><a href="#">checkin!</a></li>
<li><a href="#">Help!</a></li>
<li><a th:href="@{/v1/default/user/thanks_list/{token}(token=${token})}" method="post">Thanks</a></li>
<li><a th:href="@{/v1/default/user/history/{token}(token=${token})}" method="post">history</a></li>
</ul>
</div>
</nav>
<ul class="sidenav" id="mobile-demo">
<li><a href="#">checkin!</a></li>
<li><a href="#">Help!</a></li>
<li><a th:href="@{/v1/default/user/thanks_list/{token}(token=${token})}" method="post">Thanks</a></li>
<li><a th:href="@{/v1/default/user/history/{token}(token=${token})}" method="post">history</a></li>
</ul>
</header>

<div class="card_list">
<ul class="collection">
<form th:action="@{/v1/default/user/help/call}" method="post" th:object="${helpRequest}" class="col s12">
<span class="card-title">以下の内ようでHelpを発信しますか?</span>
<li class="collection-item avatar">
<i class="material-icons">
<img th:src="@{/img/{handicap_type}.png(handicap_type=${myHandicap.handicap_type})}" class="circle">
</i>
<p>[[${myHandicap.handicap_name}]]</p>
<p>障がいの程度: [[${myHandicap.handicap_level}]] <br>
コメント: [[${myHandicap.comment}]] </p>
<div class="input-field col s6" hidden>
<input name="handicapinfo_id" th:value="${myHandicap.handicapinfo_id}">
<input name="y_geometry" th:value="35.7107654">
<input name="x_geometry" th:value="139.795978">
<input name="token" th:value="${token}">
</div>
<button class="btn waves-effect waves-light btn-small" type="submit" name="action">help
<i class="material-icons right">call_made</i>
</button>
</li>
</form>
</ul>
<div align="center">
<a class="btn-floating btn-large waves-effect waves-light red" th:href="@{/v1/user/mypage/{token}(token=${token})}" method="get"><i class="material-icons">clear</i></a>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems);
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>
Loading

0 comments on commit 32349e8

Please sign in to comment.