Conversation
| var ( | ||
| db *sqlt.DB | ||
| stmt PreparedStatements | ||
| redis *redislib.RedisStore // redis module |
There was a problem hiding this comment.
| redis *redislib.RedisStore // redis module | |
| redis *redislib.RedisStore |
remove unnecessary comment
| ) | ||
|
|
||
| const ( | ||
| // Collection queries |
There was a problem hiding this comment.
| // Collection queries | |
| // Nilai Siswa queries |
| QueryGetNilaiSiswaByID = `select nim, mapel_id, nilai, sekolah, kelas | ||
| from nilai_siswa | ||
| where mapel_id = $1 and nim = $2;` |
There was a problem hiding this comment.
| QueryGetNilaiSiswaByID = `select nim, mapel_id, nilai, sekolah, kelas | |
| from nilai_siswa | |
| where mapel_id = $1 and nim = $2;` | |
| QueryGetNilaiSiswaByMapelIDAndNIM = ` | |
| SELECT nim, mapel_id, nilai, sekolah, kelas | |
| FROM nilai_siswa | |
| WHERE mapel_id = $1 AND nim = $2; | |
| ` |
|
|
||
| type NilaiSiswa struct { | ||
| NIM int64 `json:"nim" db:"nim"` | ||
| MapelID int64 `json:"mapel_id" db:"mapel_id"` |
There was a problem hiding this comment.
| MapelID int64 `json:"mapel_id" db:"mapel_id"` | |
| MapelID int `json:"mapel_id" db:"mapel_id"` |
sepertinya data type int64 terlalu berlebihan untuk mata pelajaran
| type NilaiSiswa struct { | ||
| NIM int64 `json:"nim" db:"nim"` | ||
| MapelID int64 `json:"mapel_id" db:"mapel_id"` | ||
| Nilai int64 `json:"nili" db:"nili"` |
There was a problem hiding this comment.
| Nilai int64 `json:"nili" db:"nili"` | |
| Nilai float32 `json:"nilai" db:"nilai"` |
nilai biasanya ada angka di belakang koma
| ) | ||
|
|
||
| func (s *server) GetNilaiSiswa(ctx context.Context, req *pb.GetNilaiSiswaRequest) (resp *pb.GetNilaiSiswaResponse, err error) { | ||
|
|
There was a problem hiding this comment.
| span, ctx := tracer.StartSpanFromContext(ctx) | |
| defer span.Finish() | |
| func (s *server) GetNilaiSiswa(ctx context.Context, req *pb.GetNilaiSiswaRequest) (resp *pb.GetNilaiSiswaResponse, err error) { | ||
|
|
||
| if req.sekolah == "" { | ||
| req.sekolah = "semua" |
There was a problem hiding this comment.
untuk string "semua" mungkin bisa dibuat const
| req.sekolah = "semua" | ||
| } | ||
|
|
||
| nilai, err := mnilai.GetNilaiSiswa(req.nim, req.sekolah, req.kelas, mapel_id) |
There was a problem hiding this comment.
| nilai, err := mnilai.GetNilaiSiswa(req.nim, req.sekolah, req.kelas, mapel_id) | |
| nilai, err := mnilai.GetNilaiSiswa(req.nim, req.sekolah, req.kelas, req.mapel_id) |
| "github.com/tokopedia/code-review-workshop/database" | ||
| redislib "github.com/tokopedia/code-review-workshop/redis" | ||
| "github.com/tokopedia/sqlt" |
There was a problem hiding this comment.
import beda repo sebaiknya dipisah dengan newline
| nilai "github.com/tokopedia/code-review-workshop/core/nilai" | ||
| "github.com/tokopedia/tokopoints/errors" | ||
| "github.com/tokopedia/tokopoints/tracer" |
There was a problem hiding this comment.
import beda repo sebaiknya dipisah dengan newline
| span, ctx := tracer.StartSpanFromContext(ctx) | ||
| defer span.Finish() | ||
|
|
||
| if nim != 0 && mapel_id != 0 { |
There was a problem hiding this comment.
| if nim != 0 && mapel_id != 0 { | |
| if nim > 0 && mapel_id > 0 { |
antisipasi negative value
| detailSekolah, err := nilai.GetDetailSekolah(ctx, nilai.Sekolah[0]) | ||
| if err != nil { | ||
| return resp, errors.AddTrace(err) | ||
| } | ||
|
|
||
| resp = mappingGetNilaiSiswa(nilai, detailSekolah) |
There was a problem hiding this comment.
GetDetailSekolah dan mappingGetNilaiSiswa lebih baik setelah if else selesai agar tidak redundant
| } | ||
|
|
||
| resp = mappingGetNilaiSiswa(nilai, detailSekolah) | ||
| } else if sekolah == "semua" { |
There was a problem hiding this comment.
| } else if sekolah == "semua" { | |
| } else { |
| "github.com/tokopedia/tokopoints/tracer" | ||
| ) | ||
|
|
||
| func GetNilaiSiswa(ctx context.Context, nim int64, sekolah, kelas string, mapel_id int64) (resp GetNilaiSiswaResponse, err error) { |
There was a problem hiding this comment.
param pakai struct supaya lebih rapi
No description provided.