Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ format: ## コード整形
go-mod-tidy:
docker compose run --rm api go mod tidy

go-fix:
docker compose run --rm api sh -c "cd /app && go fix ./..."

# Wireコードを生成
wire-gen:
docker compose run --rm api sh -c "cd /app/internals/di && go run github.com/google/wire/cmd/wire gen"
Expand Down
2 changes: 1 addition & 1 deletion api/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25.5-alpine
FROM golang:1.26-alpine3.23

RUN apk add --no-cache bash tzdata

Expand Down
1 change: 0 additions & 1 deletion api/externals/handler/wire.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build wireinject
// +build wireinject

package handler

Expand Down
9 changes: 5 additions & 4 deletions api/externals/repository/division_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"

"github.com/NUTFes/FinanSu/api/drivers/db"
"github.com/NUTFes/FinanSu/api/externals/repository/abstract"
Expand Down Expand Up @@ -40,7 +41,7 @@ func (dr *divisionRepository) AllByPeriodAndFinancialRecord(
) (*sql.Rows, error) {

var conditions []string
var args []interface{}
var args []any

if year != "" {
conditions = append(conditions, "years.year = ?")
Expand Down Expand Up @@ -213,10 +214,10 @@ type Division = generated.Division

// NOTE: getの共通部分抜き出し
func makeSelectDivisionsSQL(conditions []string) string {
condition := ""
var condition strings.Builder
if len(conditions) > 0 {
for _, c := range conditions {
condition += fmt.Sprintf(" AND %s", c)
condition.WriteString(fmt.Sprintf(" AND %s", c))
}
}

Expand Down Expand Up @@ -254,7 +255,7 @@ func makeSelectDivisionsSQL(conditions []string) string {
WHERE 1=1
%s
ORDER BY divisions.id DESC
`, condition)
`, condition.String())
}

var selectDivisionOptionsQuery = dialect.From("divisions").
Expand Down
2 changes: 1 addition & 1 deletion api/externals/repository/festival_item_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (fir *festivalItemRepository) AllByPeriodAndDivision(
divisionId string,
) (*sql.Rows, error) {
var conditions []string
var args []interface{}
var args []any

if divisionId != "" {
conditions = append(conditions, "divisions.id = ?")
Expand Down
7 changes: 4 additions & 3 deletions api/externals/repository/financial_record_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"

"github.com/NUTFes/FinanSu/api/drivers/db"
"github.com/NUTFes/FinanSu/api/externals/repository/abstract"
Expand Down Expand Up @@ -192,10 +193,10 @@ var selectFestivalItemGroupSQL = `
`

func makeSelectFinancialRecordDetailsSQL(conditions []string) string {
condition := ""
var condition strings.Builder
if len(conditions) > 0 {
for _, c := range conditions {
condition += fmt.Sprintf(" AND %s", c)
condition.WriteString(fmt.Sprintf(" AND %s", c))
}
}
return fmt.Sprintf(`
Expand Down Expand Up @@ -229,7 +230,7 @@ func makeSelectFinancialRecordDetailsSQL(conditions []string) string {
GROUP BY
financial_records.id
ORDER BY
financial_records.id`, selectFestivalItemGroupSQL, condition)
financial_records.id`, selectFestivalItemGroupSQL, condition.String())
}

// CSV用の予算・部門を取得するクエリ
Expand Down
48 changes: 25 additions & 23 deletions api/externals/repository/purchase_order_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"fmt"
"os"
"strings"

"github.com/NUTFes/FinanSu/api/drivers/db"
"github.com/NUTFes/FinanSu/api/externals/repository/abstract"
Expand Down Expand Up @@ -61,7 +62,7 @@ func (por *purchaseOrderRepository) Create(
query := `
INSERT INTO
purchase_orders (deadline, user_id, expense_id, finance_check)
VALUES ('` + deadLine + "'," + userId + "," + expenseId + "," +financeCheck + ")"
VALUES ('` + deadLine + "'," + userId + "," + expenseId + "," + financeCheck + ")"
return por.crud.UpdateDB(c, query)
}

Expand Down Expand Up @@ -196,29 +197,30 @@ func (p *purchaseOrderRepository) AllUserInfoByYear(c context.Context, year stri
}

func (p *purchaseOrderRepository) NotifySlack(c context.Context, purchaseOrder domain.PurchaseOrder, purchaseItems []domain.PurchaseItem, user domain.User, bureau domain.Bureau, expense domain.Expense) error {
token := os.Getenv("BOT_USER_OAUTH_TOKEN")
channelName := os.Getenv("CHANNEL_NAME")
token := os.Getenv("BOT_USER_OAUTH_TOKEN")
channelName := os.Getenv("CHANNEL_NAME")

//メッセージ作成
sendMessage := "購入申請を受け付けました \n"
sendMessage += fmt.Sprintf("局・団体: %s", expense.Name) + " \n"
sendMessage += fmt.Sprintf("申請者: %s %s", bureau.Name, user.Name) + " \n"
sendMessage += "購入物品 \n"
//合計金額
sum := 0
//購入物品
for _, item := range purchaseItems{
sum += item.Price*item.Quantity
sendMessage += fmt.Sprintf("・%s %d円 %d個", item.Item, item.Price, item.Quantity) + " \n"
}
sendMessage += fmt.Sprintf("合計 %d円", sum)
client := slack.New(token)
//メッセージ作成
var sendMessage strings.Builder
sendMessage.WriteString("購入申請を受け付けました \n")
sendMessage.WriteString(fmt.Sprintf("局・団体: %s", expense.Name) + " \n")
sendMessage.WriteString(fmt.Sprintf("申請者: %s %s", bureau.Name, user.Name) + " \n")
sendMessage.WriteString("購入物品 \n")
//合計金額
sum := 0
//購入物品
for _, item := range purchaseItems {
sum += item.Price * item.Quantity
sendMessage.WriteString(fmt.Sprintf("・%s %d円 %d個", item.Item, item.Price, item.Quantity) + " \n")
}
sendMessage.WriteString(fmt.Sprintf("合計 %d円", sum))
client := slack.New(token)

_, _, err := client.PostMessage(channelName, slack.MsgOptionText(sendMessage, false))
if err != nil {
panic(err)
}
return err
_, _, err := client.PostMessage(channelName, slack.MsgOptionText(sendMessage.String(), false))
if err != nil {
panic(err)
}
return err
}

func (p *purchaseOrderRepository) AllUnregisteredUserInfoByYear(c context.Context, year string) (*sql.Rows, error) {
Expand Down Expand Up @@ -247,7 +249,7 @@ func (p *purchaseOrderRepository) AllUnregisteredUserInfoByYear(c context.Contex
ON
orders.id = reports.purchase_order_id
WHERE
years.year = `+ year +`
years.year = ` + year + `
AND
reports.purchase_order_id IS NULL
ORDER BY
Expand Down
12 changes: 7 additions & 5 deletions api/externals/repository/teacher_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"strconv"
"strings"

"github.com/NUTFes/FinanSu/api/drivers/db"
"github.com/NUTFes/FinanSu/api/externals/repository/abstract"
Expand Down Expand Up @@ -121,17 +122,18 @@ func (t *teacherRepository) FindLatestRecord(c context.Context) (*sql.Row, error

// 複数削除
func (t *teacherRepository) MultiDestroy(c context.Context, ids []int) error {
query := "UPDATE teachers SET is_deleted = TRUE WHERE "
var query strings.Builder
query.WriteString("UPDATE teachers SET is_deleted = TRUE WHERE ")
for index, id := range ids {
query += "id = " + strconv.Itoa(id)
query.WriteString("id = " + strconv.Itoa(id))

if(index != len(ids)-1){
query += " OR "
if index != len(ids)-1 {
query.WriteString(" OR ")
}

}

err := t.crud.UpdateDB(c, query)
err := t.crud.UpdateDB(c, query.String())
if err != nil {
return err
}
Expand Down
19 changes: 11 additions & 8 deletions api/externals/repository/user_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"strconv"
"strings"

"github.com/NUTFes/FinanSu/api/drivers/db"
"github.com/NUTFes/FinanSu/api/externals/repository/abstract"
Expand Down Expand Up @@ -80,25 +81,27 @@ func (ur *userRepository) Destroy(c context.Context, id string) error {

// 複数削除
func (ur *userRepository) MultiDestroy(c context.Context, ids []int) error {
query := "UPDATE users SET is_deleted = TRUE WHERE "
query2 := "UPDATE mail_auth SET email = NULL WHERE "
var query strings.Builder
query.WriteString("UPDATE users SET is_deleted = TRUE WHERE ")
var query2 strings.Builder
query2.WriteString("UPDATE mail_auth SET email = NULL WHERE ")
for index, id := range ids {
query += "id = " + strconv.Itoa(id)
query2 += "user_id = " + strconv.Itoa(id)
query.WriteString("id = " + strconv.Itoa(id))
query2.WriteString("user_id = " + strconv.Itoa(id))

if index != len(ids)-1 {
query += " OR "
query2 += " OR "
query.WriteString(" OR ")
query2.WriteString(" OR ")
}

}

err := ur.crud.UpdateDB(c, query)
err := ur.crud.UpdateDB(c, query.String())
if err != nil {
return err
}

err = ur.crud.UpdateDB(c, query2)
err = ur.crud.UpdateDB(c, query2.String())

return err
}
Expand Down
1 change: 0 additions & 1 deletion api/externals/repository/wire.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build wireinject
// +build wireinject

package repository

Expand Down
4 changes: 1 addition & 3 deletions api/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/NUTFes/FinanSu/api

go 1.23.0

toolchain go1.24.1
go 1.26.0

require (
github.com/doug-martin/goqu/v9 v9.19.0
Expand Down
1 change: 0 additions & 1 deletion api/internals/di/wire.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build wireinject
// +build wireinject

package di

Expand Down
7 changes: 4 additions & 3 deletions api/internals/usecase/mail_auth_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"strconv"
"strings"

rep "github.com/NUTFes/FinanSu/api/externals/repository"
"github.com/NUTFes/FinanSu/api/internals/domain"
Expand Down Expand Up @@ -128,10 +129,10 @@ func _makeRandomStr(digit uint32) (string, error) {
}

// letters からランダムに取り出して文字列を生成
var result string
var result strings.Builder
for _, v := range b {
// index が letters の長さに収まるように調整
result += string(letters[int(v)%len(letters)])
result.WriteString(string(letters[int(v)%len(letters)]))
}
return result, nil
return result.String(), nil
}
7 changes: 3 additions & 4 deletions api/internals/usecase/sponsor_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/csv"
"fmt"
"io"
"slices"
"strings"
"unicode/utf8"

Expand Down Expand Up @@ -211,10 +212,8 @@ func (s *sponsorUseCase) CreateSponsorsByCsv(c context.Context, csvFile io.Reade
continue
}

for j := range record {
if isEmpty(record[j]) {
return nil, fmt.Errorf("空のレコードがあります。")
}
if slices.ContainsFunc(record, isEmpty) {
return nil, fmt.Errorf("空のレコードがあります。")
}

sponsor := domain.Sponsor{
Expand Down
1 change: 0 additions & 1 deletion api/internals/usecase/wire.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build wireinject
// +build wireinject

package usecase

Expand Down
2 changes: 1 addition & 1 deletion prod.api.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build用 コンテナ
FROM golang:1.25.5-alpine AS builder
FROM golang:1.26-alpine3.23 AS builder
WORKDIR /app
COPY ./api /app
ENV CGO_ENABLED=0 \
Expand Down
Loading