-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from shortintern2020-A-labyrinth/backend_model
Backend model
- Loading branch information
Showing
13 changed files
with
176 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,10 +49,13 @@ create table emojicode ( | |
emoji_code varchar(30) | ||
); | ||
|
||
|
||
insert into users(name, mail, filterlevel) values | ||
('ichigo.chocomint', '[email protected]', 1), | ||
('banana.chocomint', '[email protected]', 2), | ||
('pinapple.chocomint', '[email protected]', 3) | ||
; | ||
|
||
insert into emolog(userid, friendid, name, latestemolog) | ||
values (1, 2, 'hoge', 'emojihoge') | ||
; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/example/demo/controller/EmologController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.example.demo.controller; | ||
|
||
import com.example.demo.entity.Emolog; | ||
import com.example.demo.entity.Sample; | ||
import com.example.demo.service.EmologService; | ||
import com.example.demo.service.SampleService; | ||
import org.springframework.ui.Model; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
@RestController | ||
@RequestMapping(path = "/emologlist") | ||
public class EmologController { | ||
|
||
@Autowired | ||
EmologService service; | ||
|
||
@RequestMapping(value="/{userid}/{friendid}",method=RequestMethod.GET) | ||
public String selectAll(@PathVariable("userid") String userid, @PathVariable("friendid") String friendid, Model model) { | ||
int userId = Integer.parseInt(userid); | ||
int friendId = Integer.parseInt(friendid); | ||
List<Emolog> emologs = service.selectAll(userId, friendId); | ||
model.addAttribute("emologs", emologs); | ||
return "emologlist"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.demo.dao; | ||
|
||
import com.example.demo.entity.Emolog; | ||
import com.example.demo.entity.Sample; | ||
import org.seasar.doma.Dao; | ||
import org.seasar.doma.Insert; | ||
import org.seasar.doma.Select; | ||
import org.seasar.doma.boot.ConfigAutowireable; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
@Dao | ||
@ConfigAutowireable | ||
public interface EmologDao { | ||
|
||
@Select | ||
List<Emolog> selectAll(int user, int friend); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.demo.entity; | ||
|
||
|
||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.seasar.doma.Entity; | ||
import org.seasar.doma.GeneratedValue; | ||
import org.seasar.doma.GenerationType; | ||
import org.seasar.doma.Id; | ||
import org.springframework.format.datetime.standard.DateTimeContext; | ||
|
||
import javax.validation.constraints.Max; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
|
||
@Entity | ||
@Data | ||
@Getter | ||
@Setter | ||
public class Emolog implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@NotNull | ||
@Size(min=30) | ||
private String userid; | ||
|
||
@NotNull | ||
@Size(min=50) | ||
private String friendid; | ||
|
||
private LocalDateTime create_at; | ||
|
||
@NotNull | ||
@Max(40) | ||
private String contents; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/demo/repository/EmologRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.demo.repository; | ||
|
||
import com.example.demo.dao.EmologDao; | ||
import com.example.demo.dao.SampleDao; | ||
import com.example.demo.entity.Emolog; | ||
import com.example.demo.entity.Sample; | ||
import org.seasar.doma.Insert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
@Repository | ||
public class EmologRepository { | ||
|
||
@Autowired | ||
EmologDao dao; | ||
|
||
public List<Emolog> selectAll(int user, int friend) { // (4) | ||
return dao.selectAll(user, friend); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.demo.service; | ||
|
||
import com.example.demo.entity.Emolog; | ||
import com.example.demo.entity.Sample; | ||
import com.example.demo.repository.EmologRepository; | ||
import com.example.demo.repository.SampleRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.ui.Model; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
public class EmologService { | ||
|
||
@Autowired | ||
EmologRepository repository; | ||
|
||
public List<Emolog> selectAll(int user, int friend){ | ||
return repository.selectAll(user, friend); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/resources/META-INF/com/example/demo/dao/EmologDao/selectAll.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
select * | ||
from emolog | ||
where | ||
userid = /* user */1 | ||
and | ||
friendid = /* friend */1 | ||
order by create_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
-22 Bytes
(100%)
target/classes/com/example/demo/controller/ViewController.class
Binary file not shown.