├── ProfileImage ├── 117176385_619436809003378_2146039004734674576_n.jpg ├── 118798458_770577420401078_4464474413086101139_n.png ├── 118886941_376527033366636_1736524302910628185_n.jpg ├── 118951469_2663803540529655_8937466199392595921_n.jpg ├── 118990741_3523867317665199_7966596987101331457_n.jpg ├── 118993978_670607920476138_6265689018891159082_n.jpg ├── 118995214_4962813483744294_2934598001289673968_n.jpg ├── 119009178_256274592114505_4349216705504018769_n.jpg ├── 12341599567439동희.png ├── 1599541713처음으로 유명인에게 스타받음!!!.png ├── 69527671_385193388863294_4821303078424674304_n.jpg ├── 88307145_344291093137333_985007073815166976_n.jpg ├── 95643229_602285813708429_4010101975185096704_n.jpg ├── cnj72241599615556표.PNG ├── jinstonlee15996153280c3b3adb1a7530892e55ef36d3be6cb8.png ├── jsh01281599567495스크린샷 2020-09-06 오전 12.54.05.png ├── sh0312241599553529동희.png ├── sh0312241599558381logo192.png ├── sh0312241599558743동희.png ├── sh0312241599558797동희.png ├── sh0312241599567377동희.png ├── so01599616235박소영선생님.PNG ├── sumin1599615917김수민선생님.png ├── test111599571103스크린샷 2020-09-06 오전 12.54.05.png ├── test111599571687동희.png ├── test111599571700스크린샷 2020-09-06 오전 12.54.05.png ├── test111599571733동희.png └── zxcmnb051599615691105282114_699008504282236_1235408498389497172_n.jpg ├── README.md ├── config ├── config.go └── config.toml ├── controller ├── createComment.go ├── createReplyComment.go ├── showAllInfo.go ├── showComment.go ├── showMyInfo.go ├── showMyStar.go ├── showReplyComment.go ├── showUserInfo.go ├── showUserStar.go ├── signIn.go ├── signUp.go ├── updateComment.go ├── updateMyInfo.go ├── updateProfileImage.go ├── updateReplyComment.go └── updateStar.go ├── database ├── connection.go ├── user.go ├── userComment.go ├── userReplyComment.go └── userStar.go ├── go.mod ├── go.sum ├── library └── jwt │ └── jwt.go └── server.go /ProfileImage/117176385_619436809003378_2146039004734674576_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/117176385_619436809003378_2146039004734674576_n.jpg -------------------------------------------------------------------------------- /ProfileImage/118798458_770577420401078_4464474413086101139_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/118798458_770577420401078_4464474413086101139_n.png -------------------------------------------------------------------------------- /ProfileImage/118886941_376527033366636_1736524302910628185_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/118886941_376527033366636_1736524302910628185_n.jpg -------------------------------------------------------------------------------- /ProfileImage/118951469_2663803540529655_8937466199392595921_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/118951469_2663803540529655_8937466199392595921_n.jpg -------------------------------------------------------------------------------- /ProfileImage/118990741_3523867317665199_7966596987101331457_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/118990741_3523867317665199_7966596987101331457_n.jpg -------------------------------------------------------------------------------- /ProfileImage/118993978_670607920476138_6265689018891159082_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/118993978_670607920476138_6265689018891159082_n.jpg -------------------------------------------------------------------------------- /ProfileImage/118995214_4962813483744294_2934598001289673968_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/118995214_4962813483744294_2934598001289673968_n.jpg -------------------------------------------------------------------------------- /ProfileImage/119009178_256274592114505_4349216705504018769_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/119009178_256274592114505_4349216705504018769_n.jpg -------------------------------------------------------------------------------- /ProfileImage/12341599567439동희.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/12341599567439동희.png -------------------------------------------------------------------------------- /ProfileImage/1599541713처음으로 유명인에게 스타받음!!!.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/1599541713처음으로 유명인에게 스타받음!!!.png -------------------------------------------------------------------------------- /ProfileImage/69527671_385193388863294_4821303078424674304_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/69527671_385193388863294_4821303078424674304_n.jpg -------------------------------------------------------------------------------- /ProfileImage/88307145_344291093137333_985007073815166976_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/88307145_344291093137333_985007073815166976_n.jpg -------------------------------------------------------------------------------- /ProfileImage/95643229_602285813708429_4010101975185096704_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/95643229_602285813708429_4010101975185096704_n.jpg -------------------------------------------------------------------------------- /ProfileImage/cnj72241599615556표.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/cnj72241599615556표.PNG -------------------------------------------------------------------------------- /ProfileImage/jinstonlee15996153280c3b3adb1a7530892e55ef36d3be6cb8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/jinstonlee15996153280c3b3adb1a7530892e55ef36d3be6cb8.png -------------------------------------------------------------------------------- /ProfileImage/jsh01281599567495스크린샷 2020-09-06 오전 12.54.05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/jsh01281599567495스크린샷 2020-09-06 오전 12.54.05.png -------------------------------------------------------------------------------- /ProfileImage/sh0312241599553529동희.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/sh0312241599553529동희.png -------------------------------------------------------------------------------- /ProfileImage/sh0312241599558381logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/sh0312241599558381logo192.png -------------------------------------------------------------------------------- /ProfileImage/sh0312241599558743동희.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/sh0312241599558743동희.png -------------------------------------------------------------------------------- /ProfileImage/sh0312241599558797동희.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/sh0312241599558797동희.png -------------------------------------------------------------------------------- /ProfileImage/sh0312241599567377동희.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/sh0312241599567377동희.png -------------------------------------------------------------------------------- /ProfileImage/so01599616235박소영선생님.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/so01599616235박소영선생님.PNG -------------------------------------------------------------------------------- /ProfileImage/sumin1599615917김수민선생님.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/sumin1599615917김수민선생님.png -------------------------------------------------------------------------------- /ProfileImage/test111599571103스크린샷 2020-09-06 오전 12.54.05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/test111599571103스크린샷 2020-09-06 오전 12.54.05.png -------------------------------------------------------------------------------- /ProfileImage/test111599571687동희.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/test111599571687동희.png -------------------------------------------------------------------------------- /ProfileImage/test111599571700스크린샷 2020-09-06 오전 12.54.05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/test111599571700스크린샷 2020-09-06 오전 12.54.05.png -------------------------------------------------------------------------------- /ProfileImage/test111599571733동희.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/test111599571733동희.png -------------------------------------------------------------------------------- /ProfileImage/zxcmnb051599615691105282114_699008504282236_1235408498389497172_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjmin321/Amanda_Server/a914b05c652e86f76e1271d796e865594ab21c17/ProfileImage/zxcmnb051599615691105282114_699008504282236_1235408498389497172_n.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Amanda 아무도 만나지 못한다 2 | 💔 대구소프트웨어고등학교 학생들이 더 이상 외모 순위를 두고 다투지 않게, 평가와 피드백을 받을 수 있는 프로젝트입니다 3 | 4 | ![amanda-mockup](https://user-images.githubusercontent.com/52072077/112094120-05214880-8bde-11eb-859b-20d3ee11be3e.png) 5 | 6 | ## Stack 7 | | | Web | Server | 8 | |:--------------------:|:---------------:|:------------------:| 9 | | Developer | 차승호, 정성훈 | 제정민 | 10 | | Develop Language | TypeScript | GO| 11 | | Develop Tool | Visual Studio Code | Visual Studio Code | 12 | 13 | ## 느낀점 14 | 15 | 1학년 때 교내 해커톤에 참여했을때는 실력이 부족해 빨리 개발에 참여하고 싶어 열정적으로 공부했던 기억이 있습니다. 2학년이 되어 이번 해커톤에서는 데이터베이스 설계부터 구현, 백엔드 개발까지 혼자 맡게 되었습니다. 16 | 17 | 시간이 부족할 것 같았지만 빠르게 작업해서 모든 작업을 완료하여 뿌듯하고 더 동기부여가 된 것 같습니다. 18 | 19 | ## 소개 20 | 21 | 대구소프트웨어고등학교 학생들이 더 이상 외모 순위를 두고 다투지 않게, 평가와 피드백을 받을 수 있는 웹 앱입니다. 22 | 23 | 2020 교내 해커톤 프로젝트로 진행했습니다. 24 | 25 | ## 기능 26 | 27 | ### 로그인 & 회원가입 28 | 29 | ![로그인](https://user-images.githubusercontent.com/52072077/112094084-f63a9600-8bdd-11eb-8731-0cefd8351088.png) 30 | 31 | 아만다를 사용하기 위해 계정 생성이 필요합니다. 32 | 33 | ### 프로필 등록 34 | 35 | ![프로필등록](https://user-images.githubusercontent.com/52072077/112094100-fc307700-8bdd-11eb-8c35-15ff83553bf0.png) 36 | 37 | 첫 로그인 시, 서비스 이용을 위하여 자신의 프로필을 등록합니다. 38 | 39 | ### 프로필 페이지 40 | 41 | ![프로필](https://user-images.githubusercontent.com/52072077/112094102-fd61a400-8bdd-11eb-9c8f-f7c2ea352622.png) 42 | 43 | 다른 사용자의 프로필을 보고 평점을 남기고 댓글을 남길 수 있습니다. 44 | 45 | 평점은 사용자당 한 번씩만 등록할 수 있으며, 다른 사용자들이 등록한 평점과 참여자 수 및 댓글을 확인할 수 있습니다. 46 | 47 | ### 메인 페이지 48 | 49 | ![메인](https://user-images.githubusercontent.com/52072077/112094112-03578500-8bde-11eb-8531-632d879df009.png) 50 | 51 | 평점 순위를 바탕으로 자신의 프로필 위치가 메인페이지에서 달라집니다. 52 | 53 | 검색을 통해 다른 사용자를 찾을 수 있으며 로딩 속도를 줄이기 위해 무한 스크롤로 개발하였습니다. 54 | 55 | 56 | ## 그 외 57 | 58 | [2020 대구소프트웨어고등학교 교내 해커톤 2020-09-27](https://jjmin321.github.io/development/2020-대구소프트웨어고등학교-교내-해커톤/) 59 | -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | 7 | "github.com/BurntSushi/toml" 8 | ) 9 | 10 | var Config config 11 | 12 | type configMethod interface { 13 | InitConfig() 14 | } 15 | 16 | type config struct { 17 | App app 18 | DB database `toml:"database"` 19 | } 20 | 21 | type app struct { 22 | Name string `toml:"name"` 23 | } 24 | 25 | type database struct { 26 | Name string `toml:"name"` 27 | Username string `toml:"username"` 28 | Password string `toml:"password"` 29 | Host string `toml:"host"` 30 | Port string `toml:"port"` 31 | } 32 | 33 | // InitConfig Config 데이터 초기화 34 | func InitConfig() { 35 | configBytes, err := ioutil.ReadFile("config/config.toml") 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | _, err = toml.Decode(string(configBytes), &Config) 41 | if err != nil { 42 | panic(err) 43 | } 44 | 45 | log.Print("[CONFIG] 환경설정 초기화") 46 | } 47 | -------------------------------------------------------------------------------- /config/config.toml: -------------------------------------------------------------------------------- 1 | [app] 2 | name = "Amanda" 3 | 4 | [database] 5 | name = "Amanda_server" 6 | username = "jejeongmin" 7 | password = "qwerz123" 8 | host = "127.0.0.1" 9 | port = "5432" -------------------------------------------------------------------------------- /controller/createComment.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // CreateCommentParam - 파라미터 형식 정의 구조체 10 | type CreateCommentParam struct { 11 | ID string `json:"id" form:"id" query:"id"` 12 | Comment string `json:"comment" form:"comment" query:"comment"` 13 | } 14 | 15 | // CreateComment - 댓글을 작성하는 메서드 16 | func CreateComment(c echo.Context) error { 17 | ID := c.Get("ID").(string) 18 | u := new(CreateCommentParam) 19 | if err := c.Bind(u); err != nil { 20 | return err 21 | } 22 | UserComment := &database.UserComment{FkUserID: ID, FkObjectID: u.ID, Comment: u.Comment} 23 | err := database.DB.Create(UserComment).Error 24 | if err != nil { 25 | return c.JSON(500, map[string]interface{}{ 26 | "status": 500, 27 | "message": "댓글 달기 실패", 28 | }) 29 | } 30 | return c.JSON(200, map[string]interface{}{ 31 | "status": 200, 32 | "message": "댓글 달기 성공", 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /controller/createReplyComment.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // CreateReplyCommentParam - 파라미터 형식 정의 구조체 10 | type CreateReplyCommentParam struct { 11 | Idx uint `json:"idx" form:"idx" query:"idx"` 12 | Comment string `json:"comment" form:"comment" query:"comment"` 13 | } 14 | 15 | // CreateReplyComment - 답글을 작성하는 메서드 16 | func CreateReplyComment(c echo.Context) error { 17 | ID := c.Get("ID").(string) 18 | u := new(CreateReplyCommentParam) 19 | if err := c.Bind(u); err != nil { 20 | return err 21 | } 22 | UserReplyComment := &database.UserReplyComment{CommentIdx: u.Idx, FkUserID: ID, Comment: u.Comment} 23 | err := database.DB.Create(UserReplyComment).Error 24 | if err != nil { 25 | return c.JSON(500, map[string]interface{}{ 26 | "status": 500, 27 | "message": "답글 달기 실패", 28 | }) 29 | } 30 | return c.JSON(200, map[string]interface{}{ 31 | "status": 200, 32 | "message": "답글 달기 성공", 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /controller/showAllInfo.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // ShowAllInfoParam - 파라미터 형식 정의 구조체 10 | type ShowAllInfoParam struct { 11 | ID string `json:"id" form:"id" query:"id"` 12 | Name string `json:"name" form:"name" query:"name"` 13 | } 14 | 15 | // ShowAllInfo - 유저 정보를 보여주는 메서드 16 | func ShowAllInfo(c echo.Context) error { 17 | u := new(ShowUserInfoParam) 18 | if err := c.Bind(u); err != nil { 19 | return err 20 | } 21 | User := &[]database.User{} 22 | err := database.DB.Find(User).Error 23 | if err != nil { 24 | return c.JSON(500, map[string]interface{}{ 25 | "status": 500, 26 | "message": "멤버 리스트를 읽어오지 못했습니다.", 27 | "data": "null", 28 | }) 29 | } 30 | return c.JSON(200, map[string]interface{}{ 31 | "status": 200, 32 | "message": "멤버 리스트를 읽어오는 데 성공했습니다.", 33 | "data": User, 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /controller/showComment.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // ShowCommentParam - 파라미터 형식 정의 구조체 10 | type ShowCommentParam struct { 11 | ID string `json:"id" form:"id" query:"id"` 12 | } 13 | 14 | // ShowComment - 댓글을 보여주는 메서드 15 | func ShowComment(c echo.Context) error { 16 | u := new(ShowCommentParam) 17 | if err := c.Bind(u); err != nil { 18 | return err 19 | } 20 | UserComment := &[]database.UserComment{} 21 | err := database.DB.Where("fk_object_id = ?", u.ID).Find(UserComment).Error 22 | if err != nil { 23 | return c.JSON(500, map[string]interface{}{ 24 | "status": 500, 25 | "message": "댓글을 읽어오지 못했습니다.", 26 | "comment": "null", 27 | }) 28 | } 29 | return c.JSON(200, map[string]interface{}{ 30 | "status": 200, 31 | "message": "댓글을 읽어오는 데 성공했습니다.", 32 | "comment": UserComment, 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /controller/showMyInfo.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // ShowMyInfo - 내 정보 가져오는 메서드 10 | func ShowMyInfo(c echo.Context) error { 11 | ID := c.Get("ID") 12 | User := &database.User{} 13 | err := database.DB.Where("user_id = ?", ID).Find(User).Error 14 | if err != nil { 15 | return c.JSON(500, map[string]interface{}{ 16 | "status": 500, 17 | "message": "내 정보를 읽어오지 못했습니다.", 18 | "data": "null", 19 | }) 20 | } 21 | return c.JSON(200, map[string]interface{}{ 22 | "status": 200, 23 | "message": "내 정보를 읽어오는 데 성공했습니다.", 24 | "data": User, 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /controller/showMyStar.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // ShowMyStar - 내거 먀간 평점 정보들을 가져오는 메서드 10 | func ShowMyStar(c echo.Context) error { 11 | ID := c.Get("ID") 12 | UserStar := &[]database.UserStar{} 13 | err := database.DB.Where("fk_user_id = ?", ID).Find(UserStar).Error 14 | if err != nil { 15 | return c.JSON(500, map[string]interface{}{ 16 | "status": 500, 17 | "message": "내 정보를 읽어오지 못했습니다.", 18 | "data": "null", 19 | }) 20 | } 21 | return c.JSON(200, map[string]interface{}{ 22 | "status": 200, 23 | "message": "내 정보를 읽어오는 데 성공했습니다.", 24 | "data": UserStar, 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /controller/showReplyComment.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // ShowReplyCommentParam - 파라미터 형식 정의 구조체 10 | type ShowReplyCommentParam struct { 11 | Idx string `json:"idx" form:"idx" query:"idx"` 12 | } 13 | 14 | // ShowReplyComment - 답글을 보여주는 메서드 15 | func ShowReplyComment(c echo.Context) error { 16 | u := new(ShowReplyCommentParam) 17 | if err := c.Bind(u); err != nil { 18 | return err 19 | } 20 | UserReplyComment := &[]database.UserReplyComment{} 21 | err := database.DB.Where("comment_idx = ?", u.Idx).Find(UserReplyComment).Error 22 | if err != nil { 23 | return c.JSON(500, map[string]interface{}{ 24 | "status": 500, 25 | "message": "답글을 읽어오지 못했습니다.", 26 | "replyComment": "null", 27 | }) 28 | } 29 | return c.JSON(200, map[string]interface{}{ 30 | "status": 200, 31 | "message": "멤버 리스트를 읽어오는 데 성공했습니다.", 32 | "replyComment": UserReplyComment, 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /controller/showUserInfo.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // ShowUserInfoParam - 파라미터 형식 정의 구조체 10 | type ShowUserInfoParam struct { 11 | ID string `json:"id" form:"id" query:"id"` 12 | Name string `json:"name" form:"name" query:"name"` 13 | } 14 | 15 | // ShowUserInfo - 유저 정보를 보여주는 메서드 16 | func ShowUserInfo(c echo.Context) error { 17 | u := new(ShowUserInfoParam) 18 | if err := c.Bind(u); err != nil { 19 | return err 20 | } 21 | User := &[]database.User{} 22 | err := database.DB.Where("user_id = ? OR name = ?", u.ID, u.Name).Find(User).Error 23 | if err != nil { 24 | return c.JSON(500, map[string]interface{}{ 25 | "status": 500, 26 | "message": "멤버 리스트를 읽어오지 못했습니다.", 27 | "data": "null", 28 | }) 29 | } 30 | return c.JSON(200, map[string]interface{}{ 31 | "status": 200, 32 | "message": "멤버 리스트를 읽어오는 데 성공했습니다.", 33 | "data": User, 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /controller/showUserStar.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // ShowUserStarParam - 파라미터 형식 정의 구조체 10 | type ShowUserStarParam struct { 11 | Idx uint `json:"idx" form:"idx" query:"idx"` 12 | } 13 | 14 | // ShowUserStar - 유저의 평점과 참여자 수를 읽어오는 메소드 15 | func ShowUserStar(c echo.Context) error { 16 | u := new(ShowUserStarParam) 17 | if err := c.Bind(u); err != nil { 18 | return err 19 | } 20 | var starCnt uint 21 | starCnt = 0 22 | UserStar := &[]database.UserStar{} 23 | err := database.DB.Where("fk_object_idx = ?", u.Idx).Find(UserStar).Error 24 | for _, v := range *UserStar { 25 | starCnt += v.Star 26 | } 27 | 28 | if err != nil { 29 | return c.JSON(500, map[string]interface{}{ 30 | "status": 500, 31 | "message": "평점 정보를 읽어오지 못했습니다.", 32 | "평점": 0, 33 | "참여자 수": "알 수 없음", 34 | }) 35 | } 36 | return c.JSON(200, map[string]interface{}{ 37 | "status": 200, 38 | "message": "평점 정보를 읽어오는 데 성공했습니다.", 39 | "평점": starCnt, 40 | "참여자 수": len(*UserStar), 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /controller/signIn.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | "Amanda_Server/library/jwt" 6 | 7 | "github.com/labstack/echo" 8 | ) 9 | 10 | // SignInParam - 파라미터 형식 정의 구조체 11 | type SignInParam struct { 12 | ID string `json:"id" form:"id" query:"id"` 13 | Pw string `json:"pw" form:"pw" query:"pw"` 14 | } 15 | 16 | // SignIn - 로그인 메서드 17 | func SignIn(c echo.Context) error { 18 | u := new(SignInParam) 19 | if err := c.Bind(u); err != nil { 20 | return err 21 | } 22 | User := &database.User{} 23 | err := database.DB.Where("user_id = ? AND pw = ?", u.ID, u.Pw).Find(User).Error 24 | if err != nil { 25 | return c.JSON(400, map[string]interface{}{ 26 | "status": 400, 27 | "message": "일치하는 회원이 없습니다", 28 | "refreshToken": "null", 29 | "accessToken": "null", 30 | }) 31 | } 32 | refreshToken, err := jwt.CreateRefreshToken(User.UserID, User.Pw) 33 | if err != nil { 34 | return c.JSON(500, map[string]interface{}{ 35 | "status": 500, 36 | "message": "refreshToken 생성 중 에러", 37 | "refreshToken": "null", 38 | "accessToken": "null", 39 | }) 40 | } 41 | accessToken, err := jwt.CreateAccessToken(User.UserID, User.Pw, User.IsManager) 42 | if err != nil { 43 | return c.JSON(500, map[string]interface{}{ 44 | "status": 500, 45 | "message": "accessToken 생성 중 에러", 46 | "refreshToken": refreshToken, 47 | "accessToken": "null", 48 | }) 49 | } 50 | return c.JSON(200, map[string]interface{}{ 51 | "status": 200, 52 | "message": "토큰 발급 완료", 53 | "refreshToken": refreshToken, 54 | "accessToken": accessToken, 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /controller/signUp.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // SignUpParam - 파라미터 형식 정의 구조체 10 | type SignUpParam struct { 11 | ID string `json:"id" form:"id" query:"id"` 12 | Pw string `json:"pw" form:"pw" query:"pw"` 13 | Name string `json:"name" form:"name" query:"name"` 14 | Image string `json:"image" form:"image" query:"image"` 15 | IsManager bool `json:"manager" form:"mamager" query:"manager"` 16 | } 17 | 18 | // SignUp - 회원가입 19 | func SignUp(c echo.Context) error { 20 | u := new(SignUpParam) 21 | if err := c.Bind(u); err != nil { 22 | return err 23 | } 24 | if u.ID == "" || u.Pw == "" || u.Name == "" { 25 | return c.JSON(400, map[string]interface{}{ 26 | "status": 400, 27 | "message": "모든 값을 입력해주세요", 28 | }) 29 | } 30 | User := &database.User{} 31 | err := database.DB.Where("user_id = ?", u.ID).Find(User).Error 32 | if err == nil { 33 | return c.JSON(400, map[string]interface{}{ 34 | "status": 400, 35 | "message": "이미 사용중인 아이디입니다.", 36 | }) 37 | } 38 | User = &database.User{UserID: u.ID, Pw: u.Pw, Name: u.Name, IsManager: u.IsManager} 39 | err = database.DB.Create(User).Error 40 | if err != nil { 41 | return c.JSON(500, map[string]interface{}{ 42 | "status": 500, 43 | "message": "회원가입 실패", 44 | }) 45 | } 46 | return c.JSON(200, map[string]interface{}{ 47 | "status": 200, 48 | "message": "회원가입이 완료되었습니다", 49 | }) 50 | } 51 | -------------------------------------------------------------------------------- /controller/updateComment.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // UpdateCommentParam - 파라미터 형식 정의 구조체 10 | type UpdateCommentParam struct { 11 | Idx uint `json:"idx" form:"idx" query:"idx"` 12 | Comment string `json:"comment" form:"comment" query:"comment"` 13 | } 14 | 15 | // UpdateComment - 댓글 수정 메서드 16 | func UpdateComment(c echo.Context) error { 17 | u := new(UpdateCommentParam) 18 | if err := c.Bind(u); err != nil { 19 | return err 20 | } 21 | ID := c.Get("ID").(string) 22 | UserComment := &database.UserComment{} 23 | err := database.DB.Model(UserComment).Where("idx = ? AND fk_user_id = ?", u.Idx, ID).Update("comment", u.Comment).Error 24 | if err != nil { 25 | return c.JSON(500, map[string]interface{}{ 26 | "status": 500, 27 | "message": "댓글 수정 실패", 28 | }) 29 | } 30 | return c.JSON(200, map[string]interface{}{ 31 | "status": 200, 32 | "message": "댓글 수정 성공", 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /controller/updateMyInfo.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // UpdateMyInfoParam - 파라미터 형식 정의 구조체 10 | type UpdateMyInfoParam struct { 11 | Name string `json:"name" form:"name" query:"name"` 12 | Description string `json:"description" form:"description" query:"description"` 13 | } 14 | 15 | // UpdateMyInfo - 내 정보 변경 메서드 16 | func UpdateMyInfo(c echo.Context) error { 17 | ID := c.Get("ID") 18 | u := new(UpdateMyInfoParam) 19 | if err := c.Bind(u); err != nil { 20 | return err 21 | } 22 | 23 | if u.Name != "" { 24 | User := &database.User{} 25 | err := database.DB.Model(User).Where("user_id = ?", ID).Update("name", u.Name).Error 26 | if err != nil { 27 | return c.JSON(500, map[string]interface{}{ 28 | "status": 500, 29 | "message": "이름 변경 실패", 30 | }) 31 | } 32 | } 33 | if u.Description != "" { 34 | User := &database.User{} 35 | err := database.DB.Model(User).Where("user_id = ?", ID).Update("description", u.Description).Error 36 | if err != nil { 37 | return c.JSON(500, map[string]interface{}{ 38 | "status": 500, 39 | "message": "소개 변경 실패", 40 | }) 41 | } 42 | } 43 | return c.JSON(200, map[string]interface{}{ 44 | "status": 200, 45 | "message": "성공적으로 변경되었습니다.", 46 | }) 47 | } 48 | -------------------------------------------------------------------------------- /controller/updateProfileImage.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | "io" 6 | "os" 7 | "strconv" 8 | "time" 9 | 10 | "github.com/labstack/echo" 11 | ) 12 | 13 | // UpdateProfileImage - 프로필 사진 등록 14 | func UpdateProfileImage(c echo.Context) error { 15 | ID := c.Get("ID").(string) 16 | Pw := c.Get("Pw").(string) 17 | file, err := c.FormFile("image") 18 | t := time.Now() 19 | now := strconv.Itoa(int(t.Unix())) 20 | fileName := ID + now + file.Filename 21 | if err != nil { 22 | return c.JSON(400, map[string]interface{}{ 23 | "status": 400, 24 | "message": "파일을 읽는 데 실패하였습니다. 다시 시도해주세요.", 25 | }) 26 | } 27 | src, err := file.Open() 28 | defer src.Close() 29 | if err != nil { 30 | return c.JSON(500, map[string]interface{}{ 31 | "status": 500, 32 | "message": "파일을 여는 데 실패하였습니다. 다시 시도해주세요.", 33 | }) 34 | } 35 | dst, err := os.Create("ProfileImage/" + fileName) 36 | defer dst.Close() 37 | if err != nil { 38 | return c.JSON(500, map[string]interface{}{ 39 | "status": 500, 40 | "message": "파일을 생성하는 데 실패하였습니다. 다시 시도해주세요.", 41 | }) 42 | } 43 | if _, err = io.Copy(dst, src); err != nil { 44 | return c.JSON(500, map[string]interface{}{ 45 | "status": 500, 46 | "message": "파일을 저장하는 데 실패하였습니다. 다시 시도해주세요.", 47 | }) 48 | } 49 | // err = model.UpdateImageInTeamMember(Idx, fileName) 50 | User := &database.User{} 51 | err = database.DB.Model(User).Where("user_id = ? AND pw = ?", ID, Pw).Update("image", fileName).Error 52 | if err != nil { 53 | return c.JSON(500, map[string]interface{}{ 54 | "status": 500, 55 | "message": "경로를 저장하는 데 실패하였습니다. 다시 시도해주세요.", 56 | }) 57 | } 58 | return c.JSON(200, map[string]interface{}{ 59 | "status": 200, 60 | "message": "프로필 사진 등록에 성공하셨습니다.", 61 | }) 62 | } 63 | -------------------------------------------------------------------------------- /controller/updateReplyComment.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // UpdateReplyCommentParam - 파라미터 형식 정의 구조체 10 | type UpdateReplyCommentParam struct { 11 | Idx uint `json:"idx" form:"idx" query:"idx"` 12 | Comment string `json:"comment" form:"comment" query:"comment"` 13 | } 14 | 15 | // UpdateReplyComment - 댓글 수정 메서드 16 | func UpdateReplyComment(c echo.Context) error { 17 | u := new(UpdateCommentParam) 18 | if err := c.Bind(u); err != nil { 19 | return err 20 | } 21 | ID := c.Get("ID").(string) 22 | UserReplyComment := &database.UserReplyComment{} 23 | err := database.DB.Model(UserReplyComment).Where("idx = ? AND fk_user_id = ?", u.Idx, ID).Update("comment", u.Comment).Error 24 | if err != nil { 25 | return c.JSON(500, map[string]interface{}{ 26 | "status": 500, 27 | "message": "답글 수정 실패", 28 | }) 29 | } 30 | return c.JSON(200, map[string]interface{}{ 31 | "status": 200, 32 | "message": "답글 수정 성공", 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /controller/updateStar.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "Amanda_Server/database" 5 | 6 | "github.com/labstack/echo" 7 | ) 8 | 9 | // UpdateStarParam - 파라미터 형식 정의 구조체 10 | type UpdateStarParam struct { 11 | Idx uint `json:"idx" form:"idx" query:"idx"` 12 | Star uint `json:"star" form:"star" query:"star"` 13 | } 14 | 15 | // UpdateStar - 유저 평점 등록 메서드 16 | func UpdateStar(c echo.Context) error { 17 | u := new(UpdateStarParam) 18 | if err := c.Bind(u); err != nil { 19 | return err 20 | } 21 | if u.Idx == 0 || u.Star == 0 { 22 | return c.JSON(400, map[string]interface{}{ 23 | "status": 400, 24 | "message": "모든 값을 입력해주세요", 25 | }) 26 | } 27 | ID := c.Get("ID").(string) 28 | UserStar := &database.UserStar{} 29 | err := database.DB.Where("fk_object_idx = ? AND fk_user_id = ?", u.Idx, ID).Find(UserStar).Error 30 | if err != nil { 31 | CreateUserStar := &database.UserStar{FkObjectIdx: u.Idx, Star: u.Star, FkUserID: ID} 32 | err := database.DB.Create(CreateUserStar).Error 33 | if err != nil { 34 | return c.JSON(500, map[string]interface{}{ 35 | "status": 500, 36 | "message": "평점 등록 실패", 37 | }) 38 | } 39 | } 40 | err = database.DB.Model(UserStar).Where("fk_object_idx = ? AND fk_user_id = ?", u.Idx, ID).Update("star", u.Star).Error 41 | if err != nil { 42 | return c.JSON(500, map[string]interface{}{ 43 | "status": 500, 44 | "message": "평점 등록 실패", 45 | }) 46 | } 47 | return c.JSON(200, map[string]interface{}{ 48 | "status": 200, 49 | "message": "평점 등록 완료", 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /database/connection.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "Amanda_Server/config" 5 | "fmt" 6 | "log" 7 | 8 | "github.com/jinzhu/gorm" 9 | ) 10 | 11 | type connectionMethod interface { 12 | Connect() 13 | } 14 | 15 | // DB - 데이터베이스 전역변수 16 | var DB *gorm.DB 17 | 18 | // Connect - 데이터베이스 구조 생성, 연결 하는 메서드 19 | func Connect() { 20 | dbConf := config.Config.DB 21 | 22 | connectOptions := fmt.Sprintf("host=%s port=%s user=%s dbname=%s password=%s sslmode=disable", 23 | dbConf.Host, 24 | dbConf.Port, 25 | dbConf.Username, 26 | dbConf.Name, 27 | dbConf.Password) 28 | 29 | db, err := gorm.Open("postgres", connectOptions) 30 | 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | db.AutoMigrate( 36 | &User{}, 37 | &UserStar{}, 38 | &UserComment{}, 39 | &UserReplyComment{}, 40 | ) 41 | 42 | db.Model(&UserStar{}).AddForeignKey("fk_object_idx", "users(idx)", "RESTRICT", "RESTRICT") 43 | db.Model(&UserStar{}).AddForeignKey("fk_user_id", "users(user_id)", "RESTRICT", "RESTRICT") 44 | db.Model(&UserComment{}).AddForeignKey("fk_user_id", "users(user_id)", "RESTRICT", "RESTRICT") 45 | db.Model(&UserComment{}).AddForeignKey("fk_object_id", "users(user_id)", "RESTRICT", "RESTRICT") 46 | db.Model(&UserReplyComment{}).AddForeignKey("comment_idx", "user_comments(idx)", "RESTRICT", "RESTRICT") 47 | 48 | DB = db 49 | 50 | log.Print("[DATABASE] 연결 완료") 51 | } 52 | -------------------------------------------------------------------------------- /database/user.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import "time" 4 | 5 | // User 유저 관리 테이블 6 | type User struct { 7 | Idx uint `gorm:"primary_key; auto_increment:true" json:"idx"` 8 | UserID string `gorm:"type:varchar(255);unique;not null" json:"user_id"` 9 | Pw string `gorm:"type:varchar(255);not null" json:"pw"` 10 | Name string `gorm:"type:varchar(255);not null" json:"name"` 11 | Description string `gorm:"type:varchar(255);" json:"description"` 12 | Image string `gorm:"type:varchar(255);not null" json:"image"` 13 | IsManager bool `gorm:"not null" sql:"DEFAULT:false" json:"is_manager"` 14 | JoinedAt time.Time `gorm:"not null" sql:"DEFAULT:current_timestamp" json:"joined_at"` 15 | } 16 | -------------------------------------------------------------------------------- /database/userComment.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import "time" 4 | 5 | // UserComment 평가하는 댓글 테이블 6 | type UserComment struct { 7 | Idx uint `gorm:"primary_key; auto_increment:true" json:"idx"` 8 | FkUserID string `gorm:"type:varchar(255);not null" json:"fk_user_id"` 9 | FkObjectID string `gorm:"type:varchar(255);not null" json:"fk_object_id"` 10 | Comment string `gorm:"type:varchar(255);not null" json:"comment"` 11 | CreatedAt time.Time `gorm:"not null" sql:"DEFAULT:current_timestamp" json:"created_at"` 12 | } 13 | -------------------------------------------------------------------------------- /database/userReplyComment.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import "time" 4 | 5 | // UserReplyComment 평가하는 댓글의 답글 테이블 6 | type UserReplyComment struct { 7 | Idx uint `gorm:"primary_key; auto_increment:true" json:"idx"` 8 | CommentIdx uint `gorm:"not null" json:"comment_idx"` 9 | FkUserID string `gorm:"type:varchar(255);not null" json:"fk_user_id"` 10 | Comment string `gorm:"type:varchar(255);not null" json:"comment"` 11 | CreatedAt time.Time `gorm:"not null" sql:"DEFAULT:current_timestamp" json:"created_at"` 12 | } 13 | -------------------------------------------------------------------------------- /database/userStar.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | // UserStar 유저 평가 테이블 4 | type UserStar struct { 5 | Idx uint `gorm:"primary_key; auto_increment:true" json:"idx"` 6 | FkObjectIdx uint `gorm:"not null;" json:"fk_object_idx"` 7 | Star uint `gorm:"not null" json:"star"` 8 | FkUserID string `gorm:"type:varchar(255);not null" json:"fk_user_id"` 9 | } 10 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module Amanda_Server 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/BurntSushi/toml v0.3.1 7 | github.com/dgrijalva/jwt-go v3.2.0+incompatible 8 | github.com/jinzhu/gorm v1.9.16 9 | github.com/labstack/echo v3.3.10+incompatible 10 | github.com/labstack/gommon v0.3.0 // indirect 11 | github.com/valyala/fasttemplate v1.2.1 // indirect 12 | golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect 13 | ) 14 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= 4 | github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= 5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= 7 | github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM= 8 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= 9 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 10 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= 11 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 12 | github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= 13 | github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o= 14 | github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= 15 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 16 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 17 | github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 18 | github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= 19 | github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= 20 | github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= 21 | github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= 22 | github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= 23 | github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= 24 | github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= 25 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 26 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 27 | github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= 28 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= 29 | github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= 30 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 31 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 32 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 33 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 34 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 35 | github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= 36 | github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= 37 | github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= 38 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 39 | golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 40 | golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 41 | golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= 42 | golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 43 | golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 44 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 45 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 46 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= 47 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 48 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 49 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 50 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 51 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 52 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 53 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 54 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 55 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 56 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 57 | -------------------------------------------------------------------------------- /library/jwt/jwt.go: -------------------------------------------------------------------------------- 1 | package jwt 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/dgrijalva/jwt-go" 7 | "github.com/labstack/echo" 8 | ) 9 | 10 | type jwtMethod interface { 11 | CreateRefreshToken() 12 | CreateAccessToken() 13 | VerifyRefreshToken() 14 | VerifyAccessToken() 15 | } 16 | 17 | // CreateRefreshToken : Middleware that create RefreshToken 18 | func CreateRefreshToken(Id, Pw string) (string, error) { 19 | refreshToken := jwt.New(jwt.SigningMethodHS256) 20 | claims := refreshToken.Claims.(jwt.MapClaims) 21 | claims["ID"] = Id 22 | claims["Pw"] = Pw 23 | claims["exp"] = time.Now().Add(time.Hour * 720).Unix() 24 | 25 | t, err := refreshToken.SignedString([]byte("secret")) 26 | if err != nil { 27 | return "", err 28 | } 29 | return t, nil 30 | } 31 | 32 | // CreateAccessToken : Middleware that create AccessToken 33 | func CreateAccessToken(Id, Pw string, IsManager bool) (string, error) { 34 | accessToken := jwt.New(jwt.SigningMethodHS256) 35 | claims := accessToken.Claims.(jwt.MapClaims) 36 | claims["ID"] = Id 37 | claims["Pw"] = Pw 38 | claims["IsManager"] = IsManager 39 | claims["exp"] = time.Now().Add(time.Hour * 1).Unix() 40 | t, err := accessToken.SignedString([]byte("secret")) 41 | if err != nil { 42 | return "", err 43 | } 44 | return t, nil 45 | } 46 | 47 | // VerifyRefreshToken : Middleware that verify RefreshToken 48 | func VerifyRefreshToken(next echo.HandlerFunc) echo.HandlerFunc { 49 | return func(c echo.Context) error { 50 | token := c.Get("user").(*jwt.Token) 51 | claims := token.Claims.(jwt.MapClaims) 52 | ID := claims["ID"].(string) 53 | Pw := claims["Pw"].(string) 54 | c.Set("ID", ID) 55 | c.Set("Pw", Pw) 56 | return next(c) 57 | } 58 | } 59 | 60 | // VerifyAccessToken : Middleware that verify AccessToken 61 | func VerifyAccessToken(next echo.HandlerFunc) echo.HandlerFunc { 62 | return func(c echo.Context) error { 63 | token := c.Get("user").(*jwt.Token) 64 | claims := token.Claims.(jwt.MapClaims) 65 | ID := claims["ID"].(string) 66 | Pw := claims["Pw"].(string) 67 | IsManager := claims["IsManager"].(bool) 68 | c.Set("ID", ID) 69 | c.Set("Pw", Pw) 70 | c.Set("IsManager", IsManager) 71 | return next(c) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "Amanda_Server/config" 5 | "Amanda_Server/controller" 6 | "Amanda_Server/database" 7 | "Amanda_Server/library/jwt" 8 | 9 | _ "github.com/jinzhu/gorm/dialects/postgres" 10 | "github.com/labstack/echo" 11 | "github.com/labstack/echo/middleware" 12 | ) 13 | 14 | type serverMethod interface { 15 | main() 16 | } 17 | 18 | func main() { 19 | config.InitConfig() 20 | database.Connect() 21 | e := echo.New() 22 | e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ 23 | AllowOrigins: []string{"*"}, 24 | AllowHeaders: []string{"*"}, 25 | })) 26 | e.Static("/image", "profileimage") 27 | e.GET("/showMyInfo", controller.ShowMyInfo, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 28 | e.GET("/showUserInfo", controller.ShowUserInfo) 29 | e.GET("/showAllInfo", controller.ShowAllInfo) 30 | e.GET("/showUserStar", controller.ShowUserStar) 31 | e.GET("/showComment", controller.ShowComment) 32 | e.GET("/showReplyComment", controller.ShowReplyComment) 33 | e.GET("/showMyStar", controller.ShowMyStar, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 34 | e.POST("/signin", controller.SignIn) 35 | e.POST("/signup", controller.SignUp) 36 | e.POST("/updateStar", controller.UpdateStar, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 37 | e.POST("/updateMyInfo", controller.UpdateMyInfo, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 38 | e.POST("/updateProfileImage", controller.UpdateProfileImage, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 39 | e.POST("/createComment", controller.CreateComment, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 40 | e.POST("/updateComment", controller.UpdateComment, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 41 | e.POST("/createReplyComment", controller.CreateReplyComment, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 42 | e.POST("/updateReplyComment", controller.UpdateReplyComment, middleware.JWT([]byte("secret")), jwt.VerifyAccessToken) 43 | e.Logger.Fatal(e.Start(":3000")) 44 | } 45 | --------------------------------------------------------------------------------